diff options
author | Matthew Newhook <matthew@zeroc.com> | 2015-03-21 15:35:40 -0230 |
---|---|---|
committer | Matthew Newhook <matthew@zeroc.com> | 2015-03-21 15:35:40 -0230 |
commit | 630a37d2fe66f24518299e705f958b571803c522 (patch) | |
tree | 969723791bdc4d73bb099c19d45554d0ca241ad9 /objective-c/test | |
parent | Fix some README.md markdown formatting (diff) | |
download | ice-630a37d2fe66f24518299e705f958b571803c522.tar.bz2 ice-630a37d2fe66f24518299e705f958b571803c522.tar.xz ice-630a37d2fe66f24518299e705f958b571803c522.zip |
py -> python
rb -> ruby
objc -> objective-c
cs -> csharp
Diffstat (limited to 'objective-c/test')
304 files changed, 38214 insertions, 0 deletions
diff --git a/objective-c/test/Common/.gitignore b/objective-c/test/Common/.gitignore new file mode 100644 index 00000000000..3a412ca89c7 --- /dev/null +++ b/objective-c/test/Common/.gitignore @@ -0,0 +1,4 @@ +// Generated by makegitignore.py + +// IMPORTANT: Do not edit this file -- any edits made here will be lost! +.depend diff --git a/objective-c/test/Common/Makefile b/objective-c/test/Common/Makefile new file mode 100644 index 00000000000..f9051634da0 --- /dev/null +++ b/objective-c/test/Common/Makefile @@ -0,0 +1,42 @@ +# ********************************************************************** +# +# Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +# +# This copy of Ice is licensed to you under the terms described in the +# ICE_LICENSE file included in this distribution. +# +# ********************************************************************** + +top_srcdir = ../.. + +LIBNAME = $(call mklibname,TestCommon) + +TARGETS = ../../lib/$(LIBNAME) + +OBJS = TestCommon.o + +SRCS := $(OBJS:.o=.m) + +include $(top_srcdir)/config/Make.rules + +ifeq ($(STATICLIBS),yes) + mklibname = lib$(1).a +else + mklibname = lib$(1).dylib +endif + +CPPFLAGS := -I../include $(CPPFLAGS) + +ifeq ($(STATICLIBS),yes) + +../../lib/$(LIBNAME): $(OBJS) + rm -f $@ + $(call mklib,$@,$(OBJS)) + +else + +../../lib/$(LIBNAME): $(OBJS) + rm -f $@ + $(call mkshlib,$@,$(LIBNAME),$(OBJS),$(LIBS)) + +endif diff --git a/objective-c/test/Common/TestCommon.m b/objective-c/test/Common/TestCommon.m new file mode 100644 index 00000000000..fad9e6da5e3 --- /dev/null +++ b/objective-c/test/Common/TestCommon.m @@ -0,0 +1,242 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#ifndef TEST_API_EXPORTS +# define TEST_API_EXPORTS +#endif + +#include <TestCommon.h> + +#include <stdarg.h> +#include <stdlib.h> + +#import <objc/Ice.h> + +@implementation TestFailedException +-(id)init +{ + return [super initWithName:@"TestFailedException" reason:nil userInfo:nil]; +} +@end + +#if TARGET_OS_IPHONE + +#import <Foundation/NSString.h> +#import <Foundation/NSObject.h> +#import <Foundation/NSThread.h> + +#include <objc/Ice.h> + +static id outputTarget; +static id testRun; +static SEL readySelector; +static SEL outputSelector; +static id<ICECommunicator> communicator = nil; +static NSString* protocol; + +static BOOL sliced; +static BOOL encoding10; + +#endif + +id<ICEProperties> +defaultServerProperties(int *argc, char** argv) +{ + id<ICEProperties> properties = [ICEUtil createProperties]; + +#if TARGET_OS_IPHONE + static NSString* defaults[] = + { + @"Ice.NullHandleAbort", @"1", + @"Ice.Warn.Connections", @"1", + @"Ice.ThreadPool.Server.Size", @"1", + @"Ice.ThreadPool.Server.SizeMax", @"3", + @"Ice.ThreadPool.Server.SizeWarn", @"0", + //@"Ice.PrintAdapterReady", @"1", + @"Ice.ServerIdleTime", @"30", + @"Ice.Default.Host", @"127.0.0.1", + @"Ice.Trace.Network", @"0", + @"Ice.Trace.Protocol", @"0" + }; + + static NSString* ssldefaults[] = + { + @"Ice.Override.ConnectTimeout", @"10000", // COMPILERFIX: Workaround for SSL hang on iOS devices + @"IceSSL.CertAuthFile", @"cacert.der", + @"IceSSL.CheckCertName", @"0", + @"IceSSL.CertFile", @"s_rsa1024.pfx", + @"IceSSL.Password", @"password" + }; + + int i; + for(i = 0; i < sizeof(defaults)/sizeof(defaults[0]); i += 2) + { + [properties setProperty:defaults[i] value:defaults[i+1]]; + } + [properties setProperty:@"Ice.Default.Protocol" value:protocol]; + if([protocol isEqualToString:@"ssl"] || [protocol isEqualToString:@"wss"]) + { + for(i = 0; i < sizeof(ssldefaults)/sizeof(ssldefaults[0]); i += 2) + { + [properties setProperty:ssldefaults[i] value:ssldefaults[i+1]]; + } + } + + if(sliced) + { + [properties setProperty:@"Ice.Default.SlicedFormat" value:@"1"]; + } + else if(encoding10) + { + [properties setProperty:@"Ice.Default.EncodingVersion" value:@"1.0"]; + } +#endif + + NSArray* args = [properties parseIceCommandLineOptions:[ICEUtil argsToStringSeq:*argc argv:argv]]; + [ICEUtil stringSeqToArgs:args argc:argc argv:argv]; + + return properties; +} + +id<ICEProperties> +defaultClientProperties(int* argc, char** argv) +{ + id<ICEProperties> properties = [ICEUtil createProperties]; + +#if TARGET_OS_IPHONE + static NSString* defaults[] = + { + @"Ice.NullHandleAbort", @"1", + @"Ice.Warn.Connections", @"1", + @"Ice.Default.Host", @"127.0.0.1", + @"Ice.Trace.Network", @"0", + @"Ice.Trace.Protocol", @"0" + }; + + static NSString* ssldefaults[] = + { + @"Ice.Override.ConnectTimeout", @"10000", // COMPILERFIX: Workaround for SSL hang on iOS devices + @"IceSSL.CheckCertName", @"0", + @"IceSSL.CertAuthFile", @"cacert.der", + @"IceSSL.CertFile", @"c_rsa1024.pfx", + @"IceSSL.Password", @"password" + }; + + int i; + for(i = 0; i < sizeof(defaults)/sizeof(defaults[0]); i += 2) + { + [properties setProperty:defaults[i] value:defaults[i+1]]; + } + + [properties setProperty:@"Ice.Default.Protocol" value:protocol]; + if([protocol isEqualToString:@"ssl"] || [protocol isEqualToString:@"wss"]) + { + for(i = 0; i < sizeof(ssldefaults)/sizeof(ssldefaults[0]); i += 2) + { + [properties setProperty:ssldefaults[i] value:ssldefaults[i+1]]; + } + } + if(sliced) + { + [properties setProperty:@"Ice.Default.SlicedFormat" value:@""]; + } + else if(encoding10) + { + [properties setProperty:@"Ice.Default.EncodingVersion" value:@"1.0"]; + } +#endif + + NSArray* args = [properties parseIceCommandLineOptions:[ICEUtil argsToStringSeq:*argc argv:argv]]; + [ICEUtil stringSeqToArgs:args argc:argc argv:argv]; + return properties; +} + +#if TARGET_OS_IPHONE + +void +TestCommonInit(id target, SEL output) +{ + outputTarget = target; + outputSelector = output; +} + +void +TestCommonTestInit(id r, SEL ready, NSString* p, BOOL sl, BOOL e10) +{ + testRun = r; + readySelector = ready; + protocol = p; + sliced = sl; + encoding10 = e10; +} + +void +serverReady(id<ICECommunicator> c) +{ + ICE_RELEASE(communicator); + communicator = ICE_RETAIN(c); + [testRun performSelectorOnMainThread:readySelector withObject:nil waitUntilDone:NO]; +} + +void +serverStop() +{ + [communicator shutdown]; +} + +void +tprintf(const char* fmt, ...) +{ + va_list va; + va_start(va, fmt); + NSString* s = ICE_AUTORELEASE([[NSString alloc] initWithFormat:[NSString stringWithCString:fmt + encoding:NSUTF8StringEncoding] + arguments:va]); + va_end(va); + [outputTarget performSelectorOnMainThread:outputSelector withObject:s waitUntilDone:NO]; +} + +void +testFailed(const char* expr, const char* file, unsigned int line) +{ + tprintf("failed!\n"); + tprintf("%s:%u: assertion `%s' failed\n", file, line, expr); + @throw ICE_AUTORELEASE([[TestFailedException alloc] init]); +} + +#else + +#include <stdio.h> + +void +tprintf(const char* fmt, ...) +{ + va_list va; + va_start(va, fmt); + NSString* s = ICE_AUTORELEASE([[NSString alloc] initWithFormat:[NSString stringWithCString:fmt + encoding:NSUTF8StringEncoding] + arguments:va]); + va_end(va); + fputs([s UTF8String], stdout); + fflush(stdout); +} + +void +serverReady(id<ICECommunicator> c) +{ +} + +void +testFailed(const char* expr, const char* file, unsigned int line) +{ + tprintf("failed!\n"); + tprintf("%s:%u: assertion `%s' failed\n", file, line, expr); + abort(); +} +#endif diff --git a/objective-c/test/Ice/Makefile b/objective-c/test/Ice/Makefile new file mode 100644 index 00000000000..270f6c79dbf --- /dev/null +++ b/objective-c/test/Ice/Makefile @@ -0,0 +1,50 @@ +# ********************************************************************** +# +# Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +# +# This copy of Ice is licensed to you under the terms described in the +# ICE_LICENSE file included in this distribution. +# +# ********************************************************************** + +top_srcdir = ../.. + +include $(top_srcdir)/config/Make.rules + +SUBDIRS = proxy \ + acm \ + admin \ + ami \ + operations \ + exceptions \ + inheritance \ + facets \ + objects \ + optional \ + interceptor \ + invoke \ + dispatcher \ + defaultServant \ + defaultValue \ + enums \ + faultTolerance \ + location \ + adapterDeactivation \ + slicing \ + binding \ + hold \ + retry \ + stream \ + timeout \ + hash \ + info \ + metrics \ + services \ + servantLocator + +$(EVERYTHING):: + @for subdir in $(SUBDIRS); \ + do \ + echo "making $@ in $$subdir"; \ + ( cd $$subdir && $(MAKE) $@ ) || exit 1; \ + done diff --git a/objective-c/test/Ice/acm/.gitignore b/objective-c/test/Ice/acm/.gitignore new file mode 100644 index 00000000000..3fdb6d1ddfc --- /dev/null +++ b/objective-c/test/Ice/acm/.gitignore @@ -0,0 +1,8 @@ +// Generated by makegitignore.py + +// IMPORTANT: Do not edit this file -- any edits made here will be lost! +client +server +.depend +ACMTest.m +ACMTest.h diff --git a/objective-c/test/Ice/acm/ACMTest.ice b/objective-c/test/Ice/acm/ACMTest.ice new file mode 100644 index 00000000000..1e6bcd7eb69 --- /dev/null +++ b/objective-c/test/Ice/acm/ACMTest.ice @@ -0,0 +1,37 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#pragma once + +["objc:prefix:TestACM"] +module Test +{ + +interface TestIntf +{ + void sleep(int seconds); + void sleepAndHold(int seconds); + void interruptSleep(); +}; + +interface RemoteObjectAdapter +{ + TestIntf* getTestIntf(); + void activate(); + void hold(); + void deactivate(); +}; + +interface RemoteCommunicator +{ + RemoteObjectAdapter* createObjectAdapter(int acmTimeout, int close, int heartbeat); + void shutdown(); +}; + +}; diff --git a/objective-c/test/Ice/acm/AllTests.m b/objective-c/test/Ice/acm/AllTests.m new file mode 100644 index 00000000000..ca9d73278db --- /dev/null +++ b/objective-c/test/Ice/acm/AllTests.m @@ -0,0 +1,836 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <TestCommon.h> +#import <acm/TestI.h> + +@interface LoggerI : ICELocalObject<ICELogger> +{ + NSCondition* _cond; + BOOL _started; + NSMutableArray* _messages; +} +-(void) start; +-(void) dump; +@end + +@implementation LoggerI +-(id) init +{ + self = [super init]; + if(!self) + { + return nil; + } + _cond = [[NSCondition alloc] init]; + _started = NO; + _messages = [NSMutableArray array]; + return self; +} + +#if defined(__clang__) && !__has_feature(objc_arc) +-(void) dealloc +{ + [_cond release]; + [super dealloc]; +} +#endif +-(void) start +{ + [_cond lock]; + _started = YES; + [self dump]; + [_cond unlock]; +} +-(void) print:(NSString*)message +{ + [_cond lock]; + [_messages addObject:message]; + if(_started) + { + [self dump]; + } + [_cond unlock]; +} +-(void) trace:(NSString*)category message:(NSString*)message +{ + [_cond lock]; + [_messages addObject:message]; + if(_started) + { + [self dump]; + } + [_cond unlock]; +} +-(void) warning:(NSString*)message +{ + [_cond lock]; + [_messages addObject:message]; + if(_started) + { + [self dump]; + } + [_cond unlock]; +} +-(void) error:(NSString*)message +{ + [_cond lock]; + [_messages addObject:message]; + if(_started) + { + [self dump]; + } + [_cond unlock]; +} +-(NSMutableString*) getPrefix +{ + return [@"" mutableCopy]; +} +-(id<ICELogger>) cloneWithPrefix:(NSString*)prefix +{ + return self; +} +-(void) dump +{ + for(int i = 0; i < _messages.count; ++i) + { + tprintf([_messages[i] UTF8String]); + } + [_messages removeAllObjects]; +} +@end + +@class TestCaseThread; + +@interface TestCase : NSObject<ICEConnectionCallback> +{ + NSCondition* _cond; + + NSString* _name; + id<TestACMRemoteCommunicatorPrx> _com; + NSString* _msg; + LoggerI* _logger; + TestCaseThread* _thread; + + id<ICECommunicator> _communicator; + id<TestACMRemoteObjectAdapterPrx> _adapter; + + int _clientACMTimeout; + int _clientACMClose; + int _clientACMHeartbeat; + int _serverACMTimeout; + int _serverACMClose; + int _serverACMHeartbeat; + + int _heartbeat; + BOOL _closed; +} ++(id) testCase:(id<TestACMRemoteCommunicatorPrx>)com; +-(id) initWithName:(NSString*)name com:(id<TestACMRemoteCommunicatorPrx>)com; + +-(void) initialize; +-(void) start; +-(void) destroy; +-(void) join; + +-(void) run; + ++(NSString*) getName; +-(void) runTestCase:(id<TestACMRemoteObjectAdapterPrx>)adapter proxy:(id<TestACMTestIntfPrx>)proxy; + +-(void) waitForClosed; +-(void) setClientACM:(int)timeout close:(int)close heartbeat:(int)heartbeat; +-(void) setServerACM:(int)timeout close:(int)close heartbeat:(int)heartbeat; +@end + +@interface TestCaseThread : NSThread +{ + NSCondition* _cond; + TestCase* _test; + BOOL _called; +} +-(id) initWithTestCase:(TestCase*)test; +-(void) join; +-(void) run; +@end + +@implementation TestCase ++(id) testCase:(id<TestACMRemoteCommunicatorPrx>)com +{ + return ICE_AUTORELEASE([[self alloc] initWithName:[self getName] com:com]); +} +-(id) initWithName:(NSString*)name com:(id<TestACMRemoteCommunicatorPrx>)com +{ + self = [super init]; + if(!self) + { + return nil; + } + _name = name; + _com = com; + + _cond = [[NSCondition alloc] init]; + _logger = [[LoggerI alloc] init]; + + _clientACMTimeout = -1; + _clientACMClose = -1; + _clientACMHeartbeat = -1; + _serverACMTimeout = -1; + _serverACMClose = -1; + _serverACMHeartbeat = -1; + + _heartbeat = 0; + _closed = NO; + + return self; +} +#if defined(__clang__) && !__has_feature(objc_arc) +-(void) dealloc +{ + [_cond release]; + [_logger release]; + [super dealloc]; +} +#endif + +-(void) initialize +{ + _adapter = ICE_RETAIN([_com createObjectAdapter:_serverACMTimeout close:_serverACMClose + heartbeat:_serverACMHeartbeat]); + + ICEInitializationData* initData = [ICEInitializationData initializationData]; + initData.properties = [[[_com ice_getCommunicator] getProperties] clone]; + initData.logger = _logger; + [initData.properties setProperty:@"Ice.ACM.Timeout" value:@"1"]; + if(_clientACMTimeout >= 0) + { + [initData.properties setProperty:@"Ice.ACM.Client.Timeout" + value:[NSString stringWithFormat:@"%d", _clientACMTimeout]]; + } + if(_clientACMClose >= 0) + { + [initData.properties setProperty:@"Ice.ACM.Client.Close" + value:[NSString stringWithFormat:@"%d", _clientACMClose]]; + } + if(_clientACMHeartbeat >= 0) + { + [initData.properties setProperty:@"Ice.ACM.Client.Heartbeat" + value:[NSString stringWithFormat:@"%d", _clientACMHeartbeat]]; + } + _communicator = ICE_RETAIN([ICEUtil createCommunicator:initData]); +} +-(void) start +{ + _thread = [[TestCaseThread alloc] initWithTestCase:self]; + [_thread start]; +} +-(void) destroy +{ + [_adapter deactivate]; + ICE_RELEASE(_adapter); + + [_communicator destroy]; + ICE_RELEASE(_communicator); +} +-(void) join +{ + tprintf("testing %s... ", [_name UTF8String]); + [_logger start]; + [_thread join]; + if([_msg length] == 0) + { + tprintf("ok\n"); + } + else + { + tprintf("failed!\n%s", [_msg UTF8String]); + test(NO); + } +} + +-(void) run +{ + id<TestACMTestIntfPrx> proxy = + [TestACMTestIntfPrx uncheckedCast:[_communicator stringToProxy:[[_adapter getTestIntf] ice_toString]]]; + + @try + { + [[proxy ice_getConnection] setCallback:self]; + [self runTestCase:_adapter proxy:proxy]; + } + @catch(ICEException* ex) + { + _msg = [ex description]; + } +} + ++(NSString*) getName +{ + NSAssert(NO, @"Subclasses need to overwrite this method"); + return nil; // To keep compiler happy +} + +-(void) runTestCase:(id<TestACMRemoteObjectAdapterPrx>)adapter proxy:(id<TestACMTestIntfPrx>)proxy +{ + NSAssert(NO, @"Subclasses need to overwrite this method"); +} + +-(void)closed:(id<ICEConnection>)connection +{ + [_cond lock]; + _closed = YES; + [_cond signal]; + [_cond unlock]; +} +-(void)heartbeat:(id<ICEConnection>)connection +{ + [_cond lock]; + ++_heartbeat; + [_cond unlock]; +} + +-(void) waitForClosed +{ + [_cond lock]; + @try + { + NSDate* start = [NSDate date]; + while(!_closed) + { + [_cond waitUntilDate:[NSDate dateWithTimeIntervalSinceNow:1]]; + if(start.timeIntervalSinceNow > -1) + { + test(NO); + } + } + } + @finally + { + [_cond unlock]; + } + +} +-(void) setClientACM:(int)timeout close:(int)close heartbeat:(int)heartbeat +{ + _clientACMTimeout = timeout; + _clientACMClose = close; + _clientACMHeartbeat = heartbeat; +} +-(void) setServerACM:(int)timeout close:(int)close heartbeat:(int)heartbeat +{ + _serverACMTimeout = timeout; + _serverACMClose = close; + _serverACMHeartbeat = heartbeat; +} +@end + +@implementation TestCaseThread +-(id) initWithTestCase:(TestCase*)test +{ + self = [super initWithTarget:self selector:@selector(run) object:nil]; + if(!self) + { + return nil; + } + + _test = test; + _called = NO; + _cond = [[NSCondition alloc] init]; + + return self; +} + +#if defined(__clang__) && !__has_feature(objc_arc) +-(void) dealloc +{ + [_cond release]; + [super dealloc]; +} +#endif + +-(void) run +{ + [_cond lock]; + [_test run]; + _called = YES; + [_cond signal]; + [_cond unlock]; +} + +-(void) join +{ + [_cond lock]; + while(!_called) + { + [_cond wait]; + } + [_cond unlock]; +} +@end + +@interface InvocationHeartbeatTest : TestCase ++(NSString*) getName; +-(void) runTestCase:(id<TestACMRemoteObjectAdapterPrx>)adapter proxy:(id<TestACMTestIntfPrx>)proxy; +@end + +@implementation InvocationHeartbeatTest ++(NSString*) getName +{ + return @"invocation heartbeat"; +} +-(void) runTestCase:(id<TestACMRemoteObjectAdapterPrx>)adapter proxy:(id<TestACMTestIntfPrx>)proxy +{ + [proxy sleep:2]; + + [_cond lock]; + @try + { + test(_heartbeat >= 2); + } + @finally + { + [_cond unlock]; + } +} +@end + +@interface InvocationHeartbeatOnHoldTest : TestCase ++(NSString*) getName; +-(void) runTestCase:(id<TestACMRemoteObjectAdapterPrx>)adapter proxy:(id<TestACMTestIntfPrx>)proxy; +@end + +@implementation InvocationHeartbeatOnHoldTest ++(NSString*) getName +{ + return @"invocation with heartbeat on hold"; +} +-(void) runTestCase:(id<TestACMRemoteObjectAdapterPrx>)adapter proxy:(id<TestACMTestIntfPrx>)proxy +{ + @try + { + // When the OA is put on hold, connections shouldn't + // send heartbeats, the invocation should therefore + // fail. + [proxy sleepAndHold:10]; + test(NO); + } + @catch(ICEConnectionTimeoutException* ex) + { + [adapter activate]; + [proxy interruptSleep]; + + [self waitForClosed]; + } +} +@end + +@interface InvocationNoHeartbeatTest : TestCase ++(id) testCase:(id<TestACMRemoteCommunicatorPrx>)com; ++(NSString*) getName; +-(void) runTestCase:(id<TestACMRemoteObjectAdapterPrx>)adapter proxy:(id<TestACMTestIntfPrx>)proxy; +@end + +@implementation InvocationNoHeartbeatTest ++(id) testCase:(id<TestACMRemoteCommunicatorPrx>)com +{ + id tc = [super testCase:com]; + [tc setServerACM:1 close:2 heartbeat:0]; // Disable heartbeat on invocations + return tc; +} ++(NSString*) getName +{ + return @"invocation with no heartbeat"; +} +-(void) runTestCase:(id<TestACMRemoteObjectAdapterPrx>)adapter proxy:(id<TestACMTestIntfPrx>)proxy +{ + @try + { + // Heartbeats are disabled on the server, the + // invocation should fail since heartbeats are + // expected. + [proxy sleep:10]; + test(NO); + } + @catch(ICEConnectionTimeoutException* ex) + { + [proxy interruptSleep]; + + [self waitForClosed]; + + [_cond lock]; + @try + { + test(_heartbeat == 0); + } + @finally + { + [_cond unlock]; + } + } +} +@end + +@interface InvocationHeartbeatCloseOnIdleTest : TestCase ++(id) testCase:(id<TestACMRemoteCommunicatorPrx>)com; ++(NSString*) getName; +-(void) runTestCase:(id<TestACMRemoteObjectAdapterPrx>)adapter proxy:(id<TestACMTestIntfPrx>)proxy; +@end + +@implementation InvocationHeartbeatCloseOnIdleTest ++(id) testCase:(id<TestACMRemoteCommunicatorPrx>)com +{ + id tc = [super testCase:com]; + [tc setClientACM:1 close:1 heartbeat:0]; // Only close on idle. + [tc setServerACM:1 close:2 heartbeat:0]; // Disable heartbeat on invocations + return tc; +} ++(NSString*) getName +{ + return @"invocation with no heartbeat and close on idle"; +} +-(void) runTestCase:(id<TestACMRemoteObjectAdapterPrx>)adapter proxy:(id<TestACMTestIntfPrx>)proxy +{ + // No close on invocation, the call should succeed this time. + [proxy sleep:2]; + + [_cond lock]; + @try + { + test(_heartbeat == 0); + test(!_closed); + } + @finally + { + [_cond unlock]; + } +} +@end + +@interface CloseOnIdleTest : TestCase ++(id) testCase:(id<TestACMRemoteCommunicatorPrx>)com; ++(NSString*) getName; +-(void) runTestCase:(id<TestACMRemoteObjectAdapterPrx>)adapter proxy:(id<TestACMTestIntfPrx>)proxy; +@end + +@implementation CloseOnIdleTest ++(id) testCase:(id<TestACMRemoteCommunicatorPrx>)com +{ + id tc = [super testCase:com]; + [tc setClientACM:1 close:1 heartbeat:0]; // Only close on idle. + return tc; +} ++(NSString*) getName +{ + return @"close on idle"; +} +-(void) runTestCase:(id<TestACMRemoteObjectAdapterPrx>)adapter proxy:(id<TestACMTestIntfPrx>)proxy +{ + [_cond lock]; + [_cond waitUntilDate:[NSDate dateWithTimeIntervalSinceNow:1.5]]; // Idle for 1.5 seconds + [_cond unlock]; + + [self waitForClosed]; + + [_cond lock]; + @try + { + test(_heartbeat == 0); + } + @finally + { + [_cond unlock]; + } +} +@end + +@interface CloseOnInvocationTest : TestCase ++(id) testCase:(id<TestACMRemoteCommunicatorPrx>)com; ++(NSString*) getName; +-(void) runTestCase:(id<TestACMRemoteObjectAdapterPrx>)adapter proxy:(id<TestACMTestIntfPrx>)proxy; +@end + +@implementation CloseOnInvocationTest ++(id) testCase:(id<TestACMRemoteCommunicatorPrx>)com +{ + id tc = [super testCase:com]; + [tc setClientACM:1 close:2 heartbeat:0]; // Only close on invocation + return tc; +} ++(NSString*) getName +{ + return @"close on invocation"; +} +-(void) runTestCase:(id<TestACMRemoteObjectAdapterPrx>)adapter proxy:(id<TestACMTestIntfPrx>)proxy +{ + [_cond lock]; + [_cond waitUntilDate:[NSDate dateWithTimeIntervalSinceNow:1.5]]; // Idle for 1.5 seconds + [_cond unlock]; + + [_cond lock]; + @try + { + test(_heartbeat == 0); + test(!_closed); + } + @finally + { + [_cond unlock]; + } +} +@end + +@interface CloseOnIdleAndInvocationTest : TestCase ++(id) testCase:(id<TestACMRemoteCommunicatorPrx>)com; ++(NSString*) getName; +-(void) runTestCase:(id<TestACMRemoteObjectAdapterPrx>)adapter proxy:(id<TestACMTestIntfPrx>)proxy; +@end + +@implementation CloseOnIdleAndInvocationTest ++(id) testCase:(id<TestACMRemoteCommunicatorPrx>)com +{ + id tc = [super testCase:com]; + [tc setClientACM:1 close:3 heartbeat:0]; // Only close on idle and invocation + return tc; +} ++(NSString*) getName +{ + return @"close on idle and invocation"; +} +-(void) runTestCase:(id<TestACMRemoteObjectAdapterPrx>)adapter proxy:(id<TestACMTestIntfPrx>)proxy +{ + // + // Put the adapter on hold. The server will not respond to + // the graceful close. This allows to test whether or not + // the close is graceful or forceful. + // + [adapter hold]; + + [_cond lock]; + [_cond waitUntilDate:[NSDate dateWithTimeIntervalSinceNow:1.5]]; // Idle for 1.5 seconds + [_cond unlock]; + + [_cond lock]; + @try + { + test(_heartbeat == 0); + test(!_closed); // Not closed yet because of graceful close. + } + @finally + { + [_cond unlock]; + } + + [adapter activate]; + [_cond lock]; + [_cond waitUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.5]]; + [_cond unlock]; + + [self waitForClosed]; +} +@end + +@interface ForcefulCloseOnIdleAndInvocationTest : TestCase ++(id) testCase:(id<TestACMRemoteCommunicatorPrx>)com; ++(NSString*) getName; +-(void) runTestCase:(id<TestACMRemoteObjectAdapterPrx>)adapter proxy:(id<TestACMTestIntfPrx>)proxy; +@end + +@implementation ForcefulCloseOnIdleAndInvocationTest ++(id) testCase:(id<TestACMRemoteCommunicatorPrx>)com +{ + id tc = [super testCase:com]; + [tc setClientACM:1 close:4 heartbeat:0]; // Only close on idle and invocation + return tc; +} ++(NSString*) getName +{ + return @"forceful close on idle and invocation"; +} +-(void) runTestCase:(id<TestACMRemoteObjectAdapterPrx>)adapter proxy:(id<TestACMTestIntfPrx>)proxy +{ + [adapter hold]; + + [_cond lock]; + [_cond waitUntilDate:[NSDate dateWithTimeIntervalSinceNow:1.5]]; // Idle for 1.5 seconds + [_cond unlock]; + + [self waitForClosed]; + + [_cond lock]; + @try + { + test(_heartbeat == 0); + } + @finally + { + [_cond unlock]; + } +} +@end + +@interface HeartbeatOnIdleTest : TestCase ++(id) testCase:(id<TestACMRemoteCommunicatorPrx>)com; ++(NSString*) getName; +-(void) runTestCase:(id<TestACMRemoteObjectAdapterPrx>)adapter proxy:(id<TestACMTestIntfPrx>)proxy; +@end + +@implementation HeartbeatOnIdleTest ++(id) testCase:(id<TestACMRemoteCommunicatorPrx>)com +{ + id tc = [super testCase:com]; + [tc setServerACM:1 close:-1 heartbeat:2]; // Enable server heartbeats. + return tc; +} ++(NSString*) getName +{ + return @"heartbeat on idle"; +} +-(void) runTestCase:(id<TestACMRemoteObjectAdapterPrx>)adapter proxy:(id<TestACMTestIntfPrx>)proxy +{ + [_cond lock]; + [_cond waitUntilDate:[NSDate dateWithTimeIntervalSinceNow:2]]; + [_cond unlock]; + + [_cond lock]; + @try + { + test(_heartbeat >= 3); + } + @finally + { + [_cond unlock]; + } +} +@end + +@interface HeartbeatAlwaysTest : TestCase ++(id) testCase:(id<TestACMRemoteCommunicatorPrx>)com; ++(NSString*) getName; +-(void) runTestCase:(id<TestACMRemoteObjectAdapterPrx>)adapter proxy:(id<TestACMTestIntfPrx>)proxy; +@end + +@implementation HeartbeatAlwaysTest ++(id) testCase:(id<TestACMRemoteCommunicatorPrx>)com +{ + id tc = [super testCase:com]; + [tc setServerACM:1 close:-1 heartbeat:3]; // Enable server heartbeats. + return tc; +} ++(NSString*) getName +{ + return @"heartbeat always"; +} +-(void) runTestCase:(id<TestACMRemoteObjectAdapterPrx>)adapter proxy:(id<TestACMTestIntfPrx>)proxy +{ + for(int i = 0; i < 12; ++i) + { + [proxy ice_ping]; + + [_cond lock]; + [_cond waitUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.2]]; + [_cond unlock]; + } + + [_cond lock]; + @try + { + test(_heartbeat >= 3); + } + @finally + { + [_cond unlock]; + } +} +@end + +@interface SetACMTest : TestCase ++(id) testCase:(id<TestACMRemoteCommunicatorPrx>)com; ++(NSString*) getName; +-(void) runTestCase:(id<TestACMRemoteObjectAdapterPrx>)adapter proxy:(id<TestACMTestIntfPrx>)proxy; +@end + +@implementation SetACMTest ++(id) testCase:(id<TestACMRemoteCommunicatorPrx>)com +{ + id tc = [super testCase:com]; + [tc setClientACM:15 close:4 heartbeat:2]; + return tc; +} ++(NSString*) getName +{ + return @"setACM/getACM"; +} +-(void) runTestCase:(id<TestACMRemoteObjectAdapterPrx>)adapter proxy:(id<TestACMTestIntfPrx>)proxy +{ + ICEACM* acm = [[proxy ice_getCachedConnection] getACM]; + test(acm.timeout == 15); + test(acm.close == ICECloseOnIdleForceful); + test(acm.heartbeat == ICEHeartbeatOnIdle); + + [[proxy ice_getCachedConnection] setACM:ICENone close:ICENone heartbeat:ICENone]; + acm = [[proxy ice_getCachedConnection] getACM]; + test(acm.timeout == 15); + test(acm.close == ICECloseOnIdleForceful); + test(acm.heartbeat == ICEHeartbeatOnIdle); + + id timeout = @20; + id close = @(ICECloseOnInvocationAndIdle); + id heartbeat = @(ICEHeartbeatOnInvocation); + [[proxy ice_getCachedConnection] setACM:timeout close:close heartbeat:heartbeat]; + acm = [[proxy ice_getCachedConnection] getACM]; + test(acm.timeout == 20); + test(acm.close == ICECloseOnInvocationAndIdle); + test(acm.heartbeat == ICEHeartbeatOnInvocation); +} +@end + +void +acmAllTests(id<ICECommunicator> communicator) +{ + id<TestACMRemoteCommunicatorPrx> com = + [TestACMRemoteCommunicatorPrx uncheckedCast:[communicator stringToProxy:@"communicator:default -p 12010"]]; + + NSMutableArray* tests = [NSMutableArray array]; + + [tests addObject:[InvocationHeartbeatTest testCase:com]]; + [tests addObject:[InvocationHeartbeatOnHoldTest testCase:com]]; + [tests addObject:[InvocationNoHeartbeatTest testCase:com]]; + [tests addObject:[InvocationHeartbeatCloseOnIdleTest testCase:com]]; + + [tests addObject:[CloseOnIdleTest testCase:com]]; + [tests addObject:[CloseOnInvocationTest testCase:com]]; + [tests addObject:[CloseOnIdleAndInvocationTest testCase:com]]; + [tests addObject:[ForcefulCloseOnIdleAndInvocationTest testCase:com]]; + + [tests addObject:[HeartbeatOnIdleTest testCase:com]]; + [tests addObject:[HeartbeatAlwaysTest testCase:com]]; + [tests addObject:[SetACMTest testCase:com]]; + + for(int i = 0; i < tests.count; ++i) + { + [tests[i] initialize]; + } + for(int i = 0; i < tests.count; ++i) + { + [tests[i] start]; + } + for(int i = 0; i < tests.count; ++i) + { + [tests[i] join]; + } + for(int i = 0; i < tests.count; ++i) + { + [tests[i] destroy]; + } + + tprintf("shutting down... "); + [com shutdown]; + tprintf("ok\n"); +} diff --git a/objective-c/test/Ice/acm/Client.m b/objective-c/test/Ice/acm/Client.m new file mode 100644 index 00000000000..c709d687245 --- /dev/null +++ b/objective-c/test/Ice/acm/Client.m @@ -0,0 +1,71 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <TestCommon.h> +#import <ACMTest.h> + +static int +run(id<ICECommunicator> communicator) +{ + void acmAllTests(id<ICECommunicator>); + acmAllTests(communicator); + return EXIT_SUCCESS; +} + +#if TARGET_OS_IPHONE +# define main acmClient +#endif + +int +main(int argc, char* argv[]) +{ + int status; + @autoreleasepool + { + id<ICECommunicator> communicator = nil; + @try + { + ICEInitializationData* initData = [ICEInitializationData initializationData]; + initData.properties = defaultClientProperties(&argc, argv); + [initData.properties setProperty:@"Ice.Warn.Connections" value:@"0"]; + +#if TARGET_OS_IPHONE + initData.prefixTable__ = [NSDictionary dictionaryWithObjectsAndKeys: + @"TestACM", @"::Test", + nil]; +#endif + communicator = [ICEUtil createCommunicator:&argc argv:argv initData:initData]; + status = run(communicator); + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + @catch(TestFailedException* ex) + { + status = EXIT_FAILURE; + } + + if(communicator) + { + @try + { + [communicator destroy]; + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + } + } + return status; +} diff --git a/objective-c/test/Ice/acm/Makefile b/objective-c/test/Ice/acm/Makefile new file mode 100644 index 00000000000..ba45e28b131 --- /dev/null +++ b/objective-c/test/Ice/acm/Makefile @@ -0,0 +1,37 @@ +# ********************************************************************** +# +# Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +# +# This copy of Ice is licensed to you under the terms described in the +# ICE_LICENSE file included in this distribution. +# +# ********************************************************************** + +top_srcdir = ../../.. + +CLIENT = client +SERVER = server + +TARGETS = $(CLIENT) $(SERVER) + +SLICE_OBJS = ACMTest.o + +COBJS = Client.o \ + AllTests.o + +SOBJS = TestI.o \ + Server.o + +OBJS = $(COBJS) $(SOBJS) $(SLICE_OBJS) + +include $(top_srcdir)/config/Make.rules + +CPPFLAGS := -I. -I.. -I../../include $(CPPFLAGS) + +$(CLIENT): $(COBJS) $(SLICE_OBJS) + rm -f $@ + $(CXX) $(LDFLAGS) $(LDEXEFLAGS) -o $@ $(COBJS) $(SLICE_OBJS) $(TEST_LIBS) + +$(SERVER): $(SOBJS) $(SLICE_OBJS) + rm -f $@ + $(CXX) $(LDFLAGS) $(LDEXEFLAGS) -o $@ $(SOBJS) $(SLICE_OBJS) $(TEST_LIBS) diff --git a/objective-c/test/Ice/acm/Server.m b/objective-c/test/Ice/acm/Server.m new file mode 100644 index 00000000000..1d4e7a0a31a --- /dev/null +++ b/objective-c/test/Ice/acm/Server.m @@ -0,0 +1,80 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <acm/TestI.h> +#import <TestCommon.h> + +static int +run(id<ICECommunicator> communicator) +{ + [[communicator getProperties] setProperty:@"TestAdapter.Endpoints" value:@"default -p 12010"]; + [[communicator getProperties] setProperty:@"TestAdapter.ACM.Timeout" value:@"0"]; + id<ICEObjectAdapter> adapter = [communicator createObjectAdapter:@"TestAdapter"]; + [adapter add:[RemoteCommunicatorI remoteCommunicator] + identity:[communicator stringToIdentity:@"communicator"]]; + [adapter activate]; + + // Disable ready print for further adapters. + [[communicator getProperties] setProperty:@"Ice.PrintAdapterReady" value:@"0"]; + + serverReady(communicator); + + [communicator waitForShutdown]; + return EXIT_SUCCESS; +} + +#if TARGET_OS_IPHONE +# define main acmServer +#endif + +int +main(int argc, char* argv[]) +{ + @autoreleasepool + { + int status; + id<ICECommunicator> communicator = nil; + + @try + { + ICEInitializationData* initData = [ICEInitializationData initializationData]; + initData.properties = defaultServerProperties(&argc, argv); + [initData.properties setProperty:@"Ice.Warn.Connections" value:@"0"]; + [initData.properties setProperty:@"Ice.ACM.Timeout" value:@"1"]; + +#if TARGET_OS_IPHONE + initData.prefixTable__ = [NSDictionary dictionaryWithObjectsAndKeys: + @"TestACM", @"::Test", + nil]; +#endif + communicator = [ICEUtil createCommunicator:&argc argv:argv initData:initData]; + status = run(communicator); + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + + if(communicator) + { + @try + { + [communicator destroy]; + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + } + return status; + } +} diff --git a/objective-c/test/Ice/acm/TestI.h b/objective-c/test/Ice/acm/TestI.h new file mode 100644 index 00000000000..4f933ed32c5 --- /dev/null +++ b/objective-c/test/Ice/acm/TestI.h @@ -0,0 +1,30 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <ACMTest.h> + +#import <Foundation/Foundation.h> + +@interface RemoteCommunicatorI : TestACMRemoteCommunicator<TestACMRemoteCommunicator> +@end + +@interface RemoteObjectAdapterI : TestACMRemoteObjectAdapter<TestACMRemoteObjectAdapter> +{ + id<ICEObjectAdapter> _adapter; + id<TestACMTestIntfPrx> _testIntf; +} +-(id) initWithAdapter:(id<ICEObjectAdapter>)adapter; +@end + +@interface TestACMTestIntfI : TestACMTestIntf<TestACMTestIntf> +{ + NSCondition* _cond; +} +@end diff --git a/objective-c/test/Ice/acm/TestI.m b/objective-c/test/Ice/acm/TestI.m new file mode 100644 index 00000000000..5de0e0eeb88 --- /dev/null +++ b/objective-c/test/Ice/acm/TestI.m @@ -0,0 +1,149 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <acm/TestI.h> + +@implementation RemoteCommunicatorI +-(id<TestACMRemoteObjectAdapterPrx>) createObjectAdapter:(ICEInt)timeout close:(ICEInt)close heartbeat:(ICEInt)heartbeat + current:(ICECurrent*)current +{ + id<ICECommunicator> com = [current.adapter getCommunicator]; + id<ICEProperties> properties = [com getProperties]; + NSString* protocol = [properties getPropertyWithDefault:@"Ice.Default.Protocol" value:@"tcp"]; + NSString* host = [properties getPropertyWithDefault:@"Ice.Default.Host" value:@"127.0.0.1"]; + + NSString* name = [ICEUtil generateUUID]; + if(timeout >= 0) + { + [properties setProperty:[name stringByAppendingString:@".ACM.Timeout"] + value:[NSString stringWithFormat:@"%d", timeout]]; + } + if(close >= 0) + { + [properties setProperty:[name stringByAppendingString:@".ACM.Close"] + value:[NSString stringWithFormat:@"%d", close]]; + } + if(heartbeat >= 0) + { + [properties setProperty:[name stringByAppendingString:@".ACM.Heartbeat"] + value:[NSString stringWithFormat:@"%d", heartbeat]]; + } + [properties setProperty:[name stringByAppendingString:@".ThreadPool.Size"] value:@"12"]; + id<ICEObjectAdapter> adapter = + [com createObjectAdapterWithEndpoints:name + endpoints:[NSString stringWithFormat:@"%@ -h \"%@\"", protocol, host]]; + + RemoteObjectAdapterI* remoteAdapter = ICE_AUTORELEASE([[RemoteObjectAdapterI alloc] initWithAdapter:adapter]); + return [TestACMRemoteObjectAdapterPrx uncheckedCast:[current.adapter addWithUUID:remoteAdapter]]; +} +-(void) shutdown:(ICECurrent*)current +{ + [[current.adapter getCommunicator] shutdown]; +} +@end + +@implementation RemoteObjectAdapterI +-(id) initWithAdapter:(id<ICEObjectAdapter>)adapter +{ + self = [super init]; + if(!self) + { + return nil; + } + _adapter = ICE_RETAIN(adapter); + _testIntf = ICE_RETAIN([TestACMTestIntfPrx uncheckedCast:[_adapter add:[TestACMTestIntfI testIntf] + identity:[[_adapter getCommunicator] stringToIdentity:@"test"]]]); + [_adapter activate]; + + return self; +} +#if defined(__clang__) && !__has_feature(objc_arc) +-(void) dealloc +{ + [_adapter release]; + [_testIntf release]; + [super dealloc]; +} +#endif + +-(id<TestACMTestIntfPrx>) getTestIntf:(ICECurrent*)current +{ + return _testIntf; +} +-(void) activate:(ICECurrent*)current +{ + [_adapter activate]; +} +-(void) hold:(ICECurrent*)current +{ + [_adapter hold]; +} +-(void) deactivate:(ICECurrent*)current +{ + @try + { + [_adapter activate]; + } + @catch(ICEObjectAdapterDeactivatedException* ex) + { + } +} +@end + +@implementation TestACMTestIntfI +-(id) init +{ + self = [super init]; + if(!self) + { + return nil; + } + _cond = [[NSCondition alloc] init]; + return self; +} + +#if defined(__clang__) && !__has_feature(objc_arc) +-(void) dealloc +{ + [_cond release]; + [super dealloc]; +} +#endif +-(void) sleep:(ICEInt)delay current:(ICECurrent*)current +{ + [_cond lock]; + @try + { + [_cond waitUntilDate:[NSDate dateWithTimeIntervalSinceNow:delay]]; + } + @finally + { + [_cond unlock]; + } +} +-(void) sleepAndHold:(ICEInt)delay current:(ICECurrent*)current +{ + [_cond lock]; + [current.adapter hold]; + @try + { + [_cond waitUntilDate:[NSDate dateWithTimeIntervalSinceNow:delay]]; + } + @finally + { + [_cond unlock]; + } +} +-(void) interruptSleep:(ICECurrent*)current +{ + [_cond lock]; + [_cond signal]; + [_cond unlock]; +} +@end diff --git a/objective-c/test/Ice/acm/run.py b/objective-c/test/Ice/acm/run.py new file mode 100755 index 00000000000..ce8c5dd4b18 --- /dev/null +++ b/objective-c/test/Ice/acm/run.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python +# ********************************************************************** +# +# Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +# +# This copy of Ice is licensed to you under the terms described in the +# ICE_LICENSE file included in this distribution. +# +# ********************************************************************** + +import os, sys + +path = [ ".", "..", "../..", "../../..", "../../../..", "../../../../.." ] +head = os.path.dirname(sys.argv[0]) +if len(head) > 0: + path = [os.path.join(head, p) for p in path] +path = [os.path.abspath(p) for p in path if os.path.exists(os.path.join(p, "scripts", "TestUtil.py")) ] +if len(path) == 0: + raise RuntimeError("can't find toplevel directory!") +sys.path.append(os.path.join(path[0], "scripts")) +import TestUtil + +TestUtil.clientServerTest() diff --git a/objective-c/test/Ice/adapterDeactivation/.gitignore b/objective-c/test/Ice/adapterDeactivation/.gitignore new file mode 100644 index 00000000000..cd60a278305 --- /dev/null +++ b/objective-c/test/Ice/adapterDeactivation/.gitignore @@ -0,0 +1,9 @@ +// Generated by makegitignore.py + +// IMPORTANT: Do not edit this file -- any edits made here will be lost! +client +server +collocated +.depend +AdapterDeactivationTest.m +AdapterDeactivationTest.h diff --git a/objective-c/test/Ice/adapterDeactivation/AdapterDeactivationTest.ice b/objective-c/test/Ice/adapterDeactivation/AdapterDeactivationTest.ice new file mode 100644 index 00000000000..1f269b93af7 --- /dev/null +++ b/objective-c/test/Ice/adapterDeactivation/AdapterDeactivationTest.ice @@ -0,0 +1,23 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#pragma once + +["objc:prefix:TestAdapterDeactivation"] +module Test +{ + +interface TestIntf +{ + void transient(); + + void deactivate(); +}; + +}; diff --git a/objective-c/test/Ice/adapterDeactivation/AllTests.m b/objective-c/test/Ice/adapterDeactivation/AllTests.m new file mode 100644 index 00000000000..25f93e1936f --- /dev/null +++ b/objective-c/test/Ice/adapterDeactivation/AllTests.m @@ -0,0 +1,70 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <TestCommon.h> +#import <AdapterDeactivationTest.h> + +id<TestAdapterDeactivationTestIntfPrx> +adapterDeactivationAllTests(id<ICECommunicator> communicator) +{ + tprintf("testing stringToProxy... "); + id<ICEObjectPrx> base = [communicator stringToProxy:@"test:default -p 12010"]; + test(base); + tprintf("ok\n"); + + tprintf("testing checked cast... "); + id<TestAdapterDeactivationTestIntfPrx> obj = [TestAdapterDeactivationTestIntfPrx checkedCast:base]; + test(obj); + test([obj isEqual:base]); + tprintf("ok\n"); + + { + tprintf("creating/destroying/recreating object adapter... "); + id<ICEObjectAdapter> adapter = + [communicator createObjectAdapterWithEndpoints:@"TransientTestAdapter" endpoints:@"default -p 9999"]; + @try + { + [communicator createObjectAdapterWithEndpoints:@"TransientTestAdapter" endpoints:@"default -p 9998"]; + test(NO); + } + @catch(ICEAlreadyRegisteredException*) + { + } + [adapter destroy]; + + // + // Use a different port than the first adapter to avoid an @"address already in use" error. + // + adapter = [communicator createObjectAdapterWithEndpoints:@"TransientTestAdapter" endpoints:@"default -p 9998"]; + [adapter destroy]; + tprintf("ok\n"); + } + + tprintf("creating/activating/deactivating object adapter in one operation... "); + [obj transient]; + tprintf("ok\n"); + + tprintf("deactivating object adapter in the server... "); + [obj deactivate]; + tprintf("ok\n"); + + tprintf("testing whether server is gone... "); + @try + { + [obj ice_ping]; + test(NO); + } + @catch(ICELocalException*) + { + tprintf("ok\n"); + } + + return obj; +} diff --git a/objective-c/test/Ice/adapterDeactivation/Client.m b/objective-c/test/Ice/adapterDeactivation/Client.m new file mode 100644 index 00000000000..3572a11bb90 --- /dev/null +++ b/objective-c/test/Ice/adapterDeactivation/Client.m @@ -0,0 +1,70 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <TestCommon.h> +#import <AdapterDeactivationTest.h> + +static int +run(id<ICECommunicator> communicator) +{ + id<TestAdapterDeactivationTestIntfPrx> adapterDeactivationAllTests(id<ICECommunicator>); + adapterDeactivationAllTests(communicator); + return EXIT_SUCCESS; +} + +#if TARGET_OS_IPHONE +# define main adapterDeactivationClient +#endif + +int +main(int argc, char* argv[]) +{ + int status; + @autoreleasepool + { + id<ICECommunicator> communicator = nil; + + @try + { + ICEInitializationData* initData = [ICEInitializationData initializationData]; + initData.properties = defaultClientProperties(&argc, argv); +#if TARGET_OS_IPHONE + initData.prefixTable__ = [NSDictionary dictionaryWithObjectsAndKeys: + @"TestAdapterDeactivation", @"::Test", + nil]; +#endif + communicator = [ICEUtil createCommunicator:&argc argv:argv initData:initData]; + status = run(communicator); + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + @catch(TestFailedException* ex) + { + status = EXIT_FAILURE; + } + + if(communicator) + { + @try + { + [communicator destroy]; + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + } + } + return status; +} diff --git a/objective-c/test/Ice/adapterDeactivation/Collocated.m b/objective-c/test/Ice/adapterDeactivation/Collocated.m new file mode 100644 index 00000000000..468a6f8bbf8 --- /dev/null +++ b/objective-c/test/Ice/adapterDeactivation/Collocated.m @@ -0,0 +1,72 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <adapterDeactivation/TestI.h> +#import <TestCommon.h> + +static int +run(id<ICECommunicator> communicator) +{ + [[communicator getProperties] setProperty:@"TestAdapter.Endpoints" value:@"default -p 12010"]; + id<ICEObjectAdapter> adapter = [communicator createObjectAdapter:@"TestAdapter"]; + [adapter add:[TestAdapterDeactivationI testIntf] identity:[communicator stringToIdentity:@"test"]]; + + id<TestAdapterDeactivationTestIntfPrx> adapterDeactivationAllTests(id<ICECommunicator>); + adapterDeactivationAllTests(communicator); + + [adapter waitForDeactivate]; + return EXIT_SUCCESS; +} + +#if TARGET_OS_IPHONE +# define main adapterDeactivationCollocated +#endif + +int +main(int argc, char* argv[]) +{ + int status; + @autoreleasepool + { + id<ICECommunicator> communicator = nil; + + @try + { + ICEInitializationData* initData = [ICEInitializationData initializationData]; + initData.properties = defaultServerProperties(&argc, argv); +#if TARGET_OS_IPHONE + initData.prefixTable__ = [NSDictionary dictionaryWithObjectsAndKeys: + @"TestAdapterDeactivation", @"::Test", + nil]; +#endif + communicator = [ICEUtil createCommunicator:&argc argv:argv initData:initData]; + status = run(communicator); + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + + if(communicator) + { + @try + { + [communicator destroy]; + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + } + } + return status; +} diff --git a/objective-c/test/Ice/adapterDeactivation/Makefile b/objective-c/test/Ice/adapterDeactivation/Makefile new file mode 100644 index 00000000000..5c2173a9d94 --- /dev/null +++ b/objective-c/test/Ice/adapterDeactivation/Makefile @@ -0,0 +1,46 @@ +# ********************************************************************** +# +# Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +# +# This copy of Ice is licensed to you under the terms described in the +# ICE_LICENSE file included in this distribution. +# +# ********************************************************************** + +top_srcdir = ../../.. + +CLIENT = client +SERVER = server +COLLOCATED = collocated + +TARGETS = $(CLIENT) $(SERVER) $(COLLOCATED) + +SLICE_OBJS = AdapterDeactivationTest.o + +COBJS = Client.o \ + AllTests.o + +SOBJS = TestI.o \ + Server.o + +COLOBJS = Collocated.o \ + TestI.o \ + AllTests.o + +OBJS = $(COBJS) $(SOBJS) $(COLOBJS) $(SLICE_OBJS) + +include $(top_srcdir)/config/Make.rules + +CPPFLAGS := -I. -I.. -I../../include $(CPPFLAGS) + +$(CLIENT): $(COBJS) $(SLICE_OBJS) + rm -f $@ + $(CXX) $(LDFLAGS) $(LDEXEFLAGS) -o $@ $(COBJS) $(SLICE_OBJS) $(TEST_LIBS) + +$(SERVER): $(SOBJS) $(SLICE_OBJS) + rm -f $@ + $(CXX) $(LDFLAGS) $(LDEXEFLAGS) -o $@ $(SOBJS) $(SLICE_OBJS) $(TEST_LIBS) + +$(COLLOCATED): $(COLOBJS) $(SLICE_OBJS) + rm -f $@ + $(CXX) $(LDFLAGS) $(LDEXEFLAGS) -o $@ $(COLOBJS) $(SLICE_OBJS) $(TEST_LIBS) diff --git a/objective-c/test/Ice/adapterDeactivation/Server.m b/objective-c/test/Ice/adapterDeactivation/Server.m new file mode 100644 index 00000000000..d66fd41c1c3 --- /dev/null +++ b/objective-c/test/Ice/adapterDeactivation/Server.m @@ -0,0 +1,72 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <adapterDeactivation/TestI.h> +#import <TestCommon.h> + +static int +run(id<ICECommunicator> communicator) +{ + [[communicator getProperties] setProperty:@"TestAdapter.Endpoints" value:@"default -p 12010:udp"]; + id<ICEObjectAdapter> adapter = [communicator createObjectAdapter:@"TestAdapter"]; + [adapter add:[TestAdapterDeactivationI testIntf] identity:[communicator stringToIdentity:@"test"]]; + [adapter activate]; + + serverReady(communicator); + + [adapter waitForDeactivate]; + return EXIT_SUCCESS; +} + +#if TARGET_OS_IPHONE +# define main adapterDeactivationServer +#endif + +int +main(int argc, char* argv[]) +{ + int status; + @autoreleasepool + { + id<ICECommunicator> communicator = nil; + + @try + { + ICEInitializationData* initData = [ICEInitializationData initializationData]; + initData.properties = defaultServerProperties(&argc, argv); +#if TARGET_OS_IPHONE + initData.prefixTable__ = [NSDictionary dictionaryWithObjectsAndKeys: + @"TestAdapterDeactivation", @"::Test", + nil]; +#endif + communicator = [ICEUtil createCommunicator:&argc argv:argv initData:initData]; + status = run(communicator); + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + + if(communicator) + { + @try + { + [communicator destroy]; + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + } + } + return status; +} diff --git a/objective-c/test/Ice/adapterDeactivation/TestI.h b/objective-c/test/Ice/adapterDeactivation/TestI.h new file mode 100644 index 00000000000..7b24da28a7e --- /dev/null +++ b/objective-c/test/Ice/adapterDeactivation/TestI.h @@ -0,0 +1,15 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <AdapterDeactivationTest.h> + +@interface TestAdapterDeactivationI : TestAdapterDeactivationTestIntf<TestAdapterDeactivationTestIntf> +-(void) transient:(ICECurrent*)current; +-(void) deactivate:(ICECurrent*)current; +@end diff --git a/objective-c/test/Ice/adapterDeactivation/TestI.m b/objective-c/test/Ice/adapterDeactivation/TestI.m new file mode 100644 index 00000000000..bc4c24c87c9 --- /dev/null +++ b/objective-c/test/Ice/adapterDeactivation/TestI.m @@ -0,0 +1,31 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <adapterDeactivation/TestI.h> + +#import <Foundation/NSThread.h> + +@implementation TestAdapterDeactivationI + +-(void) transient:(ICECurrent*)current +{ + id<ICECommunicator> communicator = [current.adapter getCommunicator]; + id<ICEObjectAdapter> adapter = + [communicator createObjectAdapterWithEndpoints:@"TransientTestAdapter" endpoints:@"default -p 9999"]; + [adapter activate]; + [adapter destroy]; +} + +-(void) deactivate:(ICECurrent*)current +{ + [current.adapter deactivate]; + [NSThread sleepForTimeInterval:1]; +} +@end diff --git a/objective-c/test/Ice/adapterDeactivation/run.py b/objective-c/test/Ice/adapterDeactivation/run.py new file mode 100755 index 00000000000..0816938a196 --- /dev/null +++ b/objective-c/test/Ice/adapterDeactivation/run.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python +# ********************************************************************** +# +# Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +# +# This copy of Ice is licensed to you under the terms described in the +# ICE_LICENSE file included in this distribution. +# +# ********************************************************************** + +import os, sys + +path = [ ".", "..", "../..", "../../..", "../../../..", "../../../../.." ] +head = os.path.dirname(sys.argv[0]) +if len(head) > 0: + path = [os.path.join(head, p) for p in path] +path = [os.path.abspath(p) for p in path if os.path.exists(os.path.join(p, "scripts", "TestUtil.py")) ] +if len(path) == 0: + raise RuntimeError("can't find toplevel directory!") +sys.path.append(os.path.join(path[0], "scripts")) +import TestUtil + +print("tests with regular server.") +TestUtil.clientServerTest() +print("tests with collocated server.") +TestUtil.collocatedTest() diff --git a/objective-c/test/Ice/admin/.gitignore b/objective-c/test/Ice/admin/.gitignore new file mode 100644 index 00000000000..a064c4256c8 --- /dev/null +++ b/objective-c/test/Ice/admin/.gitignore @@ -0,0 +1,8 @@ +// Generated by makegitignore.py + +// IMPORTANT: Do not edit this file -- any edits made here will be lost! +client +server +.depend +AdminTest.m +AdminTest.h diff --git a/objective-c/test/Ice/admin/AdminTest.ice b/objective-c/test/Ice/admin/AdminTest.ice new file mode 100644 index 00000000000..5456fece9bd --- /dev/null +++ b/objective-c/test/Ice/admin/AdminTest.ice @@ -0,0 +1,51 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#pragma once + +#include <Ice/Properties.ice> + +["objc:prefix:TestAdmin"] +module Test +{ + +interface RemoteCommunicator +{ + Object* getAdmin(); + + Ice::PropertyDict getChanges(); + + // + // Logger operations + // + void print(string message); + void trace(string category, string message); + void warning(string message); + void error(string message); + + void shutdown(); + + void waitForShutdown(); + + void destroy(); +}; + +interface RemoteCommunicatorFactory +{ + RemoteCommunicator* createCommunicator(Ice::PropertyDict props); + + void shutdown(); +}; + +interface TestFacet +{ + void op(); +}; + +}; diff --git a/objective-c/test/Ice/admin/AllTests.m b/objective-c/test/Ice/admin/AllTests.m new file mode 100644 index 00000000000..006af8832b3 --- /dev/null +++ b/objective-c/test/Ice/admin/AllTests.m @@ -0,0 +1,649 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <TestCommon.h> +#import <admin/TestI.h> + +#import <Foundation/Foundation.h> + +static void +testFacets(id<ICECommunicator> com, BOOL builtInFacets) +{ + if(builtInFacets) + { + test([com findAdminFacet:@"Properties"]); + test([com findAdminFacet:@"Process"]); + test([com findAdminFacet:@"Logger"]); + test([com findAdminFacet:@"Metrics"]); + } + + TestAdminTestFacet* f1 = [TestAdminTestFacetI testFacet]; + TestAdminTestFacet* f2 = [TestAdminTestFacetI testFacet]; + TestAdminTestFacet* f3 = [TestAdminTestFacetI testFacet]; + + [com addAdminFacet:f1 facet:@"Facet1"]; + [com addAdminFacet:f2 facet:@"Facet2"]; + [com addAdminFacet:f3 facet:@"Facet3"]; + + test([com findAdminFacet:@"Facet1"] == f1); + test([com findAdminFacet:@"Facet2"] == f2); + test([com findAdminFacet:@"Facet3"] == f3); + test(![com findAdminFacet:@"Bogus"]); + + ICEFacetMap* facetMap = [com findAllAdminFacets]; + + if(builtInFacets) + { + test([facetMap count] == 7); + test([facetMap objectForKey:@"Properties"] != nil); + test([facetMap objectForKey:@"Process"] != nil); + test([facetMap objectForKey:@"Logger"] != nil); + test([facetMap objectForKey:@"Metrics"] != nil); + } + else + { + test([facetMap count] >= 3); + } + test([facetMap objectForKey:@"Facet1"] != nil); + test([facetMap objectForKey:@"Facet2"] != nil); + test([facetMap objectForKey:@"Facet3"] != nil); + + + @try + { + [com addAdminFacet:f1 facet:@"Facet1"]; + test(NO); + } + @catch(ICEAlreadyRegisteredException*) + { + // Expected + } + + @try + { + [com removeAdminFacet:@"Bogus"]; + test(NO); + } + @catch(ICENotRegisteredException*) + { + // Expected + } + + [com removeAdminFacet:@"Facet1"]; + [com removeAdminFacet:@"Facet2"]; + [com removeAdminFacet:@"Facet3"]; + + @try + { + [com removeAdminFacet:@"Facet1"]; + test(NO); + } + @catch(ICENotRegisteredException*) + { + // Expected + } +} + +@interface RemoteLoggerI : ICERemoteLogger<ICERemoteLogger> +{ + NSCondition* _cond; + int _receivedCalls; + NSString* _expectedPrefix; + ICEMutableLogMessageSeq* _expectedInitMessages; + ICEMutableLogMessageSeq* _expectedLogMessages; +} +-(void) checkNextInit:(NSString*)prefix logMessages:(ICELogMessageSeq*)logMessages; +-(void) checkNextLog:(ICELogMessageType)messageType message:(NSString*)message category:(NSString*)category; +-(void) wait:(int)duration; +@end + +@implementation RemoteLoggerI + +-(id) init +{ + self = [super init]; + if(!self) + { + return nil; + } + self->_receivedCalls = 0; + self->_cond = [[NSCondition alloc] init]; + self->_expectedLogMessages = [[ICEMutableLogMessageSeq alloc] init]; + return self; +} +#if defined(__clang__) && !__has_feature(objc_arc) +-(void) dealloc +{ + [_expectedPrefix release]; + [_expectedInitMessages release]; + [_expectedLogMessages release]; + [_cond release]; + [super dealloc]; +} +#endif +-(void) init:(NSString*)prefix logMessages:(ICEMutableLogMessageSeq*)logMessages current:(ICECurrent*)current +{ + [_cond lock]; + @try + { + test([prefix isEqual:_expectedPrefix]); + test([logMessages isEqual:_expectedInitMessages]); + _receivedCalls++; + [_cond signal]; + } + @finally + { + [_cond unlock]; + } +} +-(void) log:(ICELogMessage*)logMessage current:(ICECurrent*)current +{ + [_cond lock]; + @try + { + ICELogMessage* front = [_expectedLogMessages objectAtIndex:0]; + + test(front.type == logMessage.type && + [front.message isEqual:logMessage.message] && + [front.traceCategory isEqual:logMessage.traceCategory]); + + [_expectedLogMessages removeObjectAtIndex:0]; + _receivedCalls++; + [_cond signal]; + } + @finally + { + [_cond unlock]; + } +} +-(void) checkNextInit:(NSString*)prefix logMessages:(ICEMutableLogMessageSeq*)logMessages +{ + [_cond lock]; + @try + { + _expectedPrefix = ICE_RETAIN(prefix); + _expectedInitMessages = ICE_RETAIN(logMessages); + } + @finally + { + [_cond unlock]; + } +} +-(void) checkNextLog:(ICELogMessageType)type message:(NSString*)message category:(NSString*)category +{ + [_cond lock]; + @try + { + ICELogMessage* msg = [ICELogMessage logMessage:type timestamp:0 traceCategory:category message:message]; + [_expectedLogMessages addObject:msg]; + } + @finally + { + [_cond unlock]; + } +} +-(void) wait:(int)calls +{ + [_cond lock]; + @try + { + _receivedCalls -= calls; + while(_receivedCalls < 0) + { + [_cond wait]; + } + } + @finally + { + [_cond unlock]; + } +} +@end + +void +adminAllTests(id<ICECommunicator> communicator) +{ + tprintf("testing communicator operations... "); + { + // + // Test: Exercise addAdminFacet, findAdminFacet, removeAdminFacet with a typical configuration. + // + ICEInitializationData* init = [ICEInitializationData initializationData]; + init.properties = [ICEUtil createProperties]; + [init.properties setProperty:@"Ice.Admin.Endpoints" value:@"tcp -h 127.0.0.1"]; + [init.properties setProperty:@"Ice.Admin.InstanceName" value:@"Test"]; + id<ICECommunicator> com = [ICEUtil createCommunicator:init]; + testFacets(com, YES); + [com destroy]; + } + { + // + // Test: Verify that the operations work correctly in the presence of facet filters. + // + ICEInitializationData* init = [ICEInitializationData initializationData]; + init.properties = [ICEUtil createProperties]; + [init.properties setProperty:@"Ice.Admin.Endpoints" value:@"tcp -h 127.0.0.1"]; + [init.properties setProperty:@"Ice.Admin.InstanceName" value:@"Test"]; + [init.properties setProperty:@"Ice.Admin.Facets" value:@"Properties"]; + id<ICECommunicator> com = [ICEUtil createCommunicator:init]; + testFacets(com, NO); + [com destroy]; + } + { + // + // Test: Verify that the operations work correctly with the Admin object disabled. + // + id<ICECommunicator> com = [ICEUtil createCommunicator]; + testFacets(com, NO); + [com destroy]; + } + { + // + // Test: Verify that the operations work correctly when Ice.Admin.Enabled is set + // + ICEInitializationData* init = [ICEInitializationData initializationData]; + init.properties = [ICEUtil createProperties]; + [init.properties setProperty:@"Ice.Admin.Enabled" value:@"1"]; + id<ICECommunicator> com = [ICEUtil createCommunicator:init]; + test([com getAdmin] == nil); + + ICEIdentity* ident = [com stringToIdentity:@"test-admin"]; + @try + { + [com createAdmin:nil adminId:ident]; + test(NO); + } + @catch(ICEInitializationException*) + { + } + + id<ICEObjectAdapter> adapter = [com createObjectAdapter:@""]; + test([com createAdmin:adapter adminId:ident] != nil); + test([com getAdmin] != nil); + + testFacets(com, YES); + [com destroy]; + } + { + // + // Test: Verify that the operations work correctly when creation of the Admin object is delayed. + // + ICEInitializationData* init = [ICEInitializationData initializationData]; + init.properties = [ICEUtil createProperties]; + [init.properties setProperty:@"Ice.Admin.Endpoints" value:@"tcp -h 127.0.0.1"]; + [init.properties setProperty:@"Ice.Admin.InstanceName" value:@"Test"]; + [init.properties setProperty:@"Ice.Admin.DelayCreation" value:@"1"]; + id<ICECommunicator> com = [ICEUtil createCommunicator:init]; + testFacets(com, YES); + [com getAdmin]; + testFacets(com, YES); + [com destroy]; + } + tprintf("ok\n"); + + NSString* ref = @"factory:default -p 12010 -t 10000"; + id<TestAdminRemoteCommunicatorFactoryPrx> factory = + [TestAdminRemoteCommunicatorFactoryPrx uncheckedCast:[communicator stringToProxy:ref]]; + + tprintf("testing process facet... "); + { + // + // Test: Verify that Process::shutdown() operation shuts down the communicator. + // + ICEMutablePropertyDict* props = [ICEMutablePropertyDict dictionary]; + [props setObject:@"tcp -h 127.0.0.1" forKey:@"Ice.Admin.Endpoints"]; + [props setObject:@"Test" forKey:@"Ice.Admin.InstanceName"]; + id<TestAdminRemoteCommunicatorPrx> com = [factory createCommunicator:props]; + id<ICEObjectPrx> obj = [com getAdmin]; + id<ICEProcessPrx> proc = [ICEProcessPrx checkedCast:obj facet:@"Process"]; + [proc shutdown]; + [com waitForShutdown]; + [com destroy]; + } + tprintf("ok\n"); + + tprintf("testing properties facet... "); + { + ICEMutablePropertyDict* props = [ICEMutablePropertyDict dictionary]; + [props setObject:@"tcp -h 127.0.0.1" forKey:@"Ice.Admin.Endpoints"]; + [props setObject:@"Test" forKey:@"Ice.Admin.InstanceName"]; + [props setObject:@"1" forKey:@"Prop1"]; + [props setObject:@"2" forKey:@"Prop2"]; + [props setObject:@"3" forKey:@"Prop3"]; + id<TestAdminRemoteCommunicatorPrx> com = [factory createCommunicator:props]; + id<ICEObjectPrx> obj = [com getAdmin]; + id<ICEPropertiesAdminPrx> pa = [ICEPropertiesAdminPrx checkedCast:obj facet:@"Properties"]; + + // + // Test: PropertiesAdmin::getProperty() + // + test([[pa getProperty:@"Prop2"] isEqual:@"2"]); + test([[pa getProperty:@"Bogus"] isEqual:@""]); + + // + // Test: PropertiesAdmin::getProperties() + // + ICEPropertyDict* pd = [pa getPropertiesForPrefix:@""]; + test([pd count] == 5); + test([[pd objectForKey:@"Ice.Admin.Endpoints"] isEqual:@"tcp -h 127.0.0.1"]); + test([[pd objectForKey:@"Ice.Admin.InstanceName"] isEqual:@"Test"]); + test([[pd objectForKey:@"Prop1"] isEqual:@"1"]); + test([[pd objectForKey:@"Prop2"] isEqual:@"2"]); + test([[pd objectForKey:@"Prop3"] isEqual:@"3"]); + + ICEPropertyDict* changes; + + // + // Test: PropertiesAdmin::setProperties() + // + ICEMutablePropertyDict* setProps = [ICEMutablePropertyDict dictionary]; + [setProps setObject:@"10" forKey:@"Prop1"]; // Changed + [setProps setObject:@"20" forKey:@"Prop2"]; // Changed + [setProps setObject:@"" forKey:@"Prop3"]; // Removed + [setProps setObject:@"4" forKey:@"Prop4"]; // Added + [setProps setObject:@"5" forKey:@"Prop5"]; // Added + [pa setProperties:setProps]; + test([[pa getProperty:@"Prop1"] isEqual:@"10"]); + test([[pa getProperty:@"Prop2"] isEqual:@"20"]); + test([[pa getProperty:@"Prop3"] isEqual:@""]); + test([[pa getProperty:@"Prop4"] isEqual:@"4"]); + test([[pa getProperty:@"Prop5"] isEqual:@"5"]); + changes = [com getChanges]; + test([changes count] == 5); + test([[changes objectForKey:@"Prop1"] isEqual:@"10"]); + test([[changes objectForKey:@"Prop2"] isEqual:@"20"]); + test([[changes objectForKey:@"Prop3"] isEqual:@""]); + test([[changes objectForKey:@"Prop4"] isEqual:@"4"]); + test([[changes objectForKey:@"Prop5"] isEqual:@"5"]); + [pa setProperties:setProps]; + changes = [com getChanges]; + test([changes count] == 0); + + [com destroy]; + } + tprintf("ok\n"); + + tprintf("testing logger facet... "); + { + ICEMutablePropertyDict* props = [ICEMutablePropertyDict dictionary]; + [props setObject:@"tcp -h 127.0.0.1" forKey:@"Ice.Admin.Endpoints"]; + [props setObject:@"Test" forKey:@"Ice.Admin.InstanceName"]; + [props setObject:@"1" forKey:@"NullLogger"]; + id<TestAdminRemoteCommunicatorPrx> com = [factory createCommunicator:props]; + + [com trace:@"testCat" message:@"trace"]; + [com warning:@"warning"]; + [com error:@"error"]; + [com print:@"print"]; + + id<ICEObjectPrx> obj = [com getAdmin]; + id<ICELoggerAdminPrx> logger = [ICELoggerAdminPrx checkedCast:obj facet:@"Logger"]; + test(logger); + + NSMutableString* prefix = nil; + + // + // Get all + // + ICELogMessageSeq* logMessages = [logger getLog:nil traceCategories:nil messageMax:-1 prefix:&prefix]; + + test([logMessages count] == 4); + test([prefix isEqual:@"NullLogger"]); + int i = 0; + test([((ICELogMessage*)[logMessages objectAtIndex:i]).traceCategory isEqual:@"testCat"] && + [((ICELogMessage*)[logMessages objectAtIndex:i++]).message isEqual:@"trace"]); + test([((ICELogMessage*)[logMessages objectAtIndex:i++]).message isEqual:@"warning"]); + test([((ICELogMessage*)[logMessages objectAtIndex:i++]).message isEqual:@"error"]); + test([((ICELogMessage*)[logMessages objectAtIndex:i++]).message isEqual:@"print"]); + + // + // Get only errors and warnings + // + [com error:@"error2"]; + [com print:@"print2"]; + [com trace:@"testCat" message:@"trace2"]; + [com warning:@"warning2"]; + + + ICELogMessageTypeSeq* messageTypes; + + ICELogMessageType messageTypesArray1[] = { ICEErrorMessage, ICEWarningMessage }; + messageTypes = [ICEMutableLogMessageTypeSeq dataWithBytes:messageTypesArray1 length:sizeof(messageTypesArray1)]; + + logMessages = [logger getLog:messageTypes traceCategories:nil messageMax:-1 prefix:&prefix]; + test([logMessages count] == 4); + test([prefix isEqual:@"NullLogger"]); + + for(ICELogMessage* message in logMessages) + { + test(message.type == ICEErrorMessage || message.type == ICEWarningMessage); + } + + // + // Get only errors and traces with Cat = "testCat" + // + [com trace:@"testCat2" message:@"A"]; + [com trace:@"testCat" message:@"trace3"]; + [com trace:@"testCat2" message:@"B"]; + + ICELogMessageType messageTypesArray2[] = { ICEErrorMessage, ICETraceMessage }; + messageTypes = [ICEMutableLogMessageTypeSeq dataWithBytes:messageTypesArray2 length:sizeof(messageTypesArray2)]; + + ICEMutableStringSeq* categories = [ICEMutableStringSeq array]; + [categories addObject:@"testCat"]; + + logMessages = [logger getLog:messageTypes traceCategories:categories messageMax:-1 prefix:&prefix]; + test([logMessages count] == 5); + test([prefix isEqual:@"NullLogger"]); + + for(ICELogMessage* message in logMessages) + { + test(message.type == ICEErrorMessage || + (message.type == ICETraceMessage && [message.traceCategory isEqual:@"testCat"])); + } + + // + // Same, but limited to last 2 messages (trace3 + error3) + // + [com error:@"error3"]; + + logMessages = [logger getLog:messageTypes traceCategories:categories messageMax:2 prefix:&prefix]; + test([logMessages count] == 2); + test([prefix isEqual:@"NullLogger"]); + + i = 0; + test([((ICELogMessage*)[logMessages objectAtIndex:i++]).message isEqual:@"trace3"]); + test([((ICELogMessage*)[logMessages objectAtIndex:i++]).message isEqual:@"error3"]); + + // + // Now, test RemoteLogger + // + + id<ICEObjectAdapter> adapter = [communicator createObjectAdapterWithEndpoints:@"RemoteLoggerAdapter" + endpoints:@"tcp -h localhost"]; + + RemoteLoggerI* remoteLogger = [RemoteLoggerI remoteLogger]; + id<ICERemoteLoggerPrx> myProxy = [ICERemoteLoggerPrx uncheckedCast:[adapter addWithUUID:remoteLogger]]; + + [adapter activate]; + + // + // No filtering + // + logMessages = [logger getLog:nil traceCategories:nil messageMax:-1 prefix:&prefix]; + [remoteLogger checkNextInit:prefix logMessages:logMessages]; + + [logger attachRemoteLogger:myProxy messageTypes:nil traceCategories:nil messageMax:-1]; + [remoteLogger wait:1]; + + [remoteLogger checkNextLog:ICETraceMessage message:@"rtrace" category:@"testCat"]; + [remoteLogger checkNextLog:ICEWarningMessage message:@"rwarning" category:@""]; + [remoteLogger checkNextLog:ICEErrorMessage message:@"rerror" category:@""]; + [remoteLogger checkNextLog:ICEPrintMessage message:@"rprint" category:@""]; + + [com trace:@"testCat" message:@"rtrace"]; + [com warning:@"rwarning"]; + [com error:@"rerror"]; + [com print:@"rprint"]; + [remoteLogger wait:4]; + + test([logger detachRemoteLogger:myProxy]); + test(![logger detachRemoteLogger:myProxy]); + + // + // Use Error + Trace with "traceCat" filter with 4 limit + // + logMessages = [logger getLog:messageTypes traceCategories:categories messageMax:4 prefix:&prefix]; + test([logMessages count] == 4); + [remoteLogger checkNextInit:prefix logMessages:logMessages]; + [logger attachRemoteLogger:myProxy messageTypes:messageTypes traceCategories:categories messageMax:4]; + [remoteLogger wait:1]; + + [remoteLogger checkNextLog:ICETraceMessage message:@"rtrace2" category:@"testCat"]; + [remoteLogger checkNextLog:ICEErrorMessage message:@"rerror2" category:@""]; + + [com warning:@"rwarning2"]; + [com trace:@"testCat" message:@"rtrace2"]; + [com warning:@"rwarning3"]; + [com error:@"rerror2"]; + [com print:@"rprint2"]; + [remoteLogger wait:2]; + + // + // Attempt reconnection with slightly different proxy + // + @try + { + [logger attachRemoteLogger:[myProxy ice_oneway] + messageTypes:messageTypes + traceCategories:categories + messageMax:4]; + test(NO); + } + @catch(ICERemoteLoggerAlreadyAttachedException*) + { + // expected + } + + [com destroy]; + } + tprintf("ok\n"); + + tprintf("testing custom facet... "); + { + // + // Test: Verify that the custom facet is present. + // + ICEMutablePropertyDict* props = [ICEMutablePropertyDict dictionary]; + [props setObject:@"tcp -h 127.0.0.1" forKey:@"Ice.Admin.Endpoints"]; + [props setObject:@"Test" forKey:@"Ice.Admin.InstanceName"]; + id<TestAdminRemoteCommunicatorPrx> com = [factory createCommunicator:props]; + id<ICEObjectPrx> obj = [com getAdmin]; + id<TestAdminTestFacetPrx> tf = [TestAdminTestFacetPrx checkedCast:obj facet:@"TestFacet"]; + [tf op]; + [com destroy]; + } + tprintf("ok\n"); + + tprintf("testing facet filtering... "); + { + // + // Test: Set Ice.Admin.Facets to expose only the Properties facet, + // meaning no other facet is available. + // + ICEMutablePropertyDict* props = [ICEMutablePropertyDict dictionary]; + [props setObject:@"tcp -h 127.0.0.1" forKey:@"Ice.Admin.Endpoints"]; + [props setObject:@"Test" forKey:@"Ice.Admin.InstanceName"]; + [props setObject:@"Properties" forKey:@"Ice.Admin.Facets"]; + id<TestAdminRemoteCommunicatorPrx> com = [factory createCommunicator:props]; + id<ICEObjectPrx> obj = [com getAdmin]; + id<ICEProcessPrx> proc = [ICEProcessPrx checkedCast:obj facet:@"Process"]; + test(proc == nil); + id<TestAdminTestFacetPrx> tf = [TestAdminTestFacetPrx checkedCast:obj facet:@"TestFacet"]; + test(tf == nil); + [com destroy]; + } + { + // + // Test: Set Ice.Admin.Facets to expose only the Process facet, + // meaning no other facet is available. + // + ICEMutablePropertyDict* props = [ICEMutablePropertyDict dictionary]; + [props setObject:@"tcp -h 127.0.0.1" forKey:@"Ice.Admin.Endpoints"]; + [props setObject:@"Test" forKey:@"Ice.Admin.InstanceName"]; + [props setObject:@"Process" forKey:@"Ice.Admin.Facets"]; + id<TestAdminRemoteCommunicatorPrx> com = [factory createCommunicator:props]; + id<ICEObjectPrx> obj = [com getAdmin]; + id<ICEPropertiesAdminPrx> pa = [ICEPropertiesAdminPrx checkedCast:obj facet:@"Properties"]; + test(pa == nil); + id<TestAdminTestFacetPrx> tf = [TestAdminTestFacetPrx checkedCast:obj facet:@"TestFacet"]; + test(tf == nil); + [com destroy]; + } + { + // + // Test: Set Ice.Admin.Facets to expose only the TestFacet facet, + // meaning no other facet is available. + // + ICEMutablePropertyDict* props = [ICEMutablePropertyDict dictionary]; + [props setObject:@"tcp -h 127.0.0.1" forKey:@"Ice.Admin.Endpoints"]; + [props setObject:@"Test" forKey:@"Ice.Admin.InstanceName"]; + [props setObject:@"TestFacet" forKey:@"Ice.Admin.Facets"]; + id<TestAdminRemoteCommunicatorPrx> com = [factory createCommunicator:props]; + id<ICEObjectPrx> obj = [com getAdmin]; + id<ICEPropertiesAdminPrx> pa = [ICEPropertiesAdminPrx checkedCast:obj facet:@"Properties"]; + test(pa == nil); + id<ICEProcessPrx> proc = [ICEProcessPrx checkedCast:obj facet:@"Process"]; + test(proc == nil); + [com destroy]; + } + { + // + // Test: Set Ice.Admin.Facets to expose two facets. Use whitespace to separate the + // facet names. + // + ICEMutablePropertyDict* props = [ICEMutablePropertyDict dictionary]; + [props setObject:@"tcp -h 127.0.0.1" forKey:@"Ice.Admin.Endpoints"]; + [props setObject:@"Test" forKey:@"Ice.Admin.InstanceName"]; + [props setObject:@"Properties TestFacet" forKey:@"Ice.Admin.Facets"]; + id<TestAdminRemoteCommunicatorPrx> com = [factory createCommunicator:props]; + id<ICEObjectPrx> obj = [com getAdmin]; + id<ICEPropertiesAdminPrx> pa = [ICEPropertiesAdminPrx checkedCast:obj facet:@"Properties"]; + test([[pa getProperty:@"Ice.Admin.InstanceName"] isEqual:@"Test"]); + id<TestAdminTestFacetPrx> tf = [TestAdminTestFacetPrx checkedCast:obj facet:@"TestFacet"]; + [tf op]; + id<ICEProcessPrx> proc = [ICEProcessPrx checkedCast:obj facet:@"Process"]; + test(proc == nil); + [com destroy]; + } + { + // + // Test: Set Ice.Admin.Facets to expose two facets. Use a comma to separate the + // facet names. + // + ICEMutablePropertyDict* props = [ICEMutablePropertyDict dictionary]; + [props setObject:@"tcp -h 127.0.0.1" forKey:@"Ice.Admin.Endpoints"]; + [props setObject:@"Test" forKey:@"Ice.Admin.InstanceName"]; + [props setObject:@"TestFacet, Process" forKey:@"Ice.Admin.Facets"]; + id<TestAdminRemoteCommunicatorPrx> com = [factory createCommunicator:props]; + id<ICEObjectPrx> obj = [com getAdmin]; + id<ICEPropertiesAdminPrx> pa = [ICEPropertiesAdminPrx checkedCast:obj facet:@"Properties"]; + test(pa == nil); + id<TestAdminTestFacetPrx> tf = [TestAdminTestFacetPrx checkedCast:obj facet:@"TestFacet"]; + [tf op]; + id<ICEProcessPrx> proc = [ICEProcessPrx checkedCast:obj facet:@"Process"]; + [proc shutdown]; + [com waitForShutdown]; + [com destroy]; + } + tprintf("ok\n"); + + [factory shutdown]; +} diff --git a/objective-c/test/Ice/admin/Client.m b/objective-c/test/Ice/admin/Client.m new file mode 100644 index 00000000000..490d51f8a88 --- /dev/null +++ b/objective-c/test/Ice/admin/Client.m @@ -0,0 +1,69 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <TestCommon.h> +#import <AdminTest.h> + +static int +run(id<ICECommunicator> communicator) +{ + void adminAllTests(id<ICECommunicator>); + adminAllTests(communicator); + return EXIT_SUCCESS; +} + +#if TARGET_OS_IPHONE +# define main adminClient +#endif + +int +main(int argc, char* argv[]) +{ + int status; + @autoreleasepool + { + id<ICECommunicator> communicator = nil; + @try + { + ICEInitializationData* initData = [ICEInitializationData initializationData]; + initData.properties = defaultClientProperties(&argc, argv); +#if TARGET_OS_IPHONE + initData.prefixTable__ = [NSDictionary dictionaryWithObjectsAndKeys: + @"TestAdmin", @"::Test", + nil]; +#endif + communicator = [ICEUtil createCommunicator:&argc argv:argv initData:initData]; + status = run(communicator); + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + @catch(TestFailedException* ex) + { + status = EXIT_FAILURE; + } + + if(communicator) + { + @try + { + [communicator destroy]; + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + } + } + return status; +} diff --git a/objective-c/test/Ice/admin/Makefile b/objective-c/test/Ice/admin/Makefile new file mode 100644 index 00000000000..af39c7ba045 --- /dev/null +++ b/objective-c/test/Ice/admin/Makefile @@ -0,0 +1,38 @@ +# ********************************************************************** +# +# Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +# +# This copy of Ice is licensed to you under the terms described in the +# ICE_LICENSE file included in this distribution. +# +# ********************************************************************** + +top_srcdir = ../../.. + +CLIENT = client +SERVER = server + +TARGETS = $(CLIENT) $(SERVER) + +SLICE_OBJS = AdminTest.o + +COBJS = Client.o \ + TestI.o \ + AllTests.o + +SOBJS = TestI.o \ + Server.o + +OBJS = $(COBJS) $(SOBJS) $(SLICE_OBJS) + +include $(top_srcdir)/config/Make.rules + +CPPFLAGS := -I. -I.. -I../../include $(CPPFLAGS) + +$(CLIENT): $(COBJS) $(SLICE_OBJS) + rm -f $@ + $(CXX) $(LDFLAGS) $(LDEXEFLAGS) -o $@ $(COBJS) $(SLICE_OBJS) $(TEST_LIBS) + +$(SERVER): $(SOBJS) $(SLICE_OBJS) + rm -f $@ + $(CXX) $(LDFLAGS) $(LDEXEFLAGS) -o $@ $(SOBJS) $(SLICE_OBJS) $(TEST_LIBS) diff --git a/objective-c/test/Ice/admin/Server.m b/objective-c/test/Ice/admin/Server.m new file mode 100644 index 00000000000..f2dff2b9ec5 --- /dev/null +++ b/objective-c/test/Ice/admin/Server.m @@ -0,0 +1,76 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <admin/TestI.h> +#import <TestCommon.h> + +static int +run(id<ICECommunicator> communicator) +{ + [[communicator getProperties] setProperty:@"TestAdapter.Endpoints" value:@"default -p 12010 -t 10000"]; + id<ICEObjectAdapter> adapter = [communicator createObjectAdapter:@"TestAdapter"]; + [adapter add:[TestAdminRemoteCommunicatorFactoryI remoteCommunicatorFactory] + identity:[communicator stringToIdentity:@"factory"]]; + [adapter activate]; + + // Disable ready print for further adapters. + [[communicator getProperties] setProperty:@"Ice.PrintAdapterReady" value:@"0"]; + + serverReady(communicator); + + [communicator waitForShutdown]; + return EXIT_SUCCESS; +} + +#if TARGET_OS_IPHONE +# define main adminServer +#endif + +int +main(int argc, char* argv[]) +{ + @autoreleasepool + { + int status; + id<ICECommunicator> communicator = nil; + + @try + { + ICEInitializationData* initData = [ICEInitializationData initializationData]; + initData.properties = defaultServerProperties(&argc, argv); +#if TARGET_OS_IPHONE + initData.prefixTable__ = [NSDictionary dictionaryWithObjectsAndKeys: + @"TestAdmin", @"::Test", + nil]; +#endif + communicator = [ICEUtil createCommunicator:&argc argv:argv initData:initData]; + status = run(communicator); + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + + if(communicator) + { + @try + { + [communicator destroy]; + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + } + return status; + } +} diff --git a/objective-c/test/Ice/admin/TestI.h b/objective-c/test/Ice/admin/TestI.h new file mode 100644 index 00000000000..5dbd0808187 --- /dev/null +++ b/objective-c/test/Ice/admin/TestI.h @@ -0,0 +1,30 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <AdminTest.h> + +#import <Foundation/Foundation.h> + +@interface TestAdminRemoteCommunicatorI : TestAdminRemoteCommunicator<TestAdminRemoteCommunicator, + ICEPropertiesAdminUpdateCallback> +{ + id<ICECommunicator> _communicator; + ICEMutablePropertyDict* _changes; + BOOL _called; + NSCondition* _cond; +} ++(id) remoteCommunicator:(id<ICECommunicator>)communicator; +@end + +@interface TestAdminRemoteCommunicatorFactoryI : TestAdminRemoteCommunicatorFactory<TestAdminRemoteCommunicatorFactory> +@end + +@interface TestAdminTestFacetI : TestAdminTestFacet<TestAdminTestFacet> +@end diff --git a/objective-c/test/Ice/admin/TestI.m b/objective-c/test/Ice/admin/TestI.m new file mode 100644 index 00000000000..a63a31db733 --- /dev/null +++ b/objective-c/test/Ice/admin/TestI.m @@ -0,0 +1,192 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <admin/TestI.h> + +// +// A no-op Logger, used when testing the Logger Admin +// +@interface NullLogger : ICELocalObject<ICELogger> +@end + +@implementation NullLogger +-(void) print:(NSString*)message +{ +} +-(void) trace:(NSString*)category message:(NSString*)message +{ +} +-(void) warning:(NSString*)message +{ +} +-(void) error:(NSString*)message +{ +} +-(NSMutableString*) getPrefix +{ + return [@"NullLogger" mutableCopy]; +} +-(id<ICELogger>) cloneWithPrefix:(NSString*)prefix +{ + return self; +} +@end + +@implementation TestAdminRemoteCommunicatorI + ++(id) remoteCommunicator:(id<ICECommunicator>)communicator +{ + TestAdminRemoteCommunicatorI* obj = [TestAdminRemoteCommunicatorI remoteCommunicator]; + obj->_communicator = ICE_RETAIN(communicator); + obj->_called = NO; + obj->_cond = [[NSCondition alloc] init]; + return obj; +} +#if defined(__clang__) && !__has_feature(objc_arc) +-(void) dealloc +{ + [_communicator release]; + [_cond release]; + [_changes release]; + [super dealloc]; +} +#endif +-(id<ICEObjectPrx>) getAdmin:(ICECurrent*)current +{ + return [_communicator getAdmin]; +} + +-(ICEPropertyDict*) getChanges:(ICECurrent*)current +{ + [_cond lock]; + @try + { + // + // The client calls PropertiesAdmin::setProperties() and then invokes + // this operation. Since setProperties() is implemented using AMD, the + // client might receive its reply and then call getChanges() before our + // updated() method is called. We block here to ensure that updated() + // gets called before we return the most recent set of changes. + // + while(!_called) + { + [_cond wait]; + } + _called = NO; + return _changes; + } + @finally + { + [_cond unlock]; + } +} +-(void) print:(NSString*)message current:(ICECurrent*)current +{ + [[_communicator getLogger] print:message]; +} +-(void) trace:(NSString*)category message:(NSString*)message current:(ICECurrent*)current +{ + [[_communicator getLogger] trace:category message:message]; +} +-(void) warning:(NSString*)message current:(ICECurrent*)current +{ + [[_communicator getLogger] warning:message]; +} +-(void) error:(NSString*)message current:(ICECurrent*)current +{ + [[_communicator getLogger] error:message]; +} +-(void) shutdown:(ICECurrent*)current +{ + [_communicator shutdown]; +} +-(void) waitForShutdown:(ICECurrent*)current +{ + // + // Note that we are executing in a thread of the *main* communicator, + // not the one that is being shut down. + // + [_communicator waitForShutdown]; +} +-(void) destroy:(ICECurrent*)current +{ + [_communicator destroy]; +} +-(void) updated:(ICEMutablePropertyDict*)changes +{ + [_cond lock]; + @try + { + _changes = ICE_RETAIN(changes); + _called = YES; + [_cond signal]; + } + @finally + { + [_cond unlock]; + } +} +@end + +@implementation TestAdminRemoteCommunicatorFactoryI +-(id<TestAdminRemoteCommunicatorPrx>) createCommunicator:(ICEMutablePropertyDict*)props current:(ICECurrent*)current +{ + // + // Prepare the property set using the given properties. + // + ICEInitializationData* init = [ICEInitializationData initializationData]; + init.properties = [ICEUtil createProperties]; + for(NSString* key in props) + { + [init.properties setProperty:key value:[props objectForKey:key]]; + } + + if([init.properties getPropertyAsInt:@"NullLogger"] > 0) + { + init.logger = [NullLogger new]; + } + + // + // Initialize a new communicator. + // + id<ICECommunicator> communicator = [ICEUtil createCommunicator:init]; + + // + // Install a custom admin facet. + // + [communicator addAdminFacet:[TestAdminTestFacetI testFacet] facet:@"TestFacet"]; + + // + // The RemoteCommunicator servant also implements PropertiesAdminUpdateCallback. + // Set the callback on the admin facet. + // + TestAdminRemoteCommunicatorI* servant = [TestAdminRemoteCommunicatorI remoteCommunicator:communicator]; + ICEObject* propFacet = [communicator findAdminFacet:@"Properties"]; + if(propFacet != nil) + { + //NSAssert([propFacet isKindOfClass:[ICENativePropertiesAdmin class]], @""); + id<ICENativePropertiesAdmin> admin = (id<ICENativePropertiesAdmin>)propFacet; + [admin addUpdateCallback:servant]; + } + + id<ICEObjectPrx> proxy = [current.adapter addWithUUID:servant]; + return [TestAdminRemoteCommunicatorPrx uncheckedCast:proxy]; +} + +-(void) shutdown:(ICECurrent*)current +{ + [[current.adapter getCommunicator] shutdown]; +} +@end + +@implementation TestAdminTestFacetI +-(void) op:(ICECurrent*)current +{ +} +@end diff --git a/objective-c/test/Ice/admin/run.py b/objective-c/test/Ice/admin/run.py new file mode 100755 index 00000000000..ce8c5dd4b18 --- /dev/null +++ b/objective-c/test/Ice/admin/run.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python +# ********************************************************************** +# +# Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +# +# This copy of Ice is licensed to you under the terms described in the +# ICE_LICENSE file included in this distribution. +# +# ********************************************************************** + +import os, sys + +path = [ ".", "..", "../..", "../../..", "../../../..", "../../../../.." ] +head = os.path.dirname(sys.argv[0]) +if len(head) > 0: + path = [os.path.join(head, p) for p in path] +path = [os.path.abspath(p) for p in path if os.path.exists(os.path.join(p, "scripts", "TestUtil.py")) ] +if len(path) == 0: + raise RuntimeError("can't find toplevel directory!") +sys.path.append(os.path.join(path[0], "scripts")) +import TestUtil + +TestUtil.clientServerTest() diff --git a/objective-c/test/Ice/ami/.gitignore b/objective-c/test/Ice/ami/.gitignore new file mode 100644 index 00000000000..a8a4ccc28db --- /dev/null +++ b/objective-c/test/Ice/ami/.gitignore @@ -0,0 +1,9 @@ +// Generated by makegitignore.py + +// IMPORTANT: Do not edit this file -- any edits made here will be lost! +client +server +collocated +.depend +AMITest.m +AMITest.h diff --git a/objective-c/test/Ice/ami/AMITest.ice b/objective-c/test/Ice/ami/AMITest.ice new file mode 100644 index 00000000000..b0c0e8606fe --- /dev/null +++ b/objective-c/test/Ice/ami/AMITest.ice @@ -0,0 +1,41 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#pragma once + +#include <Ice/BuiltinSequences.ice> + +["objc:prefix:TestAMI"] +module Test +{ + +exception TestIntfException +{ +}; + +interface TestIntf +{ + void op(); + void opWithPayload(Ice::ByteSeq seq); + int opWithResult(); + void opWithUE() + throws TestIntfException; + void opBatch(); + int opBatchCount(); + bool waitForBatch(int count); + void shutdown(); +}; + +interface TestIntfController +{ + void holdAdapter(); + void resumeAdapter(); +}; + +}; diff --git a/objective-c/test/Ice/ami/AllTests.m b/objective-c/test/Ice/ami/AllTests.m new file mode 100644 index 00000000000..acfc5fe6abc --- /dev/null +++ b/objective-c/test/Ice/ami/AllTests.m @@ -0,0 +1,849 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <TestCommon.h> +#import <AMITest.h> + +#import <Foundation/Foundation.h> + +@interface TestAMICallback : NSObject +{ + BOOL called; + NSCondition* cond; +} +-(BOOL) check; +-(void) called; +@end + +@implementation TestAMICallback +-(id) init +{ + self = [super init]; + if(!self) + { + return nil; + } + cond = [[NSCondition alloc] init]; + return self; +} + +#if defined(__clang__) && !__has_feature(objc_arc) +-(void) dealloc +{ + [cond release]; + [super dealloc]; +} +#endif + +-(BOOL) check +{ + [cond lock]; + while(!called) + { + if(![cond waitUntilDate:[NSDate dateWithTimeIntervalSinceNow:50]]) + { + return NO; + } + } + called = NO; + [cond unlock]; + return YES; +} +-(void) called +{ + [cond lock]; + called = YES; + [cond signal]; + [cond unlock]; +} + ++(id) create +{ + return ICE_AUTORELEASE([[TestAMICallback alloc] init]); +} + +@end + +void +amiAllTests(id<ICECommunicator> communicator, BOOL collocated) +{ + NSString* ref = @"test:default -p 12010"; + id<ICEObjectPrx> base = [communicator stringToProxy:(ref)]; + id<TestAMITestIntfPrx> p = [TestAMITestIntfPrx checkedCast:base]; + test(p); + + ref = @"testController:tcp -p 12011"; + base = [communicator stringToProxy:ref]; + TestAMITestIntfControllerPrx* testController = [TestAMITestIntfControllerPrx uncheckedCast:base]; + test(testController); + + tprintf("testing begin/end invocation... "); + { + ICEContext* ctx = [ICEContext dictionary]; + id<ICEAsyncResult> result; + + result = [p begin_ice_isA:[TestAMITestIntfPrx ice_staticId]]; + test([p end_ice_isA:result]); + result = [p begin_ice_isA:[TestAMITestIntfPrx ice_staticId] context:ctx]; + test([p end_ice_isA:result]); + + result = [p begin_ice_ping]; + [p end_ice_ping:result]; + result = [p begin_ice_ping:ctx]; + [p end_ice_ping:result]; + + result = [p begin_ice_id]; + test([[p end_ice_id:result] isEqualToString:[TestAMITestIntfPrx ice_staticId]]); + result = [p begin_ice_id:ctx]; + test([[p end_ice_id:result] isEqualToString:[TestAMITestIntfPrx ice_staticId]]); + + result = [p begin_ice_ids]; + test([[p end_ice_ids:result] count] == 2); + result = [p begin_ice_ids:ctx]; + test([[p end_ice_ids:result] count] == 2); + + if(!collocated) + { + result = [p begin_ice_getConnection]; + test([p end_ice_getConnection:result]); + } + + result = [p begin_op]; + [p end_op:result]; + result = [p begin_op:ctx]; + [p end_op:result]; + + result = [p begin_opWithResult]; + test([p end_opWithResult:result] == 15); + result = [p begin_opWithResult:ctx]; + test([p end_opWithResult:result] == 15); + + result = [p begin_opWithUE]; + @try + { + [p end_opWithUE:result]; + test(NO); + } + @catch(TestAMITestIntfException*) + { + } + result = [p begin_opWithUE:ctx]; + @try + { + [p end_opWithUE:result]; + test(NO); + } + @catch(TestAMITestIntfException*) + { + } + } + tprintf("ok\n"); + + tprintf("testing response callback... "); + { + TestAMICallback* cb = [TestAMICallback create]; + ICEContext* ctx = [NSDictionary dictionary]; + void (^exCB)(ICEException*) = ^(ICEException* ex) + { + test(NO); + }; + + void (^isACB)(BOOL) = ^(BOOL ret) { test(ret); [cb called]; }; + [p begin_ice_isA:[TestAMITestIntfPrx ice_staticId] response:isACB exception:exCB]; + [cb check]; + [p begin_ice_isA:[TestAMITestIntfPrx ice_staticId] context:ctx response:isACB exception:exCB]; + [cb check]; + + void (^pingCB)() = ^ { [cb called]; }; + [p begin_ice_ping:pingCB exception:exCB]; + [cb check]; + [p begin_ice_ping:ctx response:pingCB exception:exCB]; + [cb check]; + + void (^idCB)(NSString* typeId) = ^(NSString* typeId) + { + test([typeId isEqualToString:[TestAMITestIntfPrx ice_staticId]]); + [cb called]; + }; + + [p begin_ice_id:idCB exception:exCB]; + [cb check]; + [p begin_ice_id:ctx response:idCB exception:exCB]; + [cb check]; + + void (^idsCB)(NSArray* types) = ^(NSArray* types) + { + test([types count] == 2); + [cb called]; + }; + + [p begin_ice_ids:idsCB exception:exCB]; + [cb check]; + [p begin_ice_ids:ctx response:idsCB exception:exCB]; + [cb check]; + + void (^conCB)(id<ICEConnection>) = ^(id<ICEConnection> conn) + { + test(conn); + [cb called]; + }; + + if(!collocated) + { + [p begin_ice_getConnection:conCB exception:exCB]; + [cb check]; + } + + void (^opCB)() = ^ { [cb called]; }; + [p begin_op:opCB exception:exCB]; + [cb check]; + [p begin_op:ctx response:opCB exception:exCB]; + [cb check]; + [p begin_op:nil exception:exCB]; + [p begin_op:ctx response:nil exception:exCB]; + + void (^opWithResultCB)(ICEInt) = ^(ICEInt r) + { + test(r == 15); + [cb called]; + }; + [p begin_opWithResult:opWithResultCB exception:exCB]; + [cb check]; + [p begin_opWithResult:ctx response:opWithResultCB exception:exCB]; + [cb check]; + + void (^opWithUE)() = ICE_AUTORELEASE([ ^() { test(NO); } copy]); + void (^opWithUEEx)(ICEException*) = ^(ICEException* ex) + { + @try + { + @throw ex; + test(NO); + } + @catch(TestAMITestIntfException*) + { + [cb called]; + } + }; + [p begin_opWithUE:opWithUE exception:opWithUEEx]; + [cb check]; + [p begin_opWithUE:ctx response:opWithUE exception:opWithUEEx]; + [cb check]; + [p begin_opWithUE:nil exception:opWithUEEx]; + [cb check]; + [p begin_opWithUE:ctx response:nil exception:opWithUEEx]; + [cb check]; + } + tprintf("ok\n"); + + tprintf("testing local exceptions... "); + { + TestAMITestIntfPrx* indirect = [TestAMITestIntfPrx uncheckedCast:[p ice_adapterId:@"dummy"]]; + id<ICEAsyncResult> r; + + r = [indirect begin_op]; + @try + { + [indirect end_op:r]; + test(NO); + } + @catch(ICENoEndpointException*) + { + } + + @try + { + r = [[p ice_oneway] begin_ice_id]; + test(NO); + } + @catch(NSException* ex) + { + test([ex name] == NSInvalidArgumentException); + } + @try + { + r = [[p ice_oneway] begin_opWithResult]; + test(NO); + } + @catch(NSException* ex) + { + test([ex name] == NSInvalidArgumentException); + } + + @try + { + r = [p begin_op:nil exception:nil]; + test(NO); + } + @catch(NSException* ex) + { + test([ex name] == NSInvalidArgumentException); + } + + // + // Check that CommunicatorDestroyedException is raised directly. + // + if([p ice_getConnection]) + { + ICEInitializationData* initData = [ICEInitializationData initializationData]; + [initData setProperties:[[communicator getProperties] clone]]; + id<ICECommunicator> ic = [ICEUtil createCommunicator:initData]; + id<ICEObjectPrx> obj = [ic stringToProxy:[p ice_toString]]; + id<TestAMITestIntfPrx> p2 = [TestAMITestIntfPrx checkedCast:obj]; + + [ic destroy]; + + @try + { + [p2 begin_op]; + test(NO); + } + @catch(ICECommunicatorDestroyedException*) + { + // Expected. + } + } + } + tprintf("ok\n"); + + tprintf("testing exception callback... "); + { + id<TestAMITestIntfPrx> i = [TestAMITestIntfPrx uncheckedCast:[p ice_adapterId:@"dummy"]]; + TestAMICallback* cb = [TestAMICallback create]; + ICEContext* ctx = [NSDictionary dictionary]; + + void (^exCB)(ICEException*) = ^(ICEException* ex) { + test([ex isKindOfClass:[ICENoEndpointException class]]); + [cb called]; + }; + + void (^isACB)(BOOL) = ICE_AUTORELEASE([ ^(BOOL ret) { test(NO); } copy ]); + [i begin_ice_isA:@"dummy" response:isACB exception:exCB]; + [cb check]; + [i begin_ice_isA:@"dummy" context:ctx response:isACB exception:exCB]; + [cb check]; + + void (^pingCB)() = ICE_AUTORELEASE([ ^ { test(NO); } copy ]); + [i begin_ice_ping:pingCB exception:exCB]; + [cb check]; + [i begin_ice_ping:ctx response:pingCB exception:exCB]; + [cb check]; + + void (^idCB)(NSString*) = ICE_AUTORELEASE([ ^(NSString* ret) { test(NO); } copy ]); + [i begin_ice_id:idCB exception:exCB]; + [cb check]; + [i begin_ice_id:ctx response:idCB exception:exCB]; + [cb check]; + + void (^idsCB)(NSArray*) = ICE_AUTORELEASE([ ^(NSArray* ret) { test(NO); } copy ]); + [i begin_ice_ids:idsCB exception:exCB]; + [cb check]; + [i begin_ice_ids:ctx response:idsCB exception:exCB]; + [cb check]; + + if(!collocated) + { + void (^conCB)(id<ICEConnection>) = ICE_AUTORELEASE([ ^(id<ICEConnection> ret) { test(NO); } copy ]); + [i begin_ice_getConnection:conCB exception:exCB]; + [cb check]; + } + + void (^opCB)() = ICE_AUTORELEASE([ ^ { test(NO); } copy ]); + [i begin_op:opCB exception:exCB]; + [cb check]; + [i begin_op:ctx response:opCB exception:exCB]; + [cb check]; + + @try + { + [p begin_opWithResult:nil exception:^(ICEException* ex) { test(NO); }]; + test(NO); + } + @catch(NSException* ex) + { + test([ex name] == NSInvalidArgumentException); + } + } + tprintf("ok\n"); + + tprintf("testing sent callback... "); + { + TestAMICallback* cb = [TestAMICallback create]; + ICEContext* ctx = [NSDictionary dictionary]; + void (^exCB)(ICEException*) = ^(ICEException* ex) { + test(NO); + }; + + void (^sentCB)(BOOL) = ^(BOOL ss) { [cb called]; }; + + [p begin_ice_isA:@"test" response:nil exception:exCB sent:sentCB]; + [cb check]; + [p begin_ice_isA:@"test" context:ctx response:nil exception:exCB sent:sentCB]; + [cb check]; + + [p begin_ice_ping:nil exception:exCB sent:sentCB]; + [cb check]; + [p begin_ice_ping:ctx response:nil exception:exCB sent:sentCB]; + [cb check]; + + [p begin_ice_id:nil exception:exCB sent:sentCB]; + [cb check]; + [p begin_ice_id:ctx response:nil exception:exCB sent:sentCB]; + [cb check]; + + [p begin_ice_ids:nil exception:exCB sent:sentCB]; + [cb check]; + [p begin_ice_ids:ctx response:nil exception:exCB sent:sentCB]; + [cb check]; + + [p begin_op:nil exception:exCB sent:sentCB]; + [cb check]; + [p begin_op:ctx response:nil exception:exCB sent:sentCB]; + [cb check]; + + ICEByte d[1024]; + ICEMutableByteSeq* seq = [ICEMutableByteSeq dataWithBytes:d length:sizeof(d)]; + [testController holdAdapter]; + NSMutableArray* cbs = [NSMutableArray array]; + + @autoreleasepool + { + @try + { + TestAMICallback* cb = [TestAMICallback create]; + while(true) + { + if(![[p begin_opWithPayload:seq response:nil exception:exCB sent: + ^(BOOL ss) { + [cb called]; + }] sentSynchronously]) + { + [cbs addObject:cb]; + break; + } + [cbs addObject:cb]; + cb = [TestAMICallback create]; + } + } + @catch(NSException* ex) + { + [testController resumeAdapter]; + @throw ex; + } + [testController resumeAdapter]; + for(TestAMICallback* cb in cbs) + { + [cb check]; + } + } + } + tprintf("ok\n"); + + tprintf("testing illegal arguments... "); + { + id<ICEAsyncResult> result; + + result = [p begin_op]; + [p end_op:result]; + @try + { + [p end_op:result]; + test(NO); + } + @catch(NSException* ex) + { + test([ex name] == NSInvalidArgumentException); + } + + result = [p begin_op]; + @try + { + [p end_opWithResult:result]; + test(NO); + } + @catch(NSException* ex) + { + test([ex name] == NSInvalidArgumentException); + } + + @try + { + [p end_op:nil]; + test(NO); + } + @catch(NSException* ex) + { + test([ex name] == NSInvalidArgumentException); + } + } + tprintf("ok\n"); + + tprintf("testing unexpected exceptions from callback... "); + { + id<TestAMITestIntfPrx> q = [TestAMITestIntfPrx uncheckedCast:[p ice_adapterId:@"dummy"]]; + TestAMICallback* cb = [TestAMICallback create]; + void (^thrower)() = ^(int i) + { + [cb called]; + switch(i) + { + case 0: + { + @throw [ICEObjectNotExistException objectNotExistException:__FILE__ line:__LINE__]; + } + case 1: + { + @throw [TestAMITestIntfException testIntfException]; + } + case 2: + { + @throw [NSException exceptionWithName:@"" reason:nil userInfo:nil]; + } + } + }; + + void (^exCB)(ICEException*) = ^(ICEException* ex) + { + test(NO); + }; + + int i; + for(i = 0; i < 3; ++i) + { + void (^throwResponse)() = ^{ thrower(i); }; + void (^throwEx)(ICEException*) = ^(ICEException* ex){ thrower(i); }; + void (^throwSent)(BOOL) = ^(BOOL b){ thrower(i); }; + + [p begin_ice_ping:throwResponse exception:exCB]; + [cb check]; + + [q begin_ice_ping:nil exception:throwEx]; + [cb check]; + + [p begin_ice_ping:nil exception:exCB sent:throwSent]; + [cb check]; + + [p begin_op:throwResponse exception:exCB]; + [cb check]; + + [q begin_op:nil exception:throwEx]; + [cb check]; + + [p begin_op:nil exception:exCB sent:throwSent]; + [cb check]; + } + } + tprintf("ok\n"); + + tprintf("testing batch requests with proxy... "); + { + { + test([p opBatchCount] == 0); + id<TestAMITestIntfPrx> b1 = [p ice_batchOneway]; + [b1 opBatch]; + [b1 opBatch]; + TestAMICallback* cb = [TestAMICallback create]; + id<ICEAsyncResult> r = [b1 begin_ice_flushBatchRequests:^(ICEException* ex) { test(NO); } + sent:^(BOOL sentSynchronously) { [cb called]; }]; + [cb check]; + test([r isSent]); + test([r isCompleted]); + test([p waitForBatch:2]); + } + + if([p ice_getConnection]) + { + test([p opBatchCount] == 0); + id<TestAMITestIntfPrx> b1 = [p ice_batchOneway]; + [b1 opBatch]; + [[b1 ice_getConnection] close:false]; + id<ICEAsyncResult> r = [b1 begin_ice_flushBatchRequests]; + [b1 end_ice_flushBatchRequests:r]; + test([r isSent]); + test([r isCompleted]); + test([p waitForBatch:1]); + } + } + tprintf("ok\n"); + + if([p ice_getConnection]) + { + tprintf("testing batch requests with connection... "); + { + { + test([p opBatchCount] == 0); + id<TestAMITestIntfPrx> b1 = [[TestAMITestIntfPrx + uncheckedCast:[[p ice_getConnection] + createProxy:[p ice_getIdentity]]] ice_batchOneway]; + [b1 opBatch]; + [b1 opBatch]; + TestAMICallback* cb = [TestAMICallback create]; + id<ICEAsyncResult> r = [[b1 ice_getConnection] begin_flushBatchRequests:^(ICEException* ex) + { + test(NO); + } + sent:^(BOOL sentSynchronously) { [cb called]; }]; + [cb check]; + test([r isSent]); + test([r isCompleted]); + test([p waitForBatch:2]); + } + + if([p ice_getConnection]) + { + test([p opBatchCount] == 0); + id<TestAMITestIntfPrx> b1 = [[TestAMITestIntfPrx + uncheckedCast:[[p ice_getConnection] + createProxy:[p ice_getIdentity]]] ice_batchOneway]; + [b1 opBatch]; + [[b1 ice_getConnection] close:false]; + TestAMICallback* cb = [TestAMICallback create]; + id<ICEAsyncResult> r = [[b1 ice_getConnection] begin_flushBatchRequests: + ^(ICEException* ex) { [cb called]; } + sent:^(BOOL sentSynchronously) { test(NO); }]; + [cb check]; + test(![r isSent]); + test([r isCompleted]); + test([p opBatchCount] == 0); + } + } + tprintf("ok\n"); + + + tprintf("testing batch requests with communicator... "); + { + { + test([p opBatchCount] == 0); + id<TestAMITestIntfPrx> b1 = [[TestAMITestIntfPrx + uncheckedCast:[[p ice_getConnection] + createProxy:[p ice_getIdentity]]] ice_batchOneway]; + [b1 opBatch]; + [b1 opBatch]; + TestAMICallback* cb = [TestAMICallback create]; + id<ICEAsyncResult> r = [communicator begin_flushBatchRequests:^(ICEException* ex) { test(NO); } + sent:^(BOOL sentSynchronously) { [cb called]; }]; + [cb check]; + test([r isSent]); + test([r isCompleted]); + test([p waitForBatch:2]); + } + + if([p ice_getConnection]) + { + test([p opBatchCount] == 0); + id<TestAMITestIntfPrx> b1 = [[TestAMITestIntfPrx + uncheckedCast:[[p ice_getConnection] + createProxy:[p ice_getIdentity]]] ice_batchOneway]; + [b1 opBatch]; + [[b1 ice_getConnection] close:false]; + TestAMICallback* cb = [TestAMICallback create]; + id<ICEAsyncResult> r = [communicator begin_flushBatchRequests:^(ICEException* ex) { test(NO); } + sent:^(BOOL sentSynchronously) { [cb called]; }]; + [cb check]; + test([r isSent]); + test([r isCompleted]); + test([p opBatchCount] == 0); + } + } + tprintf("ok\n"); + } + + tprintf("testing AsyncResult operations... "); + { + { + id<TestAMITestIntfPrx> indirect = [TestAMITestIntfPrx uncheckedCast:[p ice_adapterId:@"dummy"]]; + id<ICEAsyncResult> r = [indirect begin_op]; + @try + { + [r waitForCompleted]; + [r throwLocalException]; + } + @catch(ICENoEndpointException* ex) + { + } + + [testController holdAdapter]; + id<ICEAsyncResult> r1; + id<ICEAsyncResult> r2; + @try + { + r1 = [p begin_op]; + ICEByte d[1024]; + ICEMutableByteSeq* seq = [ICEMutableByteSeq dataWithBytes:d length:sizeof(d)]; + while([(r2 = [p begin_opWithPayload:seq]) sentSynchronously]); + + test(r1 == r1); + test(r1 != r2); + + + if([p ice_getConnection]) + { + test(([r1 sentSynchronously] && [r1 isSent] && ![r1 isCompleted]) || + (![r1 sentSynchronously] && ![r1 isCompleted])); + + test(![r2 sentSynchronously] && ![r2 isCompleted]); + } + } + @catch(NSException* ex) + { + [testController resumeAdapter]; + @throw ex; + } + [testController resumeAdapter]; + + [r1 waitForSent]; + test([r1 isSent]); + + [r2 waitForSent]; + test([r2 isSent]); + + [r1 waitForCompleted]; + test([r1 isCompleted]); + + [r2 waitForCompleted]; + test([r2 isCompleted]); + + test([[r1 getOperation] isEqualToString:@"op"]); + test([[r2 getOperation] isEqualToString:@"opWithPayload"]); + } + + { + id<ICEAsyncResult> r; + + // + // Twoway + // + r = [p begin_ice_ping]; + test([[r getOperation] isEqualToString:@"ice_ping"]); + test([r getConnection] == nil); // Expected + test([r getCommunicator] == communicator); + test([[r getProxy] isEqual:p]); + [p end_ice_ping:r]; + + id<TestAMITestIntfPrx> p2; + + // + // Oneway + // + p2 = [p ice_oneway]; + r = [p2 begin_ice_ping]; + test([[r getOperation] isEqualToString:@"ice_ping"]); + test(![r getConnection]); // Expected + test([r getCommunicator] == communicator); + test([[r getProxy] isEqual:p2]); + + // + // Batch request via proxy + // + p2 = [p ice_batchOneway]; + [p2 ice_ping]; + r = [p2 begin_ice_flushBatchRequests]; + test([r getConnection] == nil); // Expected + test([r getCommunicator] == communicator); + test([[r getProxy] isEqual:p2]); + [p2 end_ice_flushBatchRequests:r]; + + if([p ice_getConnection]) + { + // + // Batch request via connection + // + id<ICEConnection> con = [p ice_getConnection]; + p2 = [p ice_batchOneway]; + [p2 ice_ping]; + r = [con begin_flushBatchRequests]; + test([[r getConnection] isEqual:con]); + test([r getCommunicator] == communicator); + test([r getProxy] == nil); // Expected + [con end_flushBatchRequests:r]; + + // + // Batch request via communicator + // + p2 = [p ice_batchOneway]; + [p2 ice_ping]; + r = [communicator begin_flushBatchRequests]; + test([r getConnection] == nil); // Expected + test([r getCommunicator] == communicator); + test([r getProxy] == nil); // Expected + [communicator end_flushBatchRequests:r]; + } + } + } + + if([p ice_getConnection]) + { + [testController holdAdapter]; + + id<ICEAsyncResult> r; + ICEByte buf[10024]; + ICEByteSeq* seq = [ICEByteSeq dataWithBytes:buf length:sizeof(buf)]; + for(int i = 0; i < 200; ++i) // 2MB + { + r = [p begin_opWithPayload:seq]; + } + test(![r isSent]); + + id<ICEAsyncResult> r1 = [p begin_ice_ping]; + id<ICEAsyncResult> r2 = [p begin_ice_id]; + [r1 cancel]; + [r2 cancel]; + @try + { + [p end_ice_ping:r1]; + test(NO); + } + @catch(ICEInvocationCanceledException*) + { + } + @try + { + [p end_ice_id:r2]; + test(NO); + } + @catch(ICEInvocationCanceledException*) + { + } + + [testController resumeAdapter]; + [p ice_ping]; + test(![r1 isSent] && [r1 isCompleted]); + test(![r2 isSent] && [r2 isCompleted]); + + [testController holdAdapter]; + r1 = [p begin_op]; + r2 = [p begin_ice_id]; + [r1 waitForSent]; + [r2 waitForSent]; + [r1 cancel]; + [r2 cancel]; + @try + { + [p end_op:r1]; + test(NO); + } + @catch(ICEInvocationCanceledException*) + { + } + @try + { + [p end_ice_id:r2]; + test(NO); + } + @catch(ICEInvocationCanceledException*) + { + } + [testController resumeAdapter]; + } + + tprintf("ok\n"); + + [p shutdown]; +} diff --git a/objective-c/test/Ice/ami/Client.m b/objective-c/test/Ice/ami/Client.m new file mode 100644 index 00000000000..ef45b481b37 --- /dev/null +++ b/objective-c/test/Ice/ami/Client.m @@ -0,0 +1,87 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <TestCommon.h> +#import <AMITest.h> + +static int +run(id<ICECommunicator> communicator) +{ + void amiAllTests(id<ICECommunicator>, BOOL); + amiAllTests(communicator, false); + return EXIT_SUCCESS; +} + +#if TARGET_OS_IPHONE +# define main amiClient +#endif + +int +main(int argc, char* argv[]) +{ + int status; + @autoreleasepool + { + id<ICECommunicator> communicator = nil; + + @try + { + + ICEInitializationData* initData = [ICEInitializationData initializationData]; + initData.properties = defaultClientProperties(&argc, argv); + // + // In this test, we need at least two threads in the + // client side thread pool for nested AMI. + // + [initData.properties setProperty:@"Ice.ThreadPool.Client.Size" value:@"2"]; + [initData.properties setProperty:@"Ice.ThreadPool.Client.SizeWarn" value:@"0"]; + [initData.properties setProperty:@"Ice.Warn.AMICallback" value:@"0"]; + + // + // We must set MessageSizeMax to an explicit values, because + // we run tests to check whether Ice.MemoryLimitException is + // raised as expected. + // + [initData.properties setProperty:@"Ice.MessageSizeMax" value:@"100"]; + +#if TARGET_OS_IPHONE + initData.prefixTable__ = [NSDictionary dictionaryWithObjectsAndKeys: + @"TestAMI", @"::Test", + nil]; +#endif + + communicator = [ICEUtil createCommunicator:&argc argv:argv initData:initData]; + status = run(communicator); + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + @catch(TestFailedException* ex) + { + status = EXIT_FAILURE; + } + + if(communicator) + { + @try + { + [communicator destroy]; + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + } + } + return status; +} diff --git a/objective-c/test/Ice/ami/Collocated.m b/objective-c/test/Ice/ami/Collocated.m new file mode 100644 index 00000000000..d28473cfce9 --- /dev/null +++ b/objective-c/test/Ice/ami/Collocated.m @@ -0,0 +1,84 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <ami/TestI.h> +#import <TestCommon.h> + +static int +run(id<ICECommunicator> communicator) +{ + [[communicator getProperties] setProperty:@"TestAMIAdapter.Endpoints" value:@"default -p 12010:udp"]; + [[communicator getProperties] setProperty:@"ControllerAdapter.Endpoints" value:@"tcp -p 12011"]; + [[communicator getProperties] setProperty:@"ControllerAdapter.ThreadPool.Size" value:@"1"]; + + id<ICEObjectAdapter> adapter = [communicator createObjectAdapter:@"TestAMIAdapter"]; + id<ICEObjectAdapter> adapter2 = [communicator createObjectAdapter:@"ControllerAdapter"]; + + TestAMITestIntfControllerI* testController + = ICE_AUTORELEASE([[TestAMITestIntfControllerI alloc] initWithAdapter:adapter]); + + [adapter add:[TestAMITestIntfI testIntf] identity:[communicator stringToIdentity:@"test"]]; + //[adapter activate]; // Collocated test doesn't need to activate the OA + + [adapter2 add:testController identity:[communicator stringToIdentity:@"testController"]]; + //[adapter2 activate]; // Collocated test doesn't need to activate the OA + + void amiAllTests(id<ICECommunicator>, BOOL); + amiAllTests(communicator, true); + + return EXIT_SUCCESS; +} + +#if TARGET_OS_IPHONE +# define main amiServer +#endif + +int +main(int argc, char* argv[]) +{ + int status; + @autoreleasepool + { + id<ICECommunicator> communicator = nil; + + @try + { + ICEInitializationData* initData = [ICEInitializationData initializationData]; + initData.properties = defaultServerProperties(&argc, argv); + [initData.properties setProperty:@"Ice.Warn.AMICallback" value:@"0"]; +#if TARGET_OS_IPHONE + initData.prefixTable__ = [NSDictionary dictionaryWithObjectsAndKeys: + @"TestAMI", @"::Test", + nil]; +#endif + communicator = [ICEUtil createCommunicator:&argc argv:argv initData:initData]; + status = run(communicator); + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + + if(communicator) + { + @try + { + [communicator destroy]; + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + } + } + return status; +} diff --git a/objective-c/test/Ice/ami/Makefile b/objective-c/test/Ice/ami/Makefile new file mode 100644 index 00000000000..0667e0e7055 --- /dev/null +++ b/objective-c/test/Ice/ami/Makefile @@ -0,0 +1,46 @@ +# ********************************************************************** +# +# Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +# +# This copy of Ice is licensed to you under the terms described in the +# ICE_LICENSE file included in this distribution. +# +# ********************************************************************** + +top_srcdir = ../../.. + +CLIENT = client +SERVER = server +COLLOCATED = collocated + +TARGETS = $(CLIENT) $(SERVER) $(COLLOCATED) + +SLICE_OBJS = AMITest.o + +COBJS = Client.o \ + AllTests.o + +SOBJS = TestI.o \ + Server.o + +COLOBJS = Collocated.o \ + TestI.o \ + AllTests.o + +OBJS = $(COBJS) $(SOBJS) $(COLOBJS) $(SLICE_OBJS) + +include $(top_srcdir)/config/Make.rules + +CPPFLAGS := -I. -I.. -I../../include $(CPPFLAGS) + +$(CLIENT): $(COBJS) $(SLICE_OBJS) + rm -f $@ + $(CXX) $(LDFLAGS) $(LDEXEFLAGS) -o $@ $(COBJS) $(SLICE_OBJS) $(TEST_LIBS) + +$(SERVER): $(SOBJS) $(SLICE_OBJS) + rm -f $@ + $(CXX) $(LDFLAGS) $(LDEXEFLAGS) -o $@ $(SOBJS) $(SLICE_OBJS) $(TEST_LIBS) + +$(COLLOCATED): $(COLOBJS) $(SLICE_OBJS) + rm -f $@ + $(CXX) $(LDFLAGS) $(LDEXEFLAGS) -o $@ $(COLOBJS) $(SLICE_OBJS) $(TEST_LIBS) diff --git a/objective-c/test/Ice/ami/Server.m b/objective-c/test/Ice/ami/Server.m new file mode 100644 index 00000000000..d663915732d --- /dev/null +++ b/objective-c/test/Ice/ami/Server.m @@ -0,0 +1,90 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <ami/TestI.h> +#import <TestCommon.h> + +static int +run(id<ICECommunicator> communicator) +{ + [[communicator getProperties] setProperty:@"TestAMIAdapter.Endpoints" value:@"default -p 12010:udp"]; + [[communicator getProperties] setProperty:@"ControllerAdapter.Endpoints" value:@"tcp -p 12011"]; + [[communicator getProperties] setProperty:@"ControllerAdapter.ThreadPool.Size" value:@"1"]; + + id<ICEObjectAdapter> adapter = [communicator createObjectAdapter:@"TestAMIAdapter"]; + id<ICEObjectAdapter> adapter2 = [communicator createObjectAdapter:@"ControllerAdapter"]; + + TestAMITestIntfControllerI* testController + = ICE_AUTORELEASE([[TestAMITestIntfControllerI alloc] initWithAdapter:adapter]); + + [adapter add:[TestAMITestIntfI testIntf] identity:[communicator stringToIdentity:@"test"]]; + [adapter activate]; + + [adapter2 add:testController identity:[communicator stringToIdentity:@"testController"]]; + [adapter2 activate]; + + serverReady(communicator); + + [communicator waitForShutdown]; + return EXIT_SUCCESS; +} + +#if TARGET_OS_IPHONE +# define main amiServer +#endif + +int +main(int argc, char* argv[]) +{ + int status; + @autoreleasepool + { + id<ICECommunicator> communicator = nil; + + @try + { + ICEInitializationData* initData = [ICEInitializationData initializationData]; + initData.properties = defaultServerProperties(&argc, argv); + + // + // Its possible to have batch oneway requests dispatched after + // the adapter is deactivated due to thread scheduling so we + // supress this warning. + // + [initData.properties setProperty:@"Ice.Warn.Dispatch" value:@"0"]; +#if TARGET_OS_IPHONE + initData.prefixTable__ = [NSDictionary dictionaryWithObjectsAndKeys: + @"TestAMI", @"::Test", + nil]; +#endif + communicator = [ICEUtil createCommunicator:&argc argv:argv initData:initData]; + status = run(communicator); + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + + if(communicator) + { + @try + { + [communicator destroy]; + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + } + } + return status; +} diff --git a/objective-c/test/Ice/ami/TestI.h b/objective-c/test/Ice/ami/TestI.h new file mode 100644 index 00000000000..88d8f6026a7 --- /dev/null +++ b/objective-c/test/Ice/ami/TestI.h @@ -0,0 +1,29 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <AMITest.h> +#import <Foundation/Foundation.h> + +// +// Servant implementation +// +@interface TestAMITestIntfI : TestAMITestIntf<TestAMITestIntf> +{ + int _batchCount; + NSCondition* _cond; +} +@end + +@interface TestAMITestIntfControllerI : TestAMITestIntfController<TestAMITestIntfController> +{ + id<ICEObjectAdapter> _adapter; +} +-(id) initWithAdapter:(id<ICEObjectAdapter>)adapter; +@end + diff --git a/objective-c/test/Ice/ami/TestI.m b/objective-c/test/Ice/ami/TestI.m new file mode 100644 index 00000000000..1c4c493540a --- /dev/null +++ b/objective-c/test/Ice/ami/TestI.m @@ -0,0 +1,114 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> + +#import <ami/TestI.h> +#import <TestCommon.h> + +@implementation TestAMITestIntfI +-(id) init +{ + self = [super init]; + if(!self) + { + return nil; + } + _cond = [[NSCondition alloc] init]; + return self; +} + +#if defined(__clang__) && !__has_feature(objc_arc) +-(void) dealloc +{ + [_cond release]; + [super dealloc]; +} +#endif + +-(void) op:(ICECurrent*)current +{ +} +-(void) opWithPayload:(ICEMutableByteSeq*)data current:(ICECurrent*)current +{ +} +-(int) opWithResult:(ICECurrent*)current +{ + return 15; +} +-(void) opWithUE:(ICECurrent*)current +{ + @throw [TestAMITestIntfException testIntfException]; +} + +-(void) shutdown:(ICECurrent*)current +{ + [[current.adapter getCommunicator] shutdown]; +} +-(void) opBatch:(ICECurrent *)current +{ + [_cond lock]; + ++_batchCount; + [_cond signal]; + [_cond unlock]; +} +-(ICEInt) opBatchCount:(ICECurrent *)current +{ + [_cond lock]; + @try + { + return _batchCount; + } + @finally + { + [_cond unlock]; + } + return 0; +} +-(BOOL) waitForBatch:(ICEInt)count current:(ICECurrent *)current +{ + [_cond lock]; + @try + { + while(_batchCount < count) + { + [_cond waitUntilDate:[NSDate dateWithTimeIntervalSinceNow:500]]; + } + BOOL result = count == _batchCount; + _batchCount = 0; + return result; + } + @finally + { + [_cond unlock]; + } + return NO; +} +@end + +@implementation TestAMITestIntfControllerI +-(id) initWithAdapter:(id<ICEObjectAdapter>)adapter +{ + self = [super init]; + if(!self) + { + return nil; + } + _adapter = adapter; + return self; +} +-(void) holdAdapter:(ICECurrent*)current +{ + [_adapter hold]; +} +-(void) resumeAdapter:(ICECurrent*)current +{ + [_adapter activate]; +} +@end diff --git a/objective-c/test/Ice/ami/run.py b/objective-c/test/Ice/ami/run.py new file mode 100755 index 00000000000..0816938a196 --- /dev/null +++ b/objective-c/test/Ice/ami/run.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python +# ********************************************************************** +# +# Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +# +# This copy of Ice is licensed to you under the terms described in the +# ICE_LICENSE file included in this distribution. +# +# ********************************************************************** + +import os, sys + +path = [ ".", "..", "../..", "../../..", "../../../..", "../../../../.." ] +head = os.path.dirname(sys.argv[0]) +if len(head) > 0: + path = [os.path.join(head, p) for p in path] +path = [os.path.abspath(p) for p in path if os.path.exists(os.path.join(p, "scripts", "TestUtil.py")) ] +if len(path) == 0: + raise RuntimeError("can't find toplevel directory!") +sys.path.append(os.path.join(path[0], "scripts")) +import TestUtil + +print("tests with regular server.") +TestUtil.clientServerTest() +print("tests with collocated server.") +TestUtil.collocatedTest() diff --git a/objective-c/test/Ice/binding/.gitignore b/objective-c/test/Ice/binding/.gitignore new file mode 100644 index 00000000000..111134fb8e1 --- /dev/null +++ b/objective-c/test/Ice/binding/.gitignore @@ -0,0 +1,8 @@ +// Generated by makegitignore.py + +// IMPORTANT: Do not edit this file -- any edits made here will be lost! +client +server +.depend +BindingTest.m +BindingTest.h diff --git a/objective-c/test/Ice/binding/AllTests.m b/objective-c/test/Ice/binding/AllTests.m new file mode 100644 index 00000000000..ea148bbf5e3 --- /dev/null +++ b/objective-c/test/Ice/binding/AllTests.m @@ -0,0 +1,864 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <TestCommon.h> +#import <BindingTest.h> + +#import <Foundation/Foundation.h> + +@interface GetAdapterNameCB : NSObject +{ + NSCondition* cond_; + NSString* name_; +} +-(id) init; +#if defined(__clang__) && !__has_feature(objc_arc) +-(void) dealloc; +#endif +-(void) response:(NSString*)name; +-(void) exception:(ICEException*)ex; +-(NSString*) getResult; +@end + +@implementation GetAdapterNameCB +-(id) init +{ + self = [super init]; + if(!self) + { + return nil; + } + cond_ = [[NSCondition alloc] init]; + name_ = nil; + return self; +} + +#if defined(__clang__) && !__has_feature(objc_arc) +-(void) dealloc +{ + [cond_ release]; + [name_ release]; + [super dealloc]; +} +#endif + +-(void) response:(NSString*)name +{ + [cond_ lock]; + name_ = ICE_RETAIN(name); + [cond_ signal]; + [cond_ unlock]; +} +-(void) exception:(ICEException*)ex +{ + tprintf("unexpected exception: %@", ex); + test(NO); +} +-(NSString*) getResult +{ + [cond_ lock]; + @try + { + while(name_ == nil) + { + [cond_ wait]; + } + return ICE_AUTORELEASE(ICE_RETAIN(name_)); + } + @finally + { + [cond_ unlock]; + } + return nil; +} +@end + +NSString* +getAdapterNameWithAMI(id<TestBindingTestIntfPrx> test) +{ + GetAdapterNameCB* cb = ICE_AUTORELEASE([[GetAdapterNameCB alloc] init]); + [test begin_getAdapterName:^(NSMutableString* name) { [cb response:name]; } + exception:^(ICEException* ex) { [cb exception:ex]; }]; + return [cb getResult]; +} + +NSArray* +getEndpoints(id<TestBindingTestIntfPrx> proxy) +{ + NSMutableArray* edpts = [NSMutableArray array]; + bool escape = NO; + int beg = 0; + int length = 0; + NSString* s = [proxy ice_toString]; + int index; + for(index = 0; index < [s length]; ++index) + { + unichar c = [s characterAtIndex:index]; + if(c == '"') + { + escape = !escape; + } + + if(!escape && c == ':') + { + NSRange range = { beg, length }; + [edpts addObject:[s substringWithRange:range]]; + beg = beg + length + 1; + length = 0; + } + else + { + ++length; + } + } + if(length > 0) + { + NSRange range = { beg, length }; + [edpts addObject:[s substringWithRange:range]]; + } + [edpts removeObjectAtIndex:0]; + return edpts; +} + +id<TestBindingTestIntfPrx> +createTestIntfPrx(NSArray* adapters) +{ + NSMutableArray* endpoints = [NSMutableArray arrayWithCapacity:[adapters count]]; + id<TestBindingTestIntfPrx> test = nil; + for(id<TestBindingRemoteObjectAdapterPrx> a in adapters) + { + test = [a getTestIntf]; + [endpoints addObjectsFromArray:getEndpoints(test)]; + } + NSString* proxy = [[test ice_getCommunicator] identityToString:[test ice_getIdentity]]; + for(NSString* e in endpoints) + { + proxy = [proxy stringByAppendingString:@":"]; + proxy = [proxy stringByAppendingString:e]; + } + return [TestBindingTestIntfPrx uncheckedCast:[[test ice_getCommunicator] stringToProxy:proxy]]; +} + +void +deactivate(id<TestBindingRemoteCommunicatorPrx> com, NSArray* adapters) +{ + for(id<TestBindingRemoteObjectAdapterPrx> a in adapters) + { + [com deactivateObjectAdapter:a]; + } +} + +void +random_shuffle(NSMutableArray* array) +{ + NSUInteger count = [array count]; + while(count--) + { + [array exchangeObjectAtIndex:count withObjectAtIndex:(random() % (count + 1))]; + } +} + +void +bindingAllTests(id<ICECommunicator> communicator) +{ + NSString* ref = @"communicator:default -p 12010"; + id<TestBindingRemoteCommunicatorPrx> com = [TestBindingRemoteCommunicatorPrx uncheckedCast:[ + communicator stringToProxy:ref]]; + + tprintf("testing binding with single endpoint... "); + { + id<TestBindingRemoteObjectAdapterPrx> adapter = [com createObjectAdapter:@"Adapter" endpoints:@"default"]; + + id<TestBindingTestIntfPrx> test1 = [adapter getTestIntf]; + id<TestBindingTestIntfPrx> test2 = [adapter getTestIntf]; + test([[test1 ice_getConnection] isEqual:[test2 ice_getConnection]]); + + [test1 ice_ping]; + [test2 ice_ping]; + + [com deactivateObjectAdapter:adapter]; + + id<TestBindingTestIntfPrx> test3 = [TestBindingTestIntfPrx uncheckedCast:test1]; + test([[test3 ice_getConnection] isEqual:[test1 ice_getConnection]]); + test([[test3 ice_getConnection] isEqual:[test2 ice_getConnection]]); + + @try + { + [test3 ice_ping]; + test(NO); + } + @catch(ICEConnectionRefusedException*) + { + } + } + tprintf("ok\n"); + + tprintf("testing binding with multiple endpoints... "); + { + NSMutableArray* adapters = [NSMutableArray arrayWithCapacity:3]; + [adapters addObject:[com createObjectAdapter:@"Adapter11" endpoints:@"default"]]; + [adapters addObject:[com createObjectAdapter:@"Adapter12" endpoints:@"default"]]; + [adapters addObject:[com createObjectAdapter:@"Adapter13" endpoints:@"default"]]; + + // + // Ensure that when a connection is opened it's reused for new + // proxies and that all endpoints are eventually tried. + // + NSMutableSet* names = [NSMutableSet setWithCapacity:3]; + [names addObject:@"Adapter11"]; + [names addObject:@"Adapter12"]; + [names addObject:@"Adapter13"]; + while([names count] != 0) + { + NSMutableArray* adpts = ICE_AUTORELEASE([adapters mutableCopy]); + + id<TestBindingTestIntfPrx> test1 = createTestIntfPrx(adpts); + random_shuffle(adpts); + id<TestBindingTestIntfPrx> test2 = createTestIntfPrx(adpts); + random_shuffle(adpts); + id<TestBindingTestIntfPrx> test3 = createTestIntfPrx(adpts); + + test([[test1 ice_getConnection] isEqual:[test2 ice_getConnection]]); + test([[test2 ice_getConnection] isEqual:[test3 ice_getConnection]]); + + [names removeObject:[test1 getAdapterName]]; + [[test1 ice_getConnection] close:NO]; + } + + // + // Ensure that the proxy correctly caches the connection (we + // always send the request over the same connection.) + // + { + for(id<TestBindingRemoteObjectAdapterPrx> a in adapters) + { + [[a getTestIntf] ice_ping]; + } + + id<TestBindingTestIntfPrx> test = createTestIntfPrx(adapters); + NSString* name = [test getAdapterName]; + const int nRetry = 10; + int i; + for(i = 0; i < nRetry && [[test getAdapterName] isEqualToString:name]; i++); + test(i == nRetry); + + for(id<TestBindingRemoteObjectAdapterPrx> a in adapters) + { + [[[a getTestIntf] ice_getConnection] close:NO]; + } + } + + // + // Deactivate an adapter and ensure that we can still + // establish the connection to the remaining adapters. + // + [com deactivateObjectAdapter:[adapters objectAtIndex:0]]; + [names addObject:@"Adapter12"]; + [names addObject:@"Adapter13"]; + while([names count] != 0) + { + NSMutableArray* adpts = ICE_AUTORELEASE([adapters mutableCopy]); + + id<TestBindingTestIntfPrx> test1 = createTestIntfPrx(adpts); + random_shuffle(adpts); + id<TestBindingTestIntfPrx> test2 = createTestIntfPrx(adpts); + random_shuffle(adpts); + id<TestBindingTestIntfPrx> test3 = createTestIntfPrx(adpts); + + test([[test1 ice_getConnection] isEqual:[test2 ice_getConnection]]); + test([[test2 ice_getConnection] isEqual:[test3 ice_getConnection]]); + + [names removeObject:[test1 getAdapterName]]; + [[test1 ice_getConnection] close:NO]; + } + + // + // Deactivate an adapter and ensure that we can still + // establish the connection to the remaining adapter. + // + [com deactivateObjectAdapter:[adapters objectAtIndex:2]]; + id<TestBindingTestIntfPrx> test = createTestIntfPrx(adapters); + test([[test getAdapterName] isEqualToString:@"Adapter12"]); + + deactivate(com, adapters); + } + tprintf("ok\n"); + + tprintf("testing binding with multiple endpoints and AMI... "); + { + NSMutableArray* adapters = [NSMutableArray arrayWithCapacity:3]; + [adapters addObject:[com createObjectAdapter:@"AdapterAMI11" endpoints:@"default"]]; + [adapters addObject:[com createObjectAdapter:@"AdapterAMI12" endpoints:@"default"]]; + [adapters addObject:[com createObjectAdapter:@"AdapterAMI13" endpoints:@"default"]]; + + // + // Ensure that when a connection is opened it's reused for new + // proxies and that all endpoints are eventually tried. + // + NSMutableSet* names = [NSMutableSet setWithCapacity:3]; + [names addObject:@"AdapterAMI11"]; + [names addObject:@"AdapterAMI12"]; + [names addObject:@"AdapterAMI13"]; + while([names count] != 0) + { + NSMutableArray* adpts = ICE_AUTORELEASE([adapters mutableCopy]); + + id<TestBindingTestIntfPrx> test1 = createTestIntfPrx(adpts); + random_shuffle(adpts); + id<TestBindingTestIntfPrx> test2 = createTestIntfPrx(adpts); + random_shuffle(adpts); + id<TestBindingTestIntfPrx> test3 = createTestIntfPrx(adpts); + + test([[test1 ice_getConnection] isEqual:[test2 ice_getConnection]]); + test([[test2 ice_getConnection] isEqual:[test3 ice_getConnection]]); + + [names removeObject:getAdapterNameWithAMI(test1)]; + [[test1 ice_getConnection] close:NO]; + } + + // + // Ensure that the proxy correctly caches the connection (we + // always send the request over the same connection.) + // + { + for(id<TestBindingRemoteObjectAdapterPrx> a in adapters) + { + [[a getTestIntf] ice_ping]; + } + + id<TestBindingTestIntfPrx> test = createTestIntfPrx(adapters); + NSString* name = getAdapterNameWithAMI(test); + const int nRetry = 10; + int i; + for(i = 0; i < nRetry && [getAdapterNameWithAMI(test) isEqualToString:name]; i++); + test(i == nRetry); + + for(id<TestBindingRemoteObjectAdapterPrx> a in adapters) + { + [[[a getTestIntf] ice_getConnection] close:NO]; + } + } + + // + // Deactivate an adapter and ensure that we can still + // establish the connection to the remaining adapters. + // + [com deactivateObjectAdapter:[adapters objectAtIndex:0]]; + [names addObject:@"AdapterAMI12"]; + [names addObject:@"AdapterAMI13"]; + while([names count] != 0) + { + NSMutableArray* adpts = ICE_AUTORELEASE([adapters mutableCopy]); + + id<TestBindingTestIntfPrx> test1 = createTestIntfPrx(adpts); + random_shuffle(adpts); + id<TestBindingTestIntfPrx> test2 = createTestIntfPrx(adpts); + random_shuffle(adpts); + id<TestBindingTestIntfPrx> test3 = createTestIntfPrx(adpts); + + test([[test1 ice_getConnection] isEqual:[test2 ice_getConnection]]); + test([[test2 ice_getConnection] isEqual:[test3 ice_getConnection]]); + + [names removeObject:[test1 getAdapterName]]; + [[test1 ice_getConnection] close:NO]; + } + + // + // Deactivate an adapter and ensure that we can still + // establish the connection to the remaining adapter. + // + [com deactivateObjectAdapter:[adapters objectAtIndex:2]]; + id<TestBindingTestIntfPrx> test = createTestIntfPrx(adapters); + test([[test getAdapterName] isEqualToString:@"AdapterAMI12"]); + + deactivate(com, adapters); + } + tprintf("ok\n"); + + tprintf("testing random endpoint selection... "); + { + NSMutableArray* adapters = [NSMutableArray arrayWithCapacity:3]; + [adapters addObject:[com createObjectAdapter:@"Adapter21" endpoints:@"default"]]; + [adapters addObject:[com createObjectAdapter:@"Adapter22" endpoints:@"default"]]; + [adapters addObject:[com createObjectAdapter:@"Adapter23" endpoints:@"default"]]; + + id<TestBindingTestIntfPrx> test = createTestIntfPrx(adapters); + test([test ice_getEndpointSelection] == ICERandom); + + NSMutableSet* names = [NSMutableSet setWithCapacity:3]; + [names addObject:@"Adapter21"]; + [names addObject:@"Adapter22"]; + [names addObject:@"Adapter23"]; + while([names count] != 0) + { + [names removeObject:[test getAdapterName]]; + [[test ice_getConnection] close:NO]; + } + + test = [TestBindingTestIntfPrx uncheckedCast:[test ice_endpointSelection:ICERandom]]; + test([test ice_getEndpointSelection] == ICERandom); + + [names addObject:@"Adapter21"]; + [names addObject:@"Adapter22"]; + [names addObject:@"Adapter23"]; + while([names count] != 0) + { + [names removeObject:[test getAdapterName]]; + [[test ice_getConnection] close:NO]; + } + + deactivate(com, adapters); + } + tprintf("ok\n"); + + tprintf("testing ordered endpoint selection... "); + { + NSMutableArray* adapters = [NSMutableArray arrayWithCapacity:3]; + [adapters addObject:[com createObjectAdapter:@"Adapter31" endpoints:@"default"]]; + [adapters addObject:[com createObjectAdapter:@"Adapter32" endpoints:@"default"]]; + [adapters addObject:[com createObjectAdapter:@"Adapter33" endpoints:@"default"]]; + + id<TestBindingTestIntfPrx> test = createTestIntfPrx(adapters); + test = [TestBindingTestIntfPrx uncheckedCast:[test ice_endpointSelection:ICEOrdered]]; + test([test ice_getEndpointSelection] == ICEOrdered); + const int nRetry = 5; + int i; + + // + // Ensure that endpoints are tried in order by deactiving the adapters + // one after the other. + // + for(i = 0; i < nRetry && [[test getAdapterName] isEqualToString:@"Adapter31"]; i++); +#if TARGET_OS_IPHONE > 0 + if(i != nRetry) + { + [[test ice_getConnection] close:NO]; + for(i = 0; i < nRetry && [[test getAdapterName] isEqualToString:@"Adapter31"]; i++); + } +#endif + test(i == nRetry); + [com deactivateObjectAdapter:[adapters objectAtIndex:0]]; + for(i = 0; i < nRetry && [[test getAdapterName] isEqualToString:@"Adapter32"]; i++); +#if TARGET_OS_IPHONE > 0 + if(i != nRetry) + { + [[test ice_getConnection] close:NO]; + for(i = 0; i < nRetry && [[test getAdapterName] isEqualToString:@"Adapter32"]; i++); + } +#endif + test(i == nRetry); + [com deactivateObjectAdapter:[adapters objectAtIndex:1]]; + for(i = 0; i < nRetry && [[test getAdapterName] isEqualToString:@"Adapter33"]; i++); +#if TARGET_OS_IPHONE > 0 + if(i != nRetry) + { + [[test ice_getConnection] close:NO]; + for(i = 0; i < nRetry && [[test getAdapterName] isEqualToString:@"Adapter33"]; i++); + } +#endif + test(i == nRetry); + [com deactivateObjectAdapter:[adapters objectAtIndex:2]]; + + @try + { + [test getAdapterName]; + } + @catch(ICEConnectionRefusedException*) + { + } + + NSArray* endpoints = getEndpoints(test); + + adapters = [NSMutableArray arrayWithCapacity:3]; + + // + // Now, re-activate the adapters with the same endpoints in the opposite + // order. + // + [adapters addObject:[com createObjectAdapter:@"Adapter36" endpoints:[endpoints objectAtIndex:2]]]; + for(i = 0; i < nRetry && [[test getAdapterName] isEqualToString:@"Adapter36"]; i++); +#if TARGET_OS_IPHONE > 0 + if(i != nRetry) + { + [[test ice_getConnection] close:NO]; + for(i = 0; i < nRetry && [[test getAdapterName] isEqualToString:@"Adapter36"]; i++); + } +#endif + test(i == nRetry); + [[test ice_getConnection] close:NO]; + [adapters addObject:[com createObjectAdapter:@"Adapter35" endpoints:[endpoints objectAtIndex:1]]]; + for(i = 0; i < nRetry && [[test getAdapterName] isEqualToString:@"Adapter35"]; i++); +#if TARGET_OS_IPHONE > 0 + if(i != nRetry) + { + [[test ice_getConnection] close:NO]; + for(i = 0; i < nRetry && [[test getAdapterName] isEqualToString:@"Adapter35"]; i++); + } +#endif + test(i == nRetry); + [[test ice_getConnection] close:NO]; + [adapters addObject:[com createObjectAdapter:@"Adapter34" endpoints:[endpoints objectAtIndex:0]]]; + for(i = 0; i < nRetry && [[test getAdapterName] isEqualToString:@"Adapter34"]; i++); +#if TARGET_OS_IPHONE > 0 + if(i != nRetry) + { + [[test ice_getConnection] close:NO]; + for(i = 0; i < nRetry && [[test getAdapterName] isEqualToString:@"Adapter34"]; i++); + } +#endif + test(i == nRetry); + deactivate(com, adapters); + } + tprintf("ok\n"); + + tprintf("testing per request binding with single endpoint... "); + { + id<TestBindingRemoteObjectAdapterPrx> adapter = [com createObjectAdapter:@"Adapter41" endpoints:@"default"]; + + id<TestBindingTestIntfPrx> test1 = [TestBindingTestIntfPrx uncheckedCast:[[adapter getTestIntf] ice_connectionCached:NO]]; + id<TestBindingTestIntfPrx> test2 = [TestBindingTestIntfPrx uncheckedCast:[[adapter getTestIntf] ice_connectionCached:NO]]; + test(![test1 ice_isConnectionCached]); + test(![test2 ice_isConnectionCached]); + test([[test1 ice_getConnection] isEqual:[test2 ice_getConnection]]); + + [test1 ice_ping]; + + [com deactivateObjectAdapter:adapter]; + + id<TestBindingTestIntfPrx> test3 = [TestBindingTestIntfPrx uncheckedCast:test1]; + @try + { + test([[test3 ice_getConnection] isEqual:[test1 ice_getConnection]]); + test(NO); + } + @catch(ICEConnectionRefusedException*) + { + } + } + tprintf("ok\n"); + + tprintf("testing per request binding with multiple endpoints... "); + { + NSMutableArray* adapters = [NSMutableArray arrayWithCapacity:3]; + [adapters addObject:[com createObjectAdapter:@"Adapter51" endpoints:@"default"]]; + [adapters addObject:[com createObjectAdapter:@"Adapter52" endpoints:@"default"]]; + [adapters addObject:[com createObjectAdapter:@"Adapter53" endpoints:@"default"]]; + + id<TestBindingTestIntfPrx> test = [createTestIntfPrx(adapters) ice_connectionCached:NO]; + test(![test ice_isConnectionCached]); + + NSMutableSet* names = [NSMutableSet setWithCapacity:3]; + [names addObject:@"Adapter51"]; + [names addObject:@"Adapter52"]; + [names addObject:@"Adapter53"]; + while([names count] != 0) + { + [names removeObject:[test getAdapterName]]; + } + + [com deactivateObjectAdapter:[adapters objectAtIndex:0]]; + + [names addObject:@"Adapter52"]; + [names addObject:@"Adapter53"]; + while([names count] != 0) + { + [names removeObject:[test getAdapterName]]; + } + + [com deactivateObjectAdapter:[adapters objectAtIndex:2]]; + + + test([[test getAdapterName] isEqualToString:@"Adapter52"]); + + deactivate(com, adapters); + } + tprintf("ok\n"); + + tprintf("testing per request binding with multiple endpoints and AMI... "); + { + NSMutableArray* adapters = [NSMutableArray arrayWithCapacity:3]; + [adapters addObject:[com createObjectAdapter:@"AdapterAMI51" endpoints:@"default"]]; + [adapters addObject:[com createObjectAdapter:@"AdapterAMI52" endpoints:@"default"]]; + [adapters addObject:[com createObjectAdapter:@"AdapterAMI53" endpoints:@"default"]]; + + id<TestBindingTestIntfPrx> test = [createTestIntfPrx(adapters) ice_connectionCached:NO]; + test(![test ice_isConnectionCached]); + + NSMutableSet* names = [NSMutableSet setWithCapacity:3]; + [names addObject:@"AdapterAMI51"]; + [names addObject:@"AdapterAMI52"]; + [names addObject:@"AdapterAMI53"]; + while([names count] != 0) + { + [names removeObject:getAdapterNameWithAMI(test)]; + } + + [com deactivateObjectAdapter:[adapters objectAtIndex:0]]; + + [names addObject:@"AdapterAMI52"]; + [names addObject:@"AdapterAMI53"]; + while([names count] != 0) + { + [names removeObject:getAdapterNameWithAMI(test)]; + } + + [com deactivateObjectAdapter:[adapters objectAtIndex:2]]; + + test([[test getAdapterName] isEqualToString:@"AdapterAMI52"]); + + deactivate(com, adapters); + } + tprintf("ok\n"); + + tprintf("testing per request binding and ordered endpoint selection... "); + { + NSMutableArray* adapters = [NSMutableArray arrayWithCapacity:3]; + [adapters addObject:[com createObjectAdapter:@"Adapter61" endpoints:@"default"]]; + [adapters addObject:[com createObjectAdapter:@"Adapter62" endpoints:@"default"]]; + [adapters addObject:[com createObjectAdapter:@"Adapter63" endpoints:@"default"]]; + + id<TestBindingTestIntfPrx> test = createTestIntfPrx(adapters); + test = [TestBindingTestIntfPrx uncheckedCast:[test ice_endpointSelection:ICEOrdered]]; + test([test ice_getEndpointSelection] == ICEOrdered); + test = [TestBindingTestIntfPrx uncheckedCast:[test ice_connectionCached:NO]]; + test(![test ice_isConnectionCached]); + const int nRetry = 5; + int i; + + // + // Ensure that endpoints are tried in order by deactiving the adapters + // one after the other. + // + for(i = 0; i < nRetry && [[test getAdapterName] isEqualToString:@"Adapter61"]; i++); +#if TARGET_OS_IPHONE > 0 + test(i >= nRetry - 1); // WORKAROUND: for connection establishment hang. +#else + test(i == nRetry); +#endif + [com deactivateObjectAdapter:[adapters objectAtIndex:0]]; + for(i = 0; i < nRetry && [[test getAdapterName] isEqualToString:@"Adapter62"]; i++); +#if TARGET_OS_IPHONE > 0 + test(i >= nRetry - 1); // WORKAROUND: for connection establishment hang. +#else + test(i == nRetry); +#endif + [com deactivateObjectAdapter:[adapters objectAtIndex:1]]; + for(i = 0; i < nRetry && [[test getAdapterName] isEqualToString:@"Adapter63"]; i++); +#if TARGET_OS_IPHONE > 0 + test(i >= nRetry - 1); // WORKAROUND: for connection establishment hang. +#else + test(i == nRetry); +#endif + [com deactivateObjectAdapter:[adapters objectAtIndex:2]]; + + @try + { + [test getAdapterName]; + } + @catch(ICEConnectionRefusedException*) + { + } + + NSArray* endpoints = getEndpoints(test); + + adapters = [NSMutableArray arrayWithCapacity:3]; + + // + // Now, re-activate the adapters with the same endpoints in the opposite + // order. + // + [adapters addObject:[com createObjectAdapter:@"Adapter66" endpoints:[endpoints objectAtIndex:2]]]; + for(i = 0; i < nRetry && [[test getAdapterName] isEqualToString:@"Adapter66"]; i++); +#if TARGET_OS_IPHONE > 0 + test(i >= nRetry - 1); // WORKAROUND: for connection establishment hang. +#else + test(i == nRetry); +#endif + [adapters addObject:[com createObjectAdapter:@"Adapter65" endpoints:[endpoints objectAtIndex:1]]]; + for(i = 0; i < nRetry && [[test getAdapterName] isEqualToString:@"Adapter65"]; i++); +#if TARGET_OS_IPHONE > 0 + test(i >= nRetry - 1); // WORKAROUND: for connection establishment hang. +#else + test(i == nRetry); +#endif + [adapters addObject:[com createObjectAdapter:@"Adapter64" endpoints:[endpoints objectAtIndex:0]]]; + for(i = 0; i < nRetry && [[test getAdapterName] isEqualToString:@"Adapter64"]; i++); +#if TARGET_OS_IPHONE > 0 + test(i >= nRetry - 1); // WORKAROUND: for connection establishment hang. +#else + test(i == nRetry); +#endif + + deactivate(com, adapters); + } + tprintf("ok\n"); + + tprintf("testing per request binding and ordered endpoint selection and AMI... "); + { + NSMutableArray* adapters = [NSMutableArray arrayWithCapacity:3]; + [adapters addObject:[com createObjectAdapter:@"AdapterAMI61" endpoints:@"default"]]; + [adapters addObject:[com createObjectAdapter:@"AdapterAMI62" endpoints:@"default"]]; + [adapters addObject:[com createObjectAdapter:@"AdapterAMI63" endpoints:@"default"]]; + + id<TestBindingTestIntfPrx> test = createTestIntfPrx(adapters); + test = [TestBindingTestIntfPrx uncheckedCast:[test ice_endpointSelection:ICEOrdered]]; + test([test ice_getEndpointSelection] == ICEOrdered); + test = [TestBindingTestIntfPrx uncheckedCast:[test ice_connectionCached:NO]]; + test(![test ice_isConnectionCached]); + const int nRetry = 5; + int i; + + // + // Ensure that endpoints are tried in order by deactiving the adapters + // one after the other. + // + for(i = 0; i < nRetry && [getAdapterNameWithAMI(test) isEqualToString:@"AdapterAMI61"]; i++); +#if TARGET_OS_IPHONE > 0 + test(i >= nRetry - 1); // WORKAROUND: for connection establishment hang. +#else + test(i == nRetry); +#endif + [com deactivateObjectAdapter:[adapters objectAtIndex:0]]; + for(i = 0; i < nRetry && [getAdapterNameWithAMI(test) isEqualToString:@"AdapterAMI62"]; i++); +#if TARGET_OS_IPHONE > 0 + test(i >= nRetry - 1); // WORKAROUND: for connection establishment hang. +#else + test(i == nRetry); +#endif + [com deactivateObjectAdapter:[adapters objectAtIndex:1]]; + for(i = 0; i < nRetry && [getAdapterNameWithAMI(test) isEqualToString:@"AdapterAMI63"]; i++); +#if TARGET_OS_IPHONE > 0 + test(i >= nRetry - 1); // WORKAROUND: for connection establishment hang. +#else + test(i == nRetry); +#endif + [com deactivateObjectAdapter:[adapters objectAtIndex:2]]; + + @try + { + [test getAdapterName]; + } + @catch(ICEConnectionRefusedException*) + { + } + + NSArray* endpoints = getEndpoints(test); + + adapters = [NSMutableArray arrayWithCapacity:3]; + + // + // Now, re-activate the adapters with the same endpoints in the opposite + // order. + // + [adapters addObject:[com createObjectAdapter:@"AdapterAMI66" endpoints:[endpoints objectAtIndex:2]]]; + for(i = 0; i < nRetry && [getAdapterNameWithAMI(test) isEqualToString:@"AdapterAMI66"]; i++); +#if TARGET_OS_IPHONE > 0 + test(i >= nRetry - 1); // WORKAROUND: for connection establishment hang. +#else + test(i == nRetry); +#endif + [adapters addObject:[com createObjectAdapter:@"AdapterAMI65" endpoints:[endpoints objectAtIndex:1]]]; + for(i = 0; i < nRetry && [getAdapterNameWithAMI(test) isEqualToString:@"AdapterAMI65"]; i++); +#if TARGET_OS_IPHONE > 0 + test(i >= nRetry - 1); // WORKAROUND: for connection establishment hang. +#else + test(i == nRetry); +#endif + [adapters addObject:[com createObjectAdapter:@"AdapterAMI64" endpoints:[endpoints objectAtIndex:0]]]; + for(i = 0; i < nRetry && [getAdapterNameWithAMI(test) isEqualToString:@"AdapterAMI64"]; i++); +#if TARGET_OS_IPHONE > 0 + test(i >= nRetry - 1); // WORKAROUND: for connection establishment hang. +#else + test(i == nRetry); +#endif + + deactivate(com, adapters); + } + tprintf("ok\n"); + + tprintf("testing endpoint mode filtering... "); + { + NSMutableArray* adapters = [NSMutableArray arrayWithCapacity:3]; + [adapters addObject:[com createObjectAdapter:@"Adapter71" endpoints:@"default"]]; + [adapters addObject:[com createObjectAdapter:@"Adapter72" endpoints:@"udp"]]; + + id<TestBindingTestIntfPrx> test = createTestIntfPrx(adapters); + test([[test getAdapterName] isEqualToString:@"Adapter71"]); + + id<TestBindingTestIntfPrx> testUDP = [TestBindingTestIntfPrx uncheckedCast:[test ice_datagram]]; + test([test ice_getConnection] != [testUDP ice_getConnection]); + @try + { + [testUDP getAdapterName]; + } + @catch(ICETwowayOnlyException*) + { + } + } + tprintf("ok\n"); + + if([[[communicator getProperties] getProperty:@"Ice.Default.Protocol"] isEqual:@"ssl"]) + { + tprintf("testing unsecure vs. secure endpoints... "); + { + NSMutableArray* adapters = [NSMutableArray arrayWithCapacity:3]; + [adapters addObject:[com createObjectAdapter:@"Adapter81" endpoints:@"ssl"]]; + [adapters addObject:[com createObjectAdapter:@"Adapter82" endpoints:@"tcp"]]; + + id<TestBindingTestIntfPrx> test = createTestIntfPrx(adapters); + int i; + for(i = 0; i < 5; i++) + { + test([[test getAdapterName] isEqualToString:@"Adapter82"]); + [[test ice_getConnection] close:NO]; + } + + id<TestBindingTestIntfPrx> testSecure = [TestBindingTestIntfPrx uncheckedCast:[test ice_secure:YES]]; + test([testSecure ice_isSecure]); + testSecure = [TestBindingTestIntfPrx uncheckedCast:[test ice_secure:NO]]; + test(![testSecure ice_isSecure]); + testSecure = [TestBindingTestIntfPrx uncheckedCast:[test ice_secure:YES]]; + test([testSecure ice_isSecure]); + test([test ice_getConnection] != [testSecure ice_getConnection]); + + [com deactivateObjectAdapter:[adapters objectAtIndex:1]]; + + for(i = 0; i < 5; i++) + { + test([[test getAdapterName] isEqualToString:@"Adapter81"]); + [[test ice_getConnection] close:NO]; + } + + [com createObjectAdapter:@"Adapter83" endpoints:[getEndpoints(test) objectAtIndex:1]]; // Reactive tcp OA. + + for(i = 0; i < 5; i++) + { + test([[test getAdapterName] isEqualToString:@"Adapter83"]); + [[test ice_getConnection] close:NO]; + } + + [com deactivateObjectAdapter:[adapters objectAtIndex:0]]; + @try + { + [testSecure ice_ping]; + test(NO); + } + @catch(ICEConnectionRefusedException*) + { + } + + deactivate(com, adapters); + } + tprintf("ok\n"); + } + + [com shutdown]; +} + diff --git a/objective-c/test/Ice/binding/BindingTest.ice b/objective-c/test/Ice/binding/BindingTest.ice new file mode 100644 index 00000000000..65be70c52df --- /dev/null +++ b/objective-c/test/Ice/binding/BindingTest.ice @@ -0,0 +1,37 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#pragma once + +["objc:prefix:TestBinding"] +module Test +{ + +interface TestIntf +{ + string getAdapterName(); +}; + +interface RemoteObjectAdapter +{ + TestIntf* getTestIntf(); + + void deactivate(); +}; + +interface RemoteCommunicator +{ + RemoteObjectAdapter* createObjectAdapter(string name, string endpoints); + + void deactivateObjectAdapter(RemoteObjectAdapter* adapter); + + void shutdown(); +}; + +}; diff --git a/objective-c/test/Ice/binding/Client.m b/objective-c/test/Ice/binding/Client.m new file mode 100644 index 00000000000..375e6f2f18b --- /dev/null +++ b/objective-c/test/Ice/binding/Client.m @@ -0,0 +1,69 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <TestCommon.h> +#import <BindingTest.h> + +static int +run(id<ICECommunicator> communicator) +{ + void bindingAllTests(id<ICECommunicator>); + bindingAllTests(communicator); + return EXIT_SUCCESS; +} + +#if TARGET_OS_IPHONE +# define main bindingClient +#endif + +int +main(int argc, char* argv[]) +{ + int status; + @autoreleasepool + { + id<ICECommunicator> communicator = nil; + @try + { + ICEInitializationData* initData = [ICEInitializationData initializationData]; + initData.properties = defaultClientProperties(&argc, argv); +#if TARGET_OS_IPHONE + initData.prefixTable__ = [NSDictionary dictionaryWithObjectsAndKeys: + @"TestBinding", @"::Test", + nil]; +#endif + communicator = [ICEUtil createCommunicator:&argc argv:argv initData:initData]; + status = run(communicator); + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + @catch(TestFailedException* ex) + { + status = EXIT_FAILURE; + } + + if(communicator) + { + @try + { + [communicator destroy]; + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + } + } + return status; +} diff --git a/objective-c/test/Ice/binding/Makefile b/objective-c/test/Ice/binding/Makefile new file mode 100644 index 00000000000..a9da9aad0c7 --- /dev/null +++ b/objective-c/test/Ice/binding/Makefile @@ -0,0 +1,37 @@ +# ********************************************************************** +# +# Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +# +# This copy of Ice is licensed to you under the terms described in the +# ICE_LICENSE file included in this distribution. +# +# ********************************************************************** + +top_srcdir = ../../.. + +CLIENT = client +SERVER = server + +TARGETS = $(CLIENT) $(SERVER) + +SLICE_OBJS = BindingTest.o + +COBJS = Client.o \ + AllTests.o + +SOBJS = TestI.o \ + Server.o + +OBJS = $(COBJS) $(SOBJS) $(SLICE_OBJS) + +include $(top_srcdir)/config/Make.rules + +CPPFLAGS := -I. -I.. -I../../include $(CPPFLAGS) + +$(CLIENT): $(COBJS) $(SLICE_OBJS) + rm -f $@ + $(CXX) $(LDFLAGS) $(LDEXEFLAGS) -o $@ $(COBJS) $(SLICE_OBJS) $(TEST_LIBS) + +$(SERVER): $(SOBJS) $(SLICE_OBJS) + rm -f $@ + $(CXX) $(LDFLAGS) $(LDEXEFLAGS) -o $@ $(SOBJS) $(SLICE_OBJS) $(TEST_LIBS) diff --git a/objective-c/test/Ice/binding/Server.m b/objective-c/test/Ice/binding/Server.m new file mode 100644 index 00000000000..695129c7173 --- /dev/null +++ b/objective-c/test/Ice/binding/Server.m @@ -0,0 +1,75 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <binding/TestI.h> +#import <TestCommon.h> + +static int +run(id<ICECommunicator> communicator) +{ + [[communicator getProperties] setProperty:@"TestAdapter.Endpoints" value:@"default -p 12010:udp"]; + id<ICEObjectAdapter> adapter = [communicator createObjectAdapter:@"TestAdapter"]; + [adapter add:[RemoteCommunicatorI remoteCommunicator] identity:[communicator stringToIdentity:@"communicator"]]; + [adapter activate]; + + // Disable ready print for further adapters. + [[communicator getProperties] setProperty:@"Ice.PrintAdapterReady" value:@"0"]; + + serverReady(communicator); + + [communicator waitForShutdown]; + return EXIT_SUCCESS; +} + +#if TARGET_OS_IPHONE +# define main bindingServer +#endif + +int +main(int argc, char* argv[]) +{ + @autoreleasepool + { + int status; + id<ICECommunicator> communicator = nil; + + @try + { + ICEInitializationData* initData = [ICEInitializationData initializationData]; + initData.properties = defaultServerProperties(&argc, argv); +#if TARGET_OS_IPHONE + initData.prefixTable__ = [NSDictionary dictionaryWithObjectsAndKeys: + @"TestBinding", @"::Test", + nil]; +#endif + communicator = [ICEUtil createCommunicator:&argc argv:argv initData:initData]; + status = run(communicator); + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + + if(communicator) + { + @try + { + [communicator destroy]; + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + } + return status; + } +} diff --git a/objective-c/test/Ice/binding/TestI.h b/objective-c/test/Ice/binding/TestI.h new file mode 100644 index 00000000000..1b6e28598b5 --- /dev/null +++ b/objective-c/test/Ice/binding/TestI.h @@ -0,0 +1,35 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <BindingTest.h> + +@interface RemoteCommunicatorI : TestBindingRemoteCommunicator<TestBindingRemoteCommunicator> +{ + int nextPort_; +} +-(id<TestBindingRemoteObjectAdapterPrx>) createObjectAdapter:(NSMutableString *)name + endpoints:(NSMutableString *)endpoints current:(ICECurrent *)current; +-(void) deactivateObjectAdapter:(id<TestBindingRemoteObjectAdapterPrx>)adapter current:(ICECurrent *)current; +-(void) shutdown:(ICECurrent *)current; +@end + +@interface RemoteObjectAdapterI : TestBindingRemoteObjectAdapter<TestBindingRemoteObjectAdapter> +{ + id<ICEObjectAdapter> adapter_; + id<TestBindingTestIntfPrx> testIntf_; +} +-(id)initWithAdapter:(id<ICEObjectAdapter>)adapter; +-(id<TestBindingTestIntfPrx>) getTestIntf:(ICECurrent *)current; +-(void) deactivate:(ICECurrent *)current; +@end + +@interface TestBindingI : TestBindingTestIntf<TestBindingTestIntf> +-(NSString *) getAdapterName:(ICECurrent *)current; +@end + diff --git a/objective-c/test/Ice/binding/TestI.m b/objective-c/test/Ice/binding/TestI.m new file mode 100644 index 00000000000..1547ecc5181 --- /dev/null +++ b/objective-c/test/Ice/binding/TestI.m @@ -0,0 +1,94 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <binding/TestI.h> + +@implementation RemoteCommunicatorI +-(id) init +{ + self = [super init]; + if(!self) + { + return nil; + } + nextPort_ = 10001; + return self; +} + + +-(id<TestBindingRemoteObjectAdapterPrx>) createObjectAdapter:(NSMutableString*)name endpoints:(NSMutableString*)endpts + current:(ICECurrent*)current +{ + id<ICECommunicator> com = [current.adapter getCommunicator]; + [[com getProperties] setProperty:[name stringByAppendingString:@".ThreadPool.Size"] value:@"1"]; + id<ICEObjectAdapter> adapter = [com createObjectAdapterWithEndpoints:name endpoints:endpts]; + RemoteObjectAdapterI* remote = ICE_AUTORELEASE([[RemoteObjectAdapterI alloc] initWithAdapter:adapter]); + return [TestBindingRemoteObjectAdapterPrx uncheckedCast:[current.adapter addWithUUID:remote]]; +} + +-(void) deactivateObjectAdapter:(id<TestBindingRemoteObjectAdapterPrx>)adapter current:(ICECurrent*)current +{ + [adapter deactivate]; // Collocated call +} + +-(void) shutdown:(ICECurrent*)current +{ + [[current.adapter getCommunicator] shutdown]; +} +@end + +@implementation RemoteObjectAdapterI +-(id) initWithAdapter:(id<ICEObjectAdapter>)adapter +{ + self = [super init]; + if(!self) + { + return nil; + } + adapter_ = ICE_RETAIN(adapter); + testIntf_ = ICE_RETAIN([TestBindingTestIntfPrx uncheckedCast:[ + adapter_ add:[TestBindingI testIntf] + identity:[[adapter_ getCommunicator] stringToIdentity:@"test"]]]); + [adapter_ activate]; + return self; +} + +#if defined(__clang__) && !__has_feature(objc_arc) +-(void) dealloc +{ + [testIntf_ release]; + [adapter_ release]; + [super dealloc]; +} +#endif + +-(id<TestBindingTestIntfPrx>) getTestIntf:(ICECurrent*)current +{ + return testIntf_; +} + +-(void) deactivate:(ICECurrent*)current +{ + @try + { + [adapter_ destroy]; + } + @catch(ICEObjectAdapterDeactivatedException*) + { + } +} +@end + +@implementation TestBindingI +-(NSString*) getAdapterName:(ICECurrent*)current +{ + return [current.adapter getName]; +} +@end diff --git a/objective-c/test/Ice/binding/run.py b/objective-c/test/Ice/binding/run.py new file mode 100755 index 00000000000..ce8c5dd4b18 --- /dev/null +++ b/objective-c/test/Ice/binding/run.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python +# ********************************************************************** +# +# Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +# +# This copy of Ice is licensed to you under the terms described in the +# ICE_LICENSE file included in this distribution. +# +# ********************************************************************** + +import os, sys + +path = [ ".", "..", "../..", "../../..", "../../../..", "../../../../.." ] +head = os.path.dirname(sys.argv[0]) +if len(head) > 0: + path = [os.path.join(head, p) for p in path] +path = [os.path.abspath(p) for p in path if os.path.exists(os.path.join(p, "scripts", "TestUtil.py")) ] +if len(path) == 0: + raise RuntimeError("can't find toplevel directory!") +sys.path.append(os.path.join(path[0], "scripts")) +import TestUtil + +TestUtil.clientServerTest() diff --git a/objective-c/test/Ice/defaultServant/.gitignore b/objective-c/test/Ice/defaultServant/.gitignore new file mode 100644 index 00000000000..f330ebd1012 --- /dev/null +++ b/objective-c/test/Ice/defaultServant/.gitignore @@ -0,0 +1,7 @@ +// Generated by makegitignore.py + +// IMPORTANT: Do not edit this file -- any edits made here will be lost! +client +.depend +DefaultServantTest.m +DefaultServantTest.h diff --git a/objective-c/test/Ice/defaultServant/Client.m b/objective-c/test/Ice/defaultServant/Client.m new file mode 100644 index 00000000000..4baeb27d6e0 --- /dev/null +++ b/objective-c/test/Ice/defaultServant/Client.m @@ -0,0 +1,196 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <TestCommon.h> +#import <DefaultServantTest.h> +#import <defaultServant/MyObjectI.h> + +static int +run(id<ICECommunicator> communicator) +{ + // + // Create OA + // + id<ICEObjectAdapter> oa = [communicator createObjectAdapterWithEndpoints:@"MyOA" endpoints:@"tcp -h localhost"]; + [oa activate]; + ICEObject* servant = [TestDefaultServantMyObjectI myObject]; + + // + // Register default servant with category "foo" + // + [oa addDefaultServant:servant category:@"foo"]; + + // + // Start test + // + tprintf("testing single category... "); + ICEObject* r = [oa findDefaultServant:@"foo"]; + test(r == servant); + + r = [oa findDefaultServant:@"bar"]; + test(r == nil); + + ICEIdentity* identity = [ICEIdentity identity:@"" category:@"foo"]; + NSArray* stringArray = [NSArray arrayWithObjects:@"foo", @"bar", @"x", @"y", @"abcdefg", nil]; + + for(NSString* name in stringArray) + { + [identity setName:name]; + id<TestDefaultServantMyObjectPrx> prx = [TestDefaultServantMyObjectPrx uncheckedCast:[oa createProxy:identity]]; + [prx ice_ping]; + test([[prx getName] isEqualToString:name]); + } + + [identity setName:@"ObjectNotExist"]; + id<TestDefaultServantMyObjectPrx> prx = [TestDefaultServantMyObjectPrx uncheckedCast:[oa createProxy:identity]]; + @try + { + [prx ice_ping]; + //test(NO); + } + @catch(ICEObjectNotExistException*) + { + // expected + } + @try + { + [prx getName]; + test(NO); + } + @catch(ICEObjectNotExistException*) + { + // expected + } + + [identity setName:@"FacetNotExist"]; + prx = [TestDefaultServantMyObjectPrx uncheckedCast:[oa createProxy:identity]]; + + @try + { + [prx ice_ping]; + test(NO); + } + @catch(ICEFacetNotExistException*) + { + // expected + } + + @try + { + [prx getName]; + test(NO); + } + @catch(ICEFacetNotExistException*) + { + // expected + } + + [identity setCategory:@"bar"]; + for(NSString* name in stringArray) + { + [identity setName:name]; + id<TestDefaultServantMyObjectPrx> prx = [TestDefaultServantMyObjectPrx uncheckedCast:[oa createProxy:identity]]; + + @try + { + [prx ice_ping]; + test(NO); + } + @catch(ICEObjectNotExistException*) + { + } + + @try + { + [prx getName]; + test(NO); + } + @catch(ICEObjectNotExistException*) + { + } + } + tprintf("ok\n"); + tprintf("testing default category... "); + + [oa addDefaultServant:servant category:@""]; + + r = [oa findDefaultServant:@"bar"]; + test(r == nil); + + r = [oa findDefaultServant:@""]; + test(r == servant); + + for(NSString* name in stringArray) + { + [identity setName:name]; + id<TestDefaultServantMyObjectPrx> prx = [TestDefaultServantMyObjectPrx uncheckedCast:[oa createProxy:identity]]; + [prx ice_ping]; + test([[prx getName] isEqualToString:name]); + } + tprintf("ok\n"); + return 0; +} + +#if TARGET_OS_IPHONE +# define main defaultServantClient + +int +defaultServantServer(int argc, char* argv[]) +{ + serverReady(nil); + return 0; +} +#endif + +int +main(int argc, char* argv[]) +{ + int status; + @autoreleasepool + { + id<ICECommunicator> communicator = nil; + @try + { + ICEInitializationData* initData = [ICEInitializationData initializationData]; + initData.properties = defaultClientProperties(&argc, argv); +#if TARGET_OS_IPHONE + initData.prefixTable__ = [NSDictionary dictionaryWithObjectsAndKeys: + @"TestDefaultServant", @"::Test", + nil]; +#endif + communicator = [ICEUtil createCommunicator:&argc argv:argv initData:initData]; + status = run(communicator); + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + @catch(TestFailedException* ex) + { + status = EXIT_FAILURE; + } + + if(communicator) + { + @try + { + [communicator destroy]; + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + } + } + return status; +} + diff --git a/objective-c/test/Ice/defaultServant/DefaultServantTest.ice b/objective-c/test/Ice/defaultServant/DefaultServantTest.ice new file mode 100644 index 00000000000..580787d52a3 --- /dev/null +++ b/objective-c/test/Ice/defaultServant/DefaultServantTest.ice @@ -0,0 +1,21 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#pragma once + +["objc:prefix:TestDefaultServant"] +module Test +{ + +interface MyObject +{ + string getName(); +}; + +}; diff --git a/objective-c/test/Ice/defaultServant/Makefile b/objective-c/test/Ice/defaultServant/Makefile new file mode 100644 index 00000000000..76982f8e7d8 --- /dev/null +++ b/objective-c/test/Ice/defaultServant/Makefile @@ -0,0 +1,29 @@ +# ********************************************************************** +# +# Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +# +# This copy of Ice is licensed to you under the terms described in the +# ICE_LICENSE file included in this distribution. +# +# ********************************************************************** + +top_srcdir = ../../.. + +CLIENT = client + +TARGETS = $(CLIENT) + +SLICE_OBJS = DefaultServantTest.o + +COBJS = Client.o \ + MyObjectI.o + +OBJS = $(COBJS) $(SLICE_OBJS) + +include $(top_srcdir)/config/Make.rules + +CPPFLAGS := -I. -I.. -I../../include $(CPPFLAGS) + +$(CLIENT): $(COBJS) $(SLICE_OBJS) + rm -f $@ + $(CXX) $(LDFLAGS) $(LDEXEFLAGS) -o $@ $(COBJS) $(SLICE_OBJS) $(TEST_LIBS) diff --git a/objective-c/test/Ice/defaultServant/MyObjectI.h b/objective-c/test/Ice/defaultServant/MyObjectI.h new file mode 100644 index 00000000000..4cbfb538f60 --- /dev/null +++ b/objective-c/test/Ice/defaultServant/MyObjectI.h @@ -0,0 +1,13 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <DefaultServantTest.h> + +@interface TestDefaultServantMyObjectI : TestDefaultServantMyObject<TestDefaultServantMyObject> +@end diff --git a/objective-c/test/Ice/defaultServant/MyObjectI.m b/objective-c/test/Ice/defaultServant/MyObjectI.m new file mode 100644 index 00000000000..e4b6868a97e --- /dev/null +++ b/objective-c/test/Ice/defaultServant/MyObjectI.m @@ -0,0 +1,46 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <defaultServant/MyObjectI.h> + +@implementation TestDefaultServantMyObjectI + +-(void) ice_ping:(ICECurrent*)current +{ + NSString* name = current.id_.name; + + if([name isEqualToString:@"ObjectNotExist"]) + { + @throw [ICEObjectNotExistException objectNotExistException:__FILE__ line:__LINE__]; + } + + if([name isEqualToString:@"FacetNotExist"]) + { + @throw [ICEFacetNotExistException facetNotExistException:__FILE__ line:__LINE__]; + } +} + +-(NSString*) getName:(ICECurrent*)current +{ + NSString* name = current.id_.name; + + if([name isEqualToString:@"ObjectNotExist"]) + { + @throw [ICEObjectNotExistException objectNotExistException:__FILE__ line:__LINE__]; + } + + if([name isEqualToString:@"FacetNotExist"]) + { + @throw [ICEFacetNotExistException facetNotExistException:__FILE__ line:__LINE__]; + } + + return name; +} +@end diff --git a/objective-c/test/Ice/defaultServant/run.py b/objective-c/test/Ice/defaultServant/run.py new file mode 100755 index 00000000000..b155d75909d --- /dev/null +++ b/objective-c/test/Ice/defaultServant/run.py @@ -0,0 +1,25 @@ +#!/usr/bin/env python +# ********************************************************************** +# +# Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +# +# This copy of Ice is licensed to you under the terms described in the +# ICE_LICENSE file included in this distribution. +# +# ********************************************************************** + +import os, sys + +path = [ ".", "..", "../..", "../../..", "../../../..", "../../../../.." ] +head = os.path.dirname(sys.argv[0]) +if len(head) > 0: + path = [os.path.join(head, p) for p in path] +path = [os.path.abspath(p) for p in path if os.path.exists(os.path.join(p, "scripts", "TestUtil.py")) ] +if len(path) == 0: + raise RuntimeError("can't find toplevel directory!") +sys.path.append(os.path.join(path[0], "scripts")) +import TestUtil + +client = os.path.join(os.getcwd(), "client") + +TestUtil.simpleTest(client) diff --git a/objective-c/test/Ice/defaultValue/.gitignore b/objective-c/test/Ice/defaultValue/.gitignore new file mode 100644 index 00000000000..e4c2ca683a3 --- /dev/null +++ b/objective-c/test/Ice/defaultValue/.gitignore @@ -0,0 +1,7 @@ +// Generated by makegitignore.py + +// IMPORTANT: Do not edit this file -- any edits made here will be lost! +client +.depend +DefaultValueTest.m +DefaultValueTest.h diff --git a/objective-c/test/Ice/defaultValue/AllTests.m b/objective-c/test/Ice/defaultValue/AllTests.m new file mode 100644 index 00000000000..31be19f650b --- /dev/null +++ b/objective-c/test/Ice/defaultValue/AllTests.m @@ -0,0 +1,144 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <TestCommon.h> +#import <DefaultValueTest.h> + +#import <Foundation/Foundation.h> + +void +defaultValueAllTests() +{ + tprintf("testing default values... "); + + { + TestDefaultValueStruct1* v = [TestDefaultValueStruct1 struct1]; + test(!v.boolFalse); + test(v.boolTrue); + test(v.b == 254); + test(v.s == 16000); + test(v.i == 3); + test(v.l == 4); + test(v.f == 5.0); + test(v.d == 6.0); + test([v.str isEqualToString:@"foo bar"]); + test(v.c == TestDefaultValuered); + test([v.noDefault length] == 0); + } + + { + TestDefaultValueStruct2* v = [TestDefaultValueStruct2 struct2]; + test(!v.boolFalse); + test(v.boolTrue); + test(v.b == 1); + test(v.s == 2); + test(v.i == 3); + test(v.l == 4); + test(v.f == 5.0); + test(v.d == 6.0); + test([v.str isEqualToString:@"foo bar"]); + test(v.c == TestDefaultValueblue); + test([v.noDefault length] == 0); + } + + { + TestDefaultValueBase* v = [TestDefaultValueBase base]; + test(!v.boolFalse); + test(v.boolTrue); + test(v.b == 1); + test(v.s == 2); + test(v.i == 3); + test(v.l == 4); + test(v.f == 5.0); + test(v.d == 6.0); + test([v.str isEqualToString:@"foo bar"]); + test([v.noDefault length] == 0); + } + + { + TestDefaultValueDerived* v = [TestDefaultValueDerived derived]; + test(!v.boolFalse); + test(v.boolTrue); + test(v.b == 1); + test(v.s == 2); + test(v.i == 3); + test(v.l == 4); + test(v.f == 5.0); + test(v.d == 6.0); + test([v.str isEqualToString:@"foo bar"]); + test([v.noDefault length] == 0); + test(v.c == TestDefaultValuegreen); + } + + { + TestDefaultValueBaseEx* v = [TestDefaultValueBaseEx baseEx]; + test(!v.boolFalse); + test(v.boolTrue); + test(v.b == 1); + test(v.s == 2); + test(v.i == 3); + test(v.l == 4); + test(v.f == 5.0); + test(v.d == 6.0); + test([v.str isEqualToString:@"foo bar"]); + test([v.noDefault length] == 0); + } + + { + TestDefaultValueDerivedEx* v = [TestDefaultValueDerivedEx derivedEx]; + test(!v.boolFalse); + test(v.boolTrue); + test(v.b == 1); + test(v.s == 2); + test(v.i == 3); + test(v.l == 4); + test(v.f == 5.0); + test(v.d == 6.0); + test([v.str isEqualToString:@"foo bar"]); + test([v.noDefault length] == 0); + test(v.c == TestDefaultValuegreen); + } + + tprintf("ok\n"); + + tprintf("testing default constructor... "); + + { + TestDefaultValueStructNoDefaults* v = [TestDefaultValueStructNoDefaults structNoDefaults]; + test(v.bo == NO); + test(v.b == 0); + test(v.s == 0); + test(v.i == 0); + test(v.l == 0); + test(v.f == 0.0); + test(v.d == 0.0); + test([v.str isEqual:@""]); + test(v.c1 == TestDefaultValuered); + test(v.bs == nil); + test(v.is == nil); + test(v.st != nil); + test(v.dict == nil); + + TestDefaultValueExceptionNoDefaults* e = [TestDefaultValueExceptionNoDefaults exceptionNoDefaults]; + test([e.str isEqual:@""]); + test(e.c1 == TestDefaultValuered); + test(e.bs == nil); + test(e.st != nil); + test(e.dict == nil); + + TestDefaultValueClassNoDefaults* cl = [TestDefaultValueClassNoDefaults classNoDefaults]; + test([cl.str isEqual:@""]); + test(cl.c1 == TestDefaultValuered); + test(cl.bs == nil); + test(cl.st != nil); + test(cl.dict == nil); + } + tprintf("ok\n"); +} diff --git a/objective-c/test/Ice/defaultValue/Client.m b/objective-c/test/Ice/defaultValue/Client.m new file mode 100644 index 00000000000..68350320cb3 --- /dev/null +++ b/objective-c/test/Ice/defaultValue/Client.m @@ -0,0 +1,47 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <TestCommon.h> +#import <DefaultValueTest.h> + +static int +run() +{ + void defaultValueAllTests(); + defaultValueAllTests(); + return EXIT_SUCCESS; +} + +#if TARGET_OS_IPHONE +# define main defaultValueClient +#endif + +int +main(int argc, char* argv[]) +{ + @autoreleasepool + { + int status; + @try + { + status = run(); + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + @catch(TestFailedException* ex) + { + status = EXIT_FAILURE; + } + return status; + } +} diff --git a/objective-c/test/Ice/defaultValue/DefaultValueTest.ice b/objective-c/test/Ice/defaultValue/DefaultValueTest.ice new file mode 100644 index 00000000000..876b763a393 --- /dev/null +++ b/objective-c/test/Ice/defaultValue/DefaultValueTest.ice @@ -0,0 +1,139 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#pragma once + +["objc:prefix:TestDefaultValue"] +module Test +{ + +enum Color { red, green, blue }; + +struct Struct1 +{ + bool boolFalse = false; + bool boolTrue = true; + byte b = 254; + short s = 16000; + int i = 3; + long l = 4; + float f = 5.0; + double d = 6.0; + string str = "foo bar"; + Color c = red; + string noDefault; +}; + +["cpp:class"] +struct Struct2 +{ + bool boolFalse = false; + bool boolTrue = true; + byte b = 1; + short s = 2; + int i = 3; + long l = 4; + float f = 5.0; + double d = 6.0; + string str = "foo bar"; + Color c = blue; + string noDefault; +}; + +class Base +{ + bool boolFalse = false; + bool boolTrue = true; + byte b = 1; + short s = 2; + int i = 3; + long l = 4; + float f = 5.0; + double d = 6.0; + string str = "foo bar"; + string noDefault; +}; + +class Derived extends Base +{ + Color c = green; +}; + +exception BaseEx +{ + bool boolFalse = false; + bool boolTrue = true; + byte b = 1; + short s = 2; + int i = 3; + long l = 4; + float f = 5.0; + double d = 6.0; + string str = "foo bar"; + string noDefault; +}; + +exception DerivedEx extends BaseEx +{ + Color c = green; +}; + +sequence<byte> ByteSeq; +sequence<int> IntSeq; +dictionary<int, string> IntStringDict; + +struct InnerStruct +{ + int a; +}; + +struct StructNoDefaults +{ + bool bo; + byte b; + short s; + int i; + long l; + float f; + double d; + string str; + Color c1; + ByteSeq bs; + IntSeq is; + InnerStruct st; + IntStringDict dict; +}; + +exception ExceptionNoDefaultsBase +{ + string str; + Color c1; + ByteSeq bs; +}; + +exception ExceptionNoDefaults extends ExceptionNoDefaultsBase +{ + InnerStruct st; + IntStringDict dict; +}; + +class ClassNoDefaultsBase +{ + string str; + Color c1; + ByteSeq bs; +}; + +class ClassNoDefaults extends ClassNoDefaultsBase +{ + InnerStruct st; + IntStringDict dict; +}; + +}; diff --git a/objective-c/test/Ice/defaultValue/Makefile b/objective-c/test/Ice/defaultValue/Makefile new file mode 100644 index 00000000000..0fb65a35f58 --- /dev/null +++ b/objective-c/test/Ice/defaultValue/Makefile @@ -0,0 +1,29 @@ +# ********************************************************************** +# +# Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +# +# This copy of Ice is licensed to you under the terms described in the +# ICE_LICENSE file included in this distribution. +# +# ********************************************************************** + +top_srcdir = ../../.. + +CLIENT = client + +TARGETS = $(CLIENT) + +SLICE_OBJS = DefaultValueTest.o + +COBJS = Client.o \ + AllTests.o + +OBJS = $(COBJS) $(SLICE_OBJS) + +include $(top_srcdir)/config/Make.rules + +CPPFLAGS := -I. -I.. -I../../include $(CPPFLAGS) + +$(CLIENT): $(COBJS) $(SLICE_OBJS) + rm -f $@ + $(CXX) $(LDFLAGS) $(LDEXEFLAGS) -o $@ $(COBJS) $(SLICE_OBJS) $(TEST_LIBS) diff --git a/objective-c/test/Ice/defaultValue/run.py b/objective-c/test/Ice/defaultValue/run.py new file mode 100755 index 00000000000..e925f3c7010 --- /dev/null +++ b/objective-c/test/Ice/defaultValue/run.py @@ -0,0 +1,24 @@ +#!/usr/bin/env python +# ********************************************************************** +# +# Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +# +# This copy of Ice is licensed to you under the terms described in the +# ICE_LICENSE file included in this distribution. +# +# ********************************************************************** + +import os, sys + +path = [ ".", "..", "../..", "../../..", "../../../..", "../../../../.." ] +head = os.path.dirname(sys.argv[0]) +if len(head) > 0: + path = [os.path.join(head, p) for p in path] +path = [os.path.abspath(p) for p in path if os.path.exists(os.path.join(p, "scripts", "TestUtil.py")) ] +if len(path) == 0: + raise RuntimeError("can't find toplevel directory!") +sys.path.append(os.path.join(path[0], "scripts")) +import TestUtil + +client = os.path.join(os.getcwd(), "client") +TestUtil.simpleTest(client) diff --git a/objective-c/test/Ice/dispatcher/.gitignore b/objective-c/test/Ice/dispatcher/.gitignore new file mode 100644 index 00000000000..6d0e4a9258e --- /dev/null +++ b/objective-c/test/Ice/dispatcher/.gitignore @@ -0,0 +1,9 @@ +// Generated by makegitignore.py + +// IMPORTANT: Do not edit this file -- any edits made here will be lost! +client +server +collocated +.depend +DispatcherTest.m +DispatcherTest.h diff --git a/objective-c/test/Ice/dispatcher/AllTests.m b/objective-c/test/Ice/dispatcher/AllTests.m new file mode 100644 index 00000000000..4689a7b4e04 --- /dev/null +++ b/objective-c/test/Ice/dispatcher/AllTests.m @@ -0,0 +1,163 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <TestCommon.h> +#import <DispatcherTest.h> + +#import <Foundation/Foundation.h> + +static BOOL isDispatcherThread() +{ + return strcmp(dispatch_queue_get_label(DISPATCH_CURRENT_QUEUE_LABEL), "Dispatcher") == 0; +} + +@interface TestDispatcherCallback : NSObject +{ + BOOL called; + NSCondition* cond; +} +-(void) check; +-(void) called; +@end + +@implementation TestDispatcherCallback +-(id) init +{ + self = [super init]; + if(!self) + { + return nil; + } + cond = [[NSCondition alloc] init]; + return self; +} + +#if defined(__clang__) && !__has_feature(objc_arc) +-(void) dealloc +{ + [cond release]; + [super dealloc]; +} +#endif + +-(void) check +{ + [cond lock]; + while(!called) + { + [cond wait]; + } + called = NO; + [cond unlock]; +} +-(void) called +{ + [cond lock]; + called = YES; + [cond signal]; + [cond unlock]; +} +-(void) response +{ + test(isDispatcherThread()); + [self called]; +} + +-(void) exception:(ICEException*)ex +{ + test([ex isKindOfClass:[ICENoEndpointException class]]); + test(isDispatcherThread()); + [self called]; +} +-(void) responseEx +{ + test(NO); +} + +-(void) exceptionEx:(ICEException*)ex +{ + test([ex isKindOfClass:[ICEInvocationTimeoutException class]]); + test(isDispatcherThread()); + [self called]; +} + +-(void) payload +{ + test(isDispatcherThread()); +} + +-(void) ignoreEx:(ICEException*)ex +{ + test([ex isKindOfClass:[ICECommunicatorDestroyedException class]]); +} + +-(void) sent:(BOOL)sentSynchronously +{ + test(sentSynchronously || isDispatcherThread()); +} + +@end + +id<TestDispatcherTestIntfPrx> +dispatcherAllTests(id<ICECommunicator> communicator) +{ + NSString* sref = @"test:default -p 12010"; + id<ICEObjectPrx> obj = [communicator stringToProxy:sref]; + test(obj); + + id<TestDispatcherTestIntfPrx> p = [TestDispatcherTestIntfPrx uncheckedCast:obj]; + + sref = @"testController:tcp -p 12011"; + obj = [communicator stringToProxy:sref]; + test(obj); + + id<TestDispatcherTestIntfControllerPrx> testController = [TestDispatcherTestIntfControllerPrx uncheckedCast:obj]; + + tprintf("testing dispatcher... "); + { + [p op]; + + TestDispatcherCallback* cb = [[TestDispatcherCallback alloc] init]; + [p begin_op:^ { [cb response]; } exception:^(ICEException* ex) { [cb exception:ex]; }]; + [cb check]; + + TestDispatcherTestIntfPrx* i = [p ice_adapterId:@"dummy"]; + [i begin_op:^ { [cb response]; } exception:^(ICEException* ex) { [cb exception:ex]; }]; + [cb check]; + + TestDispatcherTestIntfPrx* to = [p ice_invocationTimeout:250]; + [to begin_sleep:500 response:^ { [cb responseEx]; } exception:^(ICEException* ex) { [cb exceptionEx:ex]; }]; + [cb check]; + + [testController holdAdapter]; + + ICEByte d[1024]; + ICEMutableByteSeq* seq = [ICEMutableByteSeq dataWithBytes:d length:sizeof(d)]; + + id<ICEAsyncResult> result; + @autoreleasepool + { + id response = ^{ [cb payload]; }; + id exception = ^(ICEException* ex) { [cb ignoreEx:ex]; }; + id sent = ^(BOOL ss) { [cb sent:ss]; }; + + while([(result = [p begin_opWithPayload:seq + response:response + exception:exception + sent:sent]) sentSynchronously]); + [testController resumeAdapter]; + [result waitForCompleted]; + } + ICE_RELEASE(cb); + } + tprintf("ok\n"); + + return p; +} diff --git a/objective-c/test/Ice/dispatcher/Client.m b/objective-c/test/Ice/dispatcher/Client.m new file mode 100644 index 00000000000..31e47345614 --- /dev/null +++ b/objective-c/test/Ice/dispatcher/Client.m @@ -0,0 +1,79 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <TestCommon.h> +#import <DispatcherTest.h> +#include <dispatch/dispatch.h> + +static int +run(id<ICECommunicator> communicator) +{ + TestDispatcherTestIntfPrx* dispatcherAllTests(id<ICECommunicator>); + TestDispatcherTestIntfPrx* dispatcher = dispatcherAllTests(communicator); + [dispatcher shutdown]; + return EXIT_SUCCESS; +} + +#if TARGET_OS_IPHONE +# define main dispatcherClient +#endif + +int +main(int argc, char* argv[]) +{ + int status; + @autoreleasepool + { + id<ICECommunicator> communicator = nil; + + @try + { + ICEInitializationData* initData = [ICEInitializationData initializationData]; + initData.properties = defaultClientProperties(&argc, argv); + dispatch_queue_t queue = dispatch_queue_create("Dispatcher", DISPATCH_QUEUE_SERIAL); + initData.dispatcher = ^(id<ICEDispatcherCall> call, id<ICEConnection> con) { + dispatch_sync(queue, ^ { [call run]; }); + }; +#if TARGET_OS_IPHONE + initData.prefixTable__ = [NSDictionary dictionaryWithObjectsAndKeys: + @"TestDispatcher", @"::Test", + nil]; +#endif + communicator = [ICEUtil createCommunicator:&argc argv:argv initData:initData]; + status = run(communicator); +#if defined(__clang__) && !__has_feature(objc_arc) + dispatch_release(queue); +#endif + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + @catch(TestFailedException* ex) + { + status = EXIT_FAILURE; + } + + if(communicator) + { + @try + { + [communicator destroy]; + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + } + } + return status; +} diff --git a/objective-c/test/Ice/dispatcher/Collocated.m b/objective-c/test/Ice/dispatcher/Collocated.m new file mode 100644 index 00000000000..ca8ef93b01f --- /dev/null +++ b/objective-c/test/Ice/dispatcher/Collocated.m @@ -0,0 +1,89 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <dispatcher/TestI.h> +#import <TestCommon.h> +#include <dispatch/dispatch.h> + +static int +run(id<ICECommunicator> communicator) +{ + [[communicator getProperties] setProperty:@"TestAdapter.Endpoints" value:@"default -p 12010"]; + [[communicator getProperties] setProperty:@"ControllerAdapter.Endpoints" value:@"tcp -p 12011"]; + [[communicator getProperties] setProperty:@"ControllerAdapter.ThreadPool.Size" value:@"1"]; + + id<ICEObjectAdapter> adapter = [communicator createObjectAdapter:@"TestAdapter"]; + id<ICEObjectAdapter> adapter2 = [communicator createObjectAdapter:@"ControllerAdapter"]; + + TestDispatcherTestIntfControllerI* testController + = ICE_AUTORELEASE([[TestDispatcherTestIntfControllerI alloc] initWithAdapter:adapter]); + + ICEObject* object = [TestDispatcherTestIntfI testIntf]; + + [adapter add:object identity:[communicator stringToIdentity:@"test"]]; + //[adapter activate]; // Don't activate OA to ensure collocation is used. + + [adapter2 add:testController identity:[communicator stringToIdentity:@"testController"]]; + //[adapter2 activate]; // Don't activate OA to ensure collocation is used. + + TestDispatcherTestIntfPrx* dispatcherAllTests(id<ICECommunicator>); + dispatcherAllTests(communicator); + + return EXIT_SUCCESS; +} + +#if TARGET_OS_IPHONE +# define main dispatcherCollocated +#endif + +int +main(int argc, char* argv[]) +{ + int status; + @autoreleasepool + { + id<ICECommunicator> communicator = nil; + @try + { + ICEInitializationData* initData = [ICEInitializationData initializationData]; + initData.properties = defaultServerProperties(&argc, argv); + dispatch_queue_t queue = dispatch_queue_create("Dispatcher", DISPATCH_QUEUE_SERIAL); + initData.dispatcher = ^(id<ICEDispatcherCall> call, id<ICEConnection> con) { + dispatch_sync(queue, ^ { [call run]; }); + }; +#if TARGET_OS_IPHONE + initData.prefixTable__ = [NSDictionary dictionaryWithObjectsAndKeys: + @"TestDispatcher", @"::Test", + nil]; +#endif + communicator = [ICEUtil createCommunicator:&argc argv:argv initData:initData]; + status = run(communicator); + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + + if(communicator) + { + @try + { + [communicator destroy]; + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + } + } + return status; +} diff --git a/objective-c/test/Ice/dispatcher/DispatcherTest.ice b/objective-c/test/Ice/dispatcher/DispatcherTest.ice new file mode 100644 index 00000000000..bc75ee0ee73 --- /dev/null +++ b/objective-c/test/Ice/dispatcher/DispatcherTest.ice @@ -0,0 +1,32 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#pragma once + +#include <Ice/BuiltinSequences.ice> + +["objc:prefix:TestDispatcher"] +module Test +{ + +interface TestIntf +{ + void op(); + void sleep(int to); + void opWithPayload(Ice::ByteSeq seq); + void shutdown(); +}; + +interface TestIntfController +{ + void holdAdapter(); + void resumeAdapter(); +}; + +}; diff --git a/objective-c/test/Ice/dispatcher/Makefile b/objective-c/test/Ice/dispatcher/Makefile new file mode 100644 index 00000000000..f8da9df04cd --- /dev/null +++ b/objective-c/test/Ice/dispatcher/Makefile @@ -0,0 +1,46 @@ +# ********************************************************************** +# +# Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +# +# This copy of Ice is licensed to you under the terms described in the +# ICE_LICENSE file included in this distribution. +# +# ********************************************************************** + +top_srcdir = ../../.. + +CLIENT = client +SERVER = server +COLLOCATED = collocated + +TARGETS = $(CLIENT) $(SERVER) $(COLLOCATED) + +SLICE_OBJS = DispatcherTest.o + +COBJS = Client.o \ + AllTests.o + +SOBJS = TestI.o \ + Server.o + +COLOBJS = Collocated.o \ + TestI.o \ + AllTests.o + +OBJS = $(COBJS) $(SOBJS) $(SLICE_OBJS) + +include $(top_srcdir)/config/Make.rules + +CPPFLAGS := -I. -I.. -I../../include $(CPPFLAGS) + +$(CLIENT): $(COBJS) $(SLICE_OBJS) + rm -f $@ + $(CXX) $(LDFLAGS) $(LDEXEFLAGS) -o $@ $(COBJS) $(SLICE_OBJS) $(TEST_LIBS) + +$(SERVER): $(SOBJS) $(SLICE_OBJS) + rm -f $@ + $(CXX) $(LDFLAGS) $(LDEXEFLAGS) -o $@ $(SOBJS) $(SLICE_OBJS) $(TEST_LIBS) + +$(COLLOCATED): $(COLOBJS) $(SLICE_OBJS) + rm -f $@ + $(CXX) $(LDFLAGS) $(LDEXEFLAGS) -o $@ $(COLOBJS) $(SLICE_OBJS) $(TEST_LIBS) diff --git a/objective-c/test/Ice/dispatcher/Server.m b/objective-c/test/Ice/dispatcher/Server.m new file mode 100644 index 00000000000..1457f69c077 --- /dev/null +++ b/objective-c/test/Ice/dispatcher/Server.m @@ -0,0 +1,89 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <dispatcher/TestI.h> +#import <TestCommon.h> +#include <dispatch/dispatch.h> + +static int +run(id<ICECommunicator> communicator) +{ + [[communicator getProperties] setProperty:@"TestAdapter.Endpoints" value:@"default -p 12010:udp"]; + [[communicator getProperties] setProperty:@"ControllerAdapter.Endpoints" value:@"tcp -p 12011"]; + [[communicator getProperties] setProperty:@"ControllerAdapter.ThreadPool.Size" value:@"1"]; + + id<ICEObjectAdapter> adapter = [communicator createObjectAdapter:@"TestAdapter"]; + id<ICEObjectAdapter> adapter2 = [communicator createObjectAdapter:@"ControllerAdapter"]; + + TestDispatcherTestIntfControllerI* testController + = ICE_AUTORELEASE([[TestDispatcherTestIntfControllerI alloc] initWithAdapter:adapter]); + + ICEObject* object = [TestDispatcherTestIntfI testIntf]; + + [adapter add:object identity:[communicator stringToIdentity:@"test"]]; + [adapter activate]; + + [adapter2 add:testController identity:[communicator stringToIdentity:@"testController"]]; + [adapter2 activate]; + + serverReady(communicator); + + [communicator waitForShutdown]; + return EXIT_SUCCESS; +} + +#if TARGET_OS_IPHONE +# define main dispatcherServer +#endif + +int +main(int argc, char* argv[]) +{ + int status; + @autoreleasepool + { + id<ICECommunicator> communicator = nil; + @try + { + ICEInitializationData* initData = [ICEInitializationData initializationData]; + initData.properties = defaultServerProperties(&argc, argv); + dispatch_queue_t queue = dispatch_queue_create("Dispatcher", DISPATCH_QUEUE_SERIAL); + initData.dispatcher = ^(id<ICEDispatcherCall> call, id<ICEConnection> con) { + dispatch_sync(queue, ^ { [call run]; }); + }; +#if TARGET_OS_IPHONE + initData.prefixTable__ = [NSDictionary dictionaryWithObjectsAndKeys: + @"TestDispatcher", @"::Test", + nil]; +#endif + communicator = [ICEUtil createCommunicator:&argc argv:argv initData:initData]; + status = run(communicator); + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + + if(communicator) + { + @try + { + [communicator destroy]; + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + } + } + return status; +} diff --git a/objective-c/test/Ice/dispatcher/TestI.h b/objective-c/test/Ice/dispatcher/TestI.h new file mode 100644 index 00000000000..087d1695895 --- /dev/null +++ b/objective-c/test/Ice/dispatcher/TestI.h @@ -0,0 +1,25 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <DispatcherTest.h> + +@interface TestDispatcherTestIntfI : TestDispatcherTestIntf +-(void) op:(ICECurrent *)current; +-(void) opWithPayload:(ICEMutableByteSeq*)seq current:(ICECurrent *)current; +-(void) shutdown:(ICECurrent *)current; +@end + +@interface TestDispatcherTestIntfControllerI : TestDispatcherTestIntfController +{ + id<ICEObjectAdapter> _adapter; +} +-(id) initWithAdapter:(id<ICEObjectAdapter>)adapter; +-(void) holdAdapter:(ICECurrent*)current; +-(void) resumeAdapter:(ICECurrent*)current; +@end diff --git a/objective-c/test/Ice/dispatcher/TestI.m b/objective-c/test/Ice/dispatcher/TestI.m new file mode 100644 index 00000000000..3f0a23eeff6 --- /dev/null +++ b/objective-c/test/Ice/dispatcher/TestI.m @@ -0,0 +1,51 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <dispatcher/TestI.h> + +#import <Foundation/NSThread.h> + +@implementation TestDispatcherTestIntfI +-(void) op:(ICECurrent*)current +{ +} +-(void) sleep:(ICEInt)to current:(ICECurrent*)current +{ + [NSThread sleepForTimeInterval:to / 1000.0]; +} +-(void) opWithPayload:(ICEMutableByteSeq*)data current:(ICECurrent*)current +{ +} +-(void) shutdown:(ICECurrent*)current +{ + [[current.adapter getCommunicator] shutdown]; +} +@end + +@implementation TestDispatcherTestIntfControllerI +-(id) initWithAdapter:(id<ICEObjectAdapter>)adapter +{ + self = [super init]; + if(!self) + { + return nil; + } + _adapter = adapter; + return self; +} +-(void) holdAdapter:(ICECurrent*)current +{ + [_adapter hold]; +} +-(void) resumeAdapter:(ICECurrent*)current +{ + [_adapter activate]; +} +@end diff --git a/objective-c/test/Ice/dispatcher/run.py b/objective-c/test/Ice/dispatcher/run.py new file mode 100755 index 00000000000..0816938a196 --- /dev/null +++ b/objective-c/test/Ice/dispatcher/run.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python +# ********************************************************************** +# +# Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +# +# This copy of Ice is licensed to you under the terms described in the +# ICE_LICENSE file included in this distribution. +# +# ********************************************************************** + +import os, sys + +path = [ ".", "..", "../..", "../../..", "../../../..", "../../../../.." ] +head = os.path.dirname(sys.argv[0]) +if len(head) > 0: + path = [os.path.join(head, p) for p in path] +path = [os.path.abspath(p) for p in path if os.path.exists(os.path.join(p, "scripts", "TestUtil.py")) ] +if len(path) == 0: + raise RuntimeError("can't find toplevel directory!") +sys.path.append(os.path.join(path[0], "scripts")) +import TestUtil + +print("tests with regular server.") +TestUtil.clientServerTest() +print("tests with collocated server.") +TestUtil.collocatedTest() diff --git a/objective-c/test/Ice/enums/.gitignore b/objective-c/test/Ice/enums/.gitignore new file mode 100644 index 00000000000..657ea9d677b --- /dev/null +++ b/objective-c/test/Ice/enums/.gitignore @@ -0,0 +1,8 @@ +// Generated by makegitignore.py + +// IMPORTANT: Do not edit this file -- any edits made here will be lost! +client +server +.depend +EnumTest.m +EnumTest.h diff --git a/objective-c/test/Ice/enums/AllTests.m b/objective-c/test/Ice/enums/AllTests.m new file mode 100644 index 00000000000..4ce24b2b959 --- /dev/null +++ b/objective-c/test/Ice/enums/AllTests.m @@ -0,0 +1,388 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <TestCommon.h> +#import <EnumTest.h> + + +TestEnumTestIntfPrx* +enumAllTests(id<ICECommunicator> communicator) +{ + + ICEObjectPrx* obj = [communicator stringToProxy:@"test:default -p 12010"]; + test(obj); + TestEnumTestIntfPrx* proxy = [TestEnumTestIntfPrx checkedCast:obj]; + test(proxy); + + tprintf("testing enum values... "); + + test((int)(TestEnumbenum1) == 0); + test((int)(TestEnumbenum2) == 1); + test((int)(TestEnumbenum3) == TestEnumByteConst1); + test((int)(TestEnumbenum4) == TestEnumByteConst1 + 1); + test((int)(TestEnumbenum5) == TestEnumShortConst1); + test((int)(TestEnumbenum6) == TestEnumShortConst1 + 1); + test((int)(TestEnumbenum7) == TestEnumIntConst1); + test((int)(TestEnumbenum8) == TestEnumIntConst1 + 1); + test((int)(TestEnumbenum9) == TestEnumLongConst1); + test((int)(TestEnumbenum10) == TestEnumLongConst1 + 1); + test((int)(TestEnumbenum11) == TestEnumByteConst2); + + test((int)(TestEnumsenum1) == 3); + test((int)(TestEnumsenum2) == 4); + test((int)(TestEnumsenum3) == TestEnumByteConst1); + test((int)(TestEnumsenum4) == TestEnumByteConst1 + 1); + test((int)(TestEnumsenum5) == TestEnumShortConst1); + test((int)(TestEnumsenum6) == TestEnumShortConst1 + 1); + test((int)(TestEnumsenum7) == TestEnumIntConst1); + test((int)(TestEnumsenum8) == TestEnumIntConst1 + 1); + test((int)(TestEnumsenum9) == TestEnumLongConst1); + test((int)(TestEnumsenum10) == TestEnumLongConst1 + 1); + test((int)(TestEnumsenum11) == TestEnumShortConst2); + + test((int)(TestEnumienum1) == 0); + test((int)(TestEnumienum2) == 1); + test((int)(TestEnumienum3) == TestEnumByteConst1); + test((int)(TestEnumienum4) == TestEnumByteConst1 + 1); + test((int)(TestEnumienum5) == TestEnumShortConst1); + test((int)(TestEnumienum6) == TestEnumShortConst1 + 1); + test((int)(TestEnumienum7) == TestEnumIntConst1); + test((int)(TestEnumienum8) == TestEnumIntConst1 + 1); + test((int)(TestEnumienum9) == TestEnumLongConst1); + test((int)(TestEnumienum10) == TestEnumLongConst1 + 1); + test((int)(TestEnumienum11) == TestEnumIntConst2); + test((int)(TestEnumienum12) == TestEnumLongConst2); + + test((int)(TestEnumred) == 0); + test((int)(TestEnumgreen) == 1); + test((int)(TestEnumblue) == 2); + + tprintf("ok\n"); + + tprintf("testing enum operations... "); + + TestEnumByteEnum byteEnum; + test([proxy opByte:TestEnumbenum1 b2:&byteEnum] == TestEnumbenum1); + test(byteEnum == TestEnumbenum1); + test([proxy opByte:TestEnumbenum11 b2:&byteEnum] == TestEnumbenum11); + test(byteEnum == TestEnumbenum11); + + TestEnumShortEnum shortEnum; + test([proxy opShort:TestEnumsenum1 s2:&shortEnum] == TestEnumsenum1); + test(shortEnum == TestEnumsenum1); + test([proxy opShort:TestEnumsenum11 s2:&shortEnum] == TestEnumsenum11); + test(shortEnum == TestEnumsenum11); + + TestEnumIntEnum intEnum; + test([proxy opInt:TestEnumienum1 i2:&intEnum] == TestEnumienum1); + test(intEnum == TestEnumienum1); + test([proxy opInt:TestEnumienum11 i2:&intEnum] == TestEnumienum11); + test(intEnum == TestEnumienum11); + test([proxy opInt:TestEnumienum12 i2:&intEnum] == TestEnumienum12); + test(intEnum == TestEnumienum12); + + TestEnumSimpleEnum s; + test([proxy opSimple:TestEnumgreen s2:&s] == TestEnumgreen); + test(s == TestEnumgreen); + tprintf("ok\n"); + + tprintf("testing enum sequences operations... "); + + { + TestEnumByteEnum values[] = {TestEnumbenum1, TestEnumbenum2, TestEnumbenum3, TestEnumbenum4, TestEnumbenum5, + TestEnumbenum6, TestEnumbenum7, TestEnumbenum8, TestEnumbenum9, TestEnumbenum10, + TestEnumbenum11}; + + int enumSize = sizeof(TestEnumByteEnum); + int length = sizeof(values); + int elements = length/enumSize; + + TestEnumMutableByteEnumSeq* enumSeq1 = [NSMutableData dataWithBytes:values length:length]; + TestEnumMutableByteEnumSeq* enumSeq2 = [NSMutableData dataWithLength:length]; + TestEnumByteEnumSeq* enumSeq3 = [proxy opByteSeq:enumSeq1 b2:&enumSeq2]; + + ICEByte* p1 = (ICEByte *)[enumSeq1 bytes]; + ICEByte* p2 = (ICEByte *)[enumSeq2 bytes]; + ICEByte* p3 = (ICEByte *)[enumSeq3 bytes]; + + for(int i = 0; i < elements; ++i) + { + test(*p1 == *p2); + test(*p1 == *p3); + p1++; + p2++; + p3++; + } + } + + { + + TestEnumShortEnum values[] = {TestEnumsenum1, TestEnumsenum2, TestEnumsenum3, TestEnumsenum4, TestEnumsenum5, + TestEnumsenum6, TestEnumsenum7, TestEnumsenum8, TestEnumsenum9, TestEnumsenum10, + TestEnumsenum11}; + + int enumSize = sizeof(TestEnumShortEnum); + int length = sizeof(values); + int elements = length/enumSize; + + TestEnumMutableShortEnumSeq* enumSeq1 = [NSMutableData dataWithBytes:values length:length]; + TestEnumMutableShortEnumSeq* enumSeq2 = [NSMutableData dataWithLength:length]; + TestEnumShortEnumSeq* enumSeq3 = [proxy opShortSeq:enumSeq1 s2:&enumSeq2]; + + ICEByte* p1 = (ICEByte *)[enumSeq1 bytes]; + ICEByte* p2 = (ICEByte *)[enumSeq2 bytes]; + ICEByte* p3 = (ICEByte *)[enumSeq3 bytes]; + + for(int i = 0; i < elements; ++i) + { + test(*p1 == *p2); + test(*p1 == *p3); + p1++; + p2++; + p3++; + } + } + + { + + TestEnumIntEnum values[] = {TestEnumienum1, TestEnumienum2, TestEnumienum3, TestEnumienum4, TestEnumienum5, + TestEnumienum6, TestEnumienum7, TestEnumienum8, TestEnumienum9, TestEnumienum10, + TestEnumienum11}; + + int enumSize = sizeof(TestEnumShortEnum); + int length = sizeof(values); + int elements = length/enumSize; + + TestEnumMutableShortEnumSeq* enumSeq1 = [NSMutableData dataWithBytes:values length:length]; + TestEnumMutableShortEnumSeq* enumSeq2 = [NSMutableData dataWithLength:length]; + TestEnumShortEnumSeq* enumSeq3 = [proxy opIntSeq:enumSeq1 i2:&enumSeq2]; + + ICEByte* p1 = (ICEByte *)[enumSeq1 bytes]; + ICEByte* p2 = (ICEByte *)[enumSeq2 bytes]; + ICEByte* p3 = (ICEByte *)[enumSeq3 bytes]; + + for(int i = 0; i < elements; ++i) + { + test(*p1 == *p2); + test(*p1 == *p3); + p1++; + p2++; + p3++; + } + } + + { + + TestEnumSimpleEnum values[] = {TestEnumred, TestEnumgreen, TestEnumblue}; + + int enumSize = sizeof(TestEnumShortEnum); + int length = sizeof(values); + int elements = length/enumSize; + + TestEnumMutableShortEnumSeq* enumSeq1 = [NSMutableData dataWithBytes:values length:length]; + TestEnumMutableShortEnumSeq* enumSeq2 = [NSMutableData dataWithLength:length]; + TestEnumShortEnumSeq* enumSeq3 = [proxy opSimpleSeq:enumSeq1 s2:&enumSeq2]; + + ICEByte* p1 = (ICEByte *)[enumSeq1 bytes]; + ICEByte* p2 = (ICEByte *)[enumSeq2 bytes]; + ICEByte* p3 = (ICEByte *)[enumSeq3 bytes]; + + for(int i = 0; i < elements; ++i) + { + test(*p1 == *p2); + test(*p1 == *p3); + p1++; + p2++; + p3++; + } + } + + tprintf("ok\n"); + + tprintf("testing enum exceptions... "); + + @try + { + [proxy opByte:(TestEnumByteEnum)-1 b2:&byteEnum]; // Negative enumerators are not supported + test(NO); + } + @catch(ICEMarshalException*) + { + } + + @try + { + [proxy opByte:(TestEnumByteEnum)127 b2:&byteEnum]; // Invalid enumerator + test(NO); + } + @catch(ICEMarshalException*) + { + } + + @try + { + [proxy opShort:(TestEnumShortEnum)-1 s2:&shortEnum]; // Negative enumerators are not supported + test(NO); + } + @catch(const ICEMarshalException*) + { + } + + @try + { + [proxy opShort:(TestEnumShortEnum)0 s2:&shortEnum]; // Invalid enumerator + test(NO); + } + @catch(ICEMarshalException*) + { + } + + @try + { + [proxy opShort:(TestEnumShortEnum)32767 s2:&shortEnum]; // Invalid enumerator + test(NO); + } + @catch(ICEMarshalException*) + { + } + + @try + { + [proxy opInt:(TestEnumIntEnum)-1 i2:&intEnum]; // Negative enumerators are not supported + test(NO); + } + @catch(ICEMarshalException*) + { + } + + { + TestEnumByteEnum values[] = {TestEnumbenum1, TestEnumbenum2, TestEnumbenum3, TestEnumbenum4, TestEnumbenum5, + TestEnumbenum6, (TestEnumByteEnum)-1, TestEnumbenum8, TestEnumbenum9, TestEnumbenum10, + TestEnumbenum11}; // Negative enumerators are not supported + + int length = sizeof(values); + + TestEnumMutableByteEnumSeq* enumSeq1 = [NSMutableData dataWithBytes:values length:length]; + TestEnumMutableByteEnumSeq* enumSeq2 = [NSMutableData dataWithLength:length]; + @try + { + [proxy opByteSeq:enumSeq1 b2:&enumSeq2]; + test(NO); + } + @catch(ICEMarshalException*) + { + } + } + + { + TestEnumByteEnum values[] = {TestEnumbenum1, TestEnumbenum2, TestEnumbenum3, TestEnumbenum4, TestEnumbenum5, + TestEnumbenum6, (TestEnumByteEnum)127, TestEnumbenum8, TestEnumbenum9, TestEnumbenum10, + TestEnumbenum11}; // Invalid enumerator + + int length = sizeof(values); + + TestEnumMutableByteEnumSeq* enumSeq1 = [NSMutableData dataWithBytes:values length:length]; + TestEnumMutableByteEnumSeq* enumSeq2 = [NSMutableData dataWithLength:length]; + @try + { + [proxy opByteSeq:enumSeq1 b2:&enumSeq2]; + test(NO); + } + @catch(ICEMarshalException*) + { + } + } + + { + + TestEnumShortEnum values[] = {TestEnumsenum1, TestEnumsenum2, TestEnumsenum3, TestEnumsenum4, TestEnumsenum5, + (TestEnumShortEnum)-1, TestEnumsenum7, TestEnumsenum8, TestEnumsenum9, TestEnumsenum10, + TestEnumsenum11}; // Negative enumerators are not supported + + int length = sizeof(values); + + TestEnumMutableShortEnumSeq* enumSeq1 = [NSMutableData dataWithBytes:values length:length]; + TestEnumMutableShortEnumSeq* enumSeq2 = [NSMutableData dataWithLength:length]; + @try + { + [proxy opShortSeq:enumSeq1 s2:&enumSeq2]; + test(NO); + } + @catch(ICEMarshalException*) + { + } + } + + { + + TestEnumShortEnum values[] = {TestEnumsenum1, TestEnumsenum2, TestEnumsenum3, TestEnumsenum4, TestEnumsenum5, + (TestEnumShortEnum)0, TestEnumsenum7, TestEnumsenum8, TestEnumsenum9, TestEnumsenum10, + TestEnumsenum11}; // Invalid enumerator + + int length = sizeof(values); + + TestEnumMutableShortEnumSeq* enumSeq1 = [NSMutableData dataWithBytes:values length:length]; + TestEnumMutableShortEnumSeq* enumSeq2 = [NSMutableData dataWithLength:length]; + @try + { + [proxy opShortSeq:enumSeq1 s2:&enumSeq2]; + test(NO); + } + @catch(ICEMarshalException*) + { + } + } + + { + + TestEnumShortEnum values[] = {TestEnumsenum1, TestEnumsenum2, TestEnumsenum3, TestEnumsenum4, TestEnumsenum5, + (TestEnumShortEnum)32767, TestEnumsenum7, TestEnumsenum8, TestEnumsenum9, TestEnumsenum10, + TestEnumsenum11}; // Invalid enumerator + + int length = sizeof(values); + + TestEnumMutableShortEnumSeq* enumSeq1 = [NSMutableData dataWithBytes:values length:length]; + TestEnumMutableShortEnumSeq* enumSeq2 = [NSMutableData dataWithLength:length]; + @try + { + [proxy opShortSeq:enumSeq1 s2:&enumSeq2]; + test(NO); + } + @catch(ICEMarshalException*) + { + } + } + + { + + TestEnumIntEnum values[] = {TestEnumienum1, TestEnumienum2, TestEnumienum3, TestEnumienum4, TestEnumienum5, + (TestEnumIntEnum)-1, TestEnumienum7, TestEnumienum8, TestEnumienum9, TestEnumienum10, + TestEnumienum11}; // Negative enumerators are not supported + + int length = sizeof(values); + + TestEnumMutableShortEnumSeq* enumSeq1 = [NSMutableData dataWithBytes:values length:length]; + TestEnumMutableShortEnumSeq* enumSeq2 = [NSMutableData dataWithLength:length]; + @try + { + [proxy opIntSeq:enumSeq1 i2:&enumSeq2]; + test(NO); + } + @catch(ICEMarshalException*) + { + } + } + + + + tprintf("ok\n"); + + return proxy; +} diff --git a/objective-c/test/Ice/enums/Client.m b/objective-c/test/Ice/enums/Client.m new file mode 100644 index 00000000000..d11c5cac461 --- /dev/null +++ b/objective-c/test/Ice/enums/Client.m @@ -0,0 +1,73 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <TestCommon.h> +#import <EnumTest.h> + +static int +run(id<ICECommunicator> communicator) +{ + TestEnumTestIntfPrx* enumAllTests(id<ICECommunicator>); + TestEnumTestIntfPrx* test = enumAllTests(communicator); + + [test shutdown]; + + return EXIT_SUCCESS; +} + +#if TARGET_OS_IPHONE +# define main enumClient +#endif + +int +main(int argc, char* argv[]) +{ + int status; + @autoreleasepool + { + id<ICECommunicator> communicator = nil; + + @try + { + ICEInitializationData* initData = [ICEInitializationData initializationData]; + initData.properties = defaultClientProperties(&argc, argv); +#if TARGET_OS_IPHONE + initData.prefixTable__ = [NSDictionary dictionaryWithObjectsAndKeys: + @"TestEnum", @"::Test", + nil]; +#endif + communicator = [ICEUtil createCommunicator:&argc argv:argv initData:initData]; + status = run(communicator); + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + @catch(TestFailedException* ex) + { + status = EXIT_FAILURE; + } + + if(communicator) + { + @try + { + [communicator destroy]; + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + } + } + return status; +} diff --git a/objective-c/test/Ice/enums/EnumTest.ice b/objective-c/test/Ice/enums/EnumTest.ice new file mode 100644 index 00000000000..e22e6cd367e --- /dev/null +++ b/objective-c/test/Ice/enums/EnumTest.ice @@ -0,0 +1,98 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#pragma once + +["objc:prefix:TestEnum"] +module Test +{ + +const byte ByteConst1 = 10; +const short ShortConst1 = 20; +const int IntConst1 = 30; +const long LongConst1 = 40; + +const byte ByteConst2 = 126; +const short ShortConst2 = 32766; +const int IntConst2 = 2147483647; +const long LongConst2 = 2147483646; + +enum ByteEnum +{ + benum1, + benum2, + benum3 = ByteConst1, + benum4, + benum5 = ShortConst1, + benum6, + benum7 = IntConst1, + benum8, + benum9 = LongConst1, + benum10, + benum11 = ByteConst2 +}; +sequence<ByteEnum> ByteEnumSeq; + +enum ShortEnum +{ + senum1 = 3, + senum2, + senum3 = ByteConst1, + senum4, + senum5 = ShortConst1, + senum6, + senum7 = IntConst1, + senum8, + senum9 = LongConst1, + senum10, + senum11 = ShortConst2 +}; +sequence<ShortEnum> ShortEnumSeq; + +enum IntEnum +{ + ienum1, + ienum2, + ienum3 = ByteConst1, + ienum4, + ienum5 = ShortConst1, + ienum6, + ienum7 = IntConst1, + ienum8, + ienum9 = LongConst1, + ienum10, + ienum11 = IntConst2, + ienum12 = LongConst2 +}; +sequence<IntEnum> IntEnumSeq; + +enum SimpleEnum +{ + red, + green, + blue +}; +sequence<SimpleEnum> SimpleEnumSeq; + +interface TestIntf +{ + ByteEnum opByte(ByteEnum b1, out ByteEnum b2); + ShortEnum opShort(ShortEnum s1, out ShortEnum s2); + IntEnum opInt(IntEnum i1, out IntEnum i2); + SimpleEnum opSimple(SimpleEnum s1, out SimpleEnum s2); + + ByteEnumSeq opByteSeq(ByteEnumSeq b1, out ByteEnumSeq b2); + ShortEnumSeq opShortSeq(ShortEnumSeq s1, out ShortEnumSeq s2); + IntEnumSeq opIntSeq(IntEnumSeq i1, out IntEnumSeq i2); + SimpleEnumSeq opSimpleSeq(SimpleEnumSeq s1, out SimpleEnumSeq s2); + + void shutdown(); +}; + +}; diff --git a/objective-c/test/Ice/enums/Makefile b/objective-c/test/Ice/enums/Makefile new file mode 100644 index 00000000000..14ab68894c1 --- /dev/null +++ b/objective-c/test/Ice/enums/Makefile @@ -0,0 +1,37 @@ +# ********************************************************************** +# +# Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +# +# This copy of Ice is licensed to you under the terms described in the +# ICE_LICENSE file included in this distribution. +# +# ********************************************************************** + +top_srcdir = ../../.. + +CLIENT = client +SERVER = server + +TARGETS = $(CLIENT) $(SERVER) + +SLICE_OBJS = EnumTest.o + +COBJS = Client.o \ + AllTests.o + +SOBJS = TestI.o \ + Server.o + +OBJS = $(COBJS) $(SOBJS) $(SLICE_OBJS) + +include $(top_srcdir)/config/Make.rules + +CPPFLAGS := -I. -I.. -I../../include $(CPPFLAGS) + +$(CLIENT): $(COBJS) $(SLICE_OBJS) + rm -f $@ + $(CXX) $(LDFLAGS) $(LDEXEFLAGS) -o $@ $(COBJS) $(SLICE_OBJS) $(TEST_LIBS) + +$(SERVER): $(SOBJS) $(SLICE_OBJS) + rm -f $@ + $(CXX) $(LDFLAGS) $(LDEXEFLAGS) -o $@ $(SOBJS) $(SLICE_OBJS) $(TEST_LIBS) diff --git a/objective-c/test/Ice/enums/Server.m b/objective-c/test/Ice/enums/Server.m new file mode 100644 index 00000000000..bb90ed96f70 --- /dev/null +++ b/objective-c/test/Ice/enums/Server.m @@ -0,0 +1,72 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <enums/TestI.h> +#import <TestCommon.h> + +static int +run(id<ICECommunicator> communicator) +{ + [[communicator getProperties] setProperty:@"TestAdapter.Endpoints" value:@"default -p 12010:udp"]; + id<ICEObjectAdapter> adapter = [communicator createObjectAdapter:@"TestAdapter"]; + [adapter add:[TestEnumTestIntfI testIntf] identity:[communicator stringToIdentity:@"test"]]; + [adapter activate]; + + serverReady(communicator); + + [communicator waitForShutdown]; + return EXIT_SUCCESS; +} + +#if TARGET_OS_IPHONE +# define main enumServer +#endif + +int +main(int argc, char* argv[]) +{ + int status; + @autoreleasepool + { + id<ICECommunicator> communicator = nil; + + @try + { + ICEInitializationData* initData = [ICEInitializationData initializationData]; + initData.properties = defaultServerProperties(&argc, argv); +#if TARGET_OS_IPHONE + initData.prefixTable__ = [NSDictionary dictionaryWithObjectsAndKeys: + @"TestEnum", @"::Test", + nil]; +#endif + communicator = [ICEUtil createCommunicator:&argc argv:argv initData:initData]; + status = run(communicator); + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + + if(communicator) + { + @try + { + [communicator destroy]; + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + } + } + return status; +} diff --git a/objective-c/test/Ice/enums/TestI.h b/objective-c/test/Ice/enums/TestI.h new file mode 100644 index 00000000000..880ad26630b --- /dev/null +++ b/objective-c/test/Ice/enums/TestI.h @@ -0,0 +1,15 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <EnumTest.h> + +@interface TestEnumTestIntfI : TestEnumTestIntf<TestEnumTestIntf> +{ +} +@end diff --git a/objective-c/test/Ice/enums/TestI.m b/objective-c/test/Ice/enums/TestI.m new file mode 100644 index 00000000000..6cec06b7c4e --- /dev/null +++ b/objective-c/test/Ice/enums/TestI.m @@ -0,0 +1,69 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <enums/TestI.h> +#import <TestCommon.h> + +@implementation TestEnumTestIntfI + +-(void) shutdown:(ICECurrent*)current +{ + [[[current adapter] getCommunicator] shutdown]; +} + +-(TestEnumByteEnum) opByte:(TestEnumByteEnum)b1 b2:(TestEnumByteEnum*)b2 current:(ICECurrent*)current +{ + *b2 = b1; + return b1; +} + +-(TestEnumShortEnum) opShort:(TestEnumShortEnum)s1 s2:(TestEnumShortEnum*)s2 current:(ICECurrent*)current +{ + *s2 = s1; + return s1; +} + +-(TestEnumIntEnum) opInt:(TestEnumIntEnum)i1 i2:(TestEnumIntEnum*)i2 current:(ICECurrent*)current +{ + *i2 = i1; + return i1; +} + +-(TestEnumSimpleEnum) opSimple:(TestEnumSimpleEnum)s1 s2:(TestEnumSimpleEnum*)s2 current:(ICECurrent*)current +{ + *s2 = s1; + return s1; +} + +-(TestEnumByteEnumSeq*) opByteSeq:(TestEnumByteEnumSeq*)b1 b2:(TestEnumByteEnumSeq**)b2 current:(ICECurrent*)current +{ + *b2 = b1; + return b1; +} + +-(TestEnumShortEnumSeq*) opShortSeq:(TestEnumShortEnumSeq*)s1 s2:(TestEnumShortEnumSeq**)s2 current:(ICECurrent*)current +{ + *s2 = s1; + return s1; +} + +-(TestEnumIntEnumSeq*) opIntSeq:(TestEnumIntEnumSeq*)i1 i2:(TestEnumIntEnumSeq**)i2 current:(ICECurrent*)current +{ + *i2 = i1; + return i1; +} + +-(TestEnumSimpleEnumSeq*) opSimpleSeq:(TestEnumSimpleEnumSeq*)s1 s2:(TestEnumSimpleEnumSeq**)s2 current:(ICECurrent*)current +{ + *s2 = s1; + return s1; +} + +@end diff --git a/objective-c/test/Ice/enums/run.py b/objective-c/test/Ice/enums/run.py new file mode 100755 index 00000000000..ad8767bd99e --- /dev/null +++ b/objective-c/test/Ice/enums/run.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python +# ********************************************************************** +# +# Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +# +# This copy of Ice is licensed to you under the terms described in the +# ICE_LICENSE file included in this distribution. +# +# ********************************************************************** + +import os, sys + +path = [ ".", "..", "../..", "../../..", "../../../..", "../../../../.." ] +head = os.path.dirname(sys.argv[0]) +if len(head) > 0: + path = [os.path.join(head, p) for p in path] +path = [os.path.abspath(p) for p in path if os.path.exists(os.path.join(p, "scripts", "TestUtil.py")) ] +if len(path) == 0: + raise RuntimeError("can't find toplevel directory!") +sys.path.append(os.path.join(path[0], "scripts")) +import TestUtil + +print("Running test with 1.0 encoding.") +TestUtil.clientServerTest(additionalClientOptions="--Ice.Default.EncodingVersion=1.0", + additionalServerOptions="--Ice.Default.EncodingVersion=1.0") + +print("Running test with 1.1 encoding.") +TestUtil.clientServerTest() diff --git a/objective-c/test/Ice/exceptions/.gitignore b/objective-c/test/Ice/exceptions/.gitignore new file mode 100644 index 00000000000..2d0da9fe75b --- /dev/null +++ b/objective-c/test/Ice/exceptions/.gitignore @@ -0,0 +1,9 @@ +// Generated by makegitignore.py + +// IMPORTANT: Do not edit this file -- any edits made here will be lost! +client +server +collocated +.depend +ExceptionsTest.m +ExceptionsTest.h diff --git a/objective-c/test/Ice/exceptions/AllTests.m b/objective-c/test/Ice/exceptions/AllTests.m new file mode 100644 index 00000000000..1d88483961a --- /dev/null +++ b/objective-c/test/Ice/exceptions/AllTests.m @@ -0,0 +1,519 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <TestCommon.h> +#import <ExceptionsTest.h> + +@interface ExceptionsEmptyI : TestExceptionsEmpty<TestExceptionsEmpty> +@end + +@implementation ExceptionsEmptyI +@end + +id<TestExceptionsThrowerPrx> +exceptionsAllTests(id<ICECommunicator> communicator) +{ + tprintf("testing object adapter registration exceptions... "); + { + id<ICEObjectAdapter> first; + @try + { + first = [communicator createObjectAdapter:@"TestAdapter0"]; + test(false); + } + @catch(ICEInitializationException *ex) + { + // Expeccted + } + + [[communicator getProperties] setProperty:@"TestAdapter0.Endpoints" value:@"default"]; + first = [communicator createObjectAdapter:@"TestAdapter0"]; + @try + { + [communicator createObjectAdapter:@"TestAdapter0"]; + test(false); + } + @catch(ICEAlreadyRegisteredException *ex) + { + // Expected + } + + @try + { + } + @catch(ICEAlreadyRegisteredException *ex) + { + // Expected + } + + // + // Properties must remain unaffected if an exception occurs. + // + test([[[communicator getProperties] getProperty:@"TestAdapter0.Endpoints"] isEqualToString:@"default"]); + [first deactivate]; + } + tprintf("ok\n"); + + tprintf("testing servant registration exceptions... "); + { + [[communicator getProperties] setProperty:@"TestAdapter1.Endpoints" value:@"default"]; + id<ICEObjectAdapter> adapter = [communicator createObjectAdapter:@"TestAdapter1"]; + ICEObject* obj = [ExceptionsEmptyI empty]; + [adapter add:obj identity:[communicator stringToIdentity:@"x"]]; + @try + { + [adapter add:obj identity:[communicator stringToIdentity:@"x"]]; + test(false); + } + @catch(ICEAlreadyRegisteredException *ex) + { + } + + [adapter remove:[communicator stringToIdentity:@"x"]]; + @try + { + [adapter remove:[communicator stringToIdentity:@"x"]]; + test(false); + } + @catch(ICENotRegisteredException *ex) + { + } + + [adapter deactivate]; + } + tprintf("ok\n"); + + tprintf("testing stringToProxy... "); + NSString *ref = @"thrower:default -p 12010"; + id<ICEObjectPrx> base = [communicator stringToProxy:ref]; + test(base); + tprintf("ok\n"); + + tprintf("testing checked cast... "); + id<TestExceptionsThrowerPrx> thrower = [TestExceptionsThrowerPrx checkedCast:base]; + test(thrower); + test([thrower isEqual:base]); + tprintf("ok\n"); + + tprintf("catching exact types... "); + + @try + { + [thrower throwAasA:1]; + test(false); + } + @catch(TestExceptionsA *ex) + { + test(ex.aMem == 1); + } + @catch(NSException *ex) + { + test(false); + } + + @try + { + [thrower throwAorDasAorD:1]; + test(false); + } + @catch(TestExceptionsA *ex) + { + test(ex.aMem == 1); + } + @catch(NSException *ex) + { + test(false); + } + + @try + { + [thrower throwAorDasAorD:-1]; + test(false); + } + @catch(TestExceptionsD *ex) + { + test(ex.dMem == -1); + } + @catch(NSException* ex) + { + test(false); + } + + @try + { + [thrower throwBasB:1 b:2]; + test(false); + } + @catch(TestExceptionsB *ex) + { + test(ex.aMem == 1); + test(ex.bMem == 2); + } + @catch(NSException *ex) + { + test(false); + } + + @try + { + [thrower throwCasC:1 b:2 c:3]; + test(false); + } + @catch(TestExceptionsC *ex) + { + test(ex.aMem == 1); + test(ex.bMem == 2); + test(ex.cMem == 3); + } + @catch(NSException *ex) + { + test(false); + } + + @try + { + [thrower throwModA:1 a2:2]; + test(false); + } + @catch(TestExceptionsModA *ex) + { + test(ex.aMem == 1); + test(ex.a2Mem == 2); + } + @catch(ICEOperationNotExistException *ex) + { + // + // This operation is not supported in Java. + // + } + @catch(NSException *ex) + { + test(false); + } + + tprintf("ok\n"); + + tprintf("catching base types... "); + + @try + { + [thrower throwBasB:1 b:2]; + test(false); + } + @catch(TestExceptionsA *ex) + { + test(ex.aMem == 1); + } + @catch(NSException *ex) + { + test(false); + } + + @try + { + [thrower throwCasC:1 b:2 c:3]; + test(false); + } + @catch(TestExceptionsB *ex) + { + test(ex.aMem == 1); + test(ex.bMem == 2); + } + @catch(NSException *ex) + { + test(false); + } + + @try + { + [thrower throwModA:1 a2:2]; + test(false); + } + @catch(TestExceptionsA *ex) + { + test(ex.aMem == 1); + } + @catch(ICEOperationNotExistException *ex) + { + // + // This operation is not supported in Java. + // + } + @catch(NSException *ex) + { + test(false); + } + + tprintf("ok\n"); + + tprintf("catching derived types... "); + + @try + { + [thrower throwBasA:1 b:2]; + test(false); + } + @catch(TestExceptionsB *ex) + { + test(ex.aMem == 1); + test(ex.bMem == 2); + } + @catch(NSException *ex) + { + test(false); + } + + @try + { + [thrower throwCasA:1 b:2 c:3]; + test(false); + } + @catch(TestExceptionsC *ex) + { + test(ex.aMem == 1); + test(ex.bMem == 2); + test(ex.cMem == 3); + } + @catch(NSException *ex) + { + test(false); + } + + @try + { + [thrower throwCasB:1 b:2 c:3]; + test(false); + } + @catch(TestExceptionsC *ex) + { + test(ex.aMem == 1); + test(ex.bMem == 2); + test(ex.cMem == 3); + } + @catch(NSException *ex) + { + test(false); + } + + tprintf("ok\n"); + + if([thrower supportsUndeclaredExceptions]) + { + tprintf("catching unknown user exception... "); + + @try + { + [thrower throwUndeclaredA:1]; + test(false); + } + @catch(ICEUnknownUserException *ex) + { + } + @catch(NSException *ex) + { + test(false); + } + + @try + { + [thrower throwUndeclaredB:1 b:2]; + test(false); + } + @catch(ICEUnknownUserException *ex) + { + } + @catch(NSException *ex) + { + test(false); + } + + @try + { + [thrower throwUndeclaredC:1 b:2 c:3]; + test(false); + } + @catch(ICEUnknownUserException *ex) + { + } + @catch(NSException *ex) + { + test(false); + } + + tprintf("ok\n"); + } + + if([thrower ice_getConnection]) + { + tprintf("testing memory limit marshal exception..."); + @try + { + ICEByteSeq *bs = [NSMutableData dataWithLength:0]; + [thrower throwMemoryLimitException:bs]; + test(false); + } + @catch(ICEMemoryLimitException *ex) + { + } + @catch(NSException *ex) + { + test(false); + } + + @try + { + [thrower throwMemoryLimitException:[NSMutableData dataWithLength:20 * 1024]]; // 20KB + test(false); + } + @catch(ICEConnectionLostException *ex) + { + } + @catch(NSException *ex) + { + test(false); + } + + id<TestExceptionsThrowerPrx> thrower2 = + [TestExceptionsThrowerPrx checkedCast:[communicator stringToProxy:@"thrower:default -p 12011"]]; + @try + { + [thrower2 throwMemoryLimitException:[NSMutableData dataWithLength:20 * 1024 * 1024]]; // 2MB (no limits) + } + @catch(ICEMemoryLimitException *ex) + { + } + id<TestExceptionsThrowerPrx> thrower3 = + [TestExceptionsThrowerPrx checkedCast:[communicator stringToProxy:@"thrower:default -p 12012"]]; + @try + { + [thrower3 throwMemoryLimitException:[NSMutableData dataWithLength:1024]]; // 1KB limit + test(NO); + } + @catch(ICEConnectionLostException *ex) + { + } + + tprintf("ok\n"); + } + + tprintf("catching object not exist exception... "); + + ICEIdentity *id_ = [communicator stringToIdentity:@"does not exist"]; + @try + { + id<TestExceptionsThrowerPrx> thrower2 = [TestExceptionsThrowerPrx uncheckedCast:[thrower ice_identity:id_]]; + [thrower2 throwAasA:1]; +// //[thrower2 ice_ping]; + test(false); + } + @catch(ICEObjectNotExistException *ex) + { + test([ex.id_ isEqual:id_]); + } + @catch(NSException *ex) + { + test(false); + } + + tprintf("ok\n"); + + tprintf("catching facet not exist exception... "); + + @try + { + id<TestExceptionsThrowerPrx> thrower2 = [TestExceptionsThrowerPrx uncheckedCast:thrower facet:@"no such facet"]; + @try + { + [thrower2 ice_ping]; + test(false); + } + @catch(ICEFacetNotExistException *ex) + { + test([ex.facet isEqualToString:@"no such facet"]); + } + } + @catch(NSException *ex) + { + test(false); + } + + tprintf("ok\n"); + + tprintf("catching operation not exist exception... "); + + @try + { + id<TestExceptionsWrongOperationPrx> thrower2 = [TestExceptionsWrongOperationPrx uncheckedCast:thrower]; + [thrower2 noSuchOperation]; + test(false); + } + @catch(ICEOperationNotExistException *ex) + { + test([ex.operation isEqualToString:@"noSuchOperation"]); + } + @catch(NSException *ex) + { + test(false); + } + + tprintf("ok\n"); + + tprintf("catching unknown local exception... "); + + @try + { + [thrower throwLocalException]; + test(false); + } + @catch(ICEUnknownLocalException *ex) + { + } + @catch(NSException *ex) + { + test(false); + } + @try + { + [thrower throwLocalExceptionIdempotent]; + test(false); + } + @catch(ICEUnknownLocalException*) + { + } + @catch(ICEOperationNotExistException*) + { + } + @catch(NSException* ex) + { + test(false); + } + + + tprintf("ok\n"); + + tprintf("catching unknown non-Ice exception... "); + + @try + { + [thrower throwNonIceException]; + test(false); + } + @catch(ICEUnknownException *) + { + } + @catch(NSException *) + { + test(false); + } + + tprintf("ok\n"); + + return thrower; +} diff --git a/objective-c/test/Ice/exceptions/Client.m b/objective-c/test/Ice/exceptions/Client.m new file mode 100644 index 00000000000..d9f710f7a59 --- /dev/null +++ b/objective-c/test/Ice/exceptions/Client.m @@ -0,0 +1,73 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <TestCommon.h> +#import <ExceptionsTest.h> + +static int +run(id<ICECommunicator> communicator) +{ + TestExceptionsThrowerPrx* exceptionsAllTests(id<ICECommunicator>); + TestExceptionsThrowerPrx* thrower = exceptionsAllTests(communicator); + [thrower shutdown]; + return EXIT_SUCCESS; +} + +#if TARGET_OS_IPHONE +# define main exceptionsClient +#endif + +int +main(int argc, char* argv[]) +{ + int status; + @autoreleasepool + { + id<ICECommunicator> communicator = nil; + @try + { + ICEInitializationData* initData = [ICEInitializationData initializationData]; + initData.properties = defaultClientProperties(&argc, argv); + [initData.properties setProperty:@"Ice.MessageSizeMax" value:@"10"]; // 10KB max + [initData.properties setProperty:@"Ice.Warn.Connections" value:@"0"]; +#if TARGET_OS_IPHONE + initData.prefixTable__ = [NSDictionary dictionaryWithObjectsAndKeys: + @"TestExceptions", @"::Test", + @"TestExceptionsMod", @"::Test::Mod", + nil]; +#endif + communicator = [ICEUtil createCommunicator:&argc argv:argv initData:initData]; + status = run(communicator); + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + @catch(TestFailedException* ex) + { + status = EXIT_FAILURE; + } + + if(communicator) + { + @try + { + [communicator destroy]; + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + } + } + return status; +} diff --git a/objective-c/test/Ice/exceptions/Collocated.m b/objective-c/test/Ice/exceptions/Collocated.m new file mode 100644 index 00000000000..9b0f5e0ed20 --- /dev/null +++ b/objective-c/test/Ice/exceptions/Collocated.m @@ -0,0 +1,78 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <exceptions/TestI.h> +#import <TestCommon.h> + +static int +run(id<ICECommunicator> communicator) +{ + [[communicator getProperties] setProperty:@"TestAdapter.Endpoints" value:@"default -p 12010"]; + id<ICEObjectAdapter> adapter = [communicator createObjectAdapter:@"TestAdapter"]; + ICEObject* object = [ThrowerI thrower]; + [adapter add:object identity:[communicator stringToIdentity:@"thrower"]]; + + TestExceptionsThrowerPrx* exceptionsAllTests(id<ICECommunicator>); + exceptionsAllTests(communicator); + + return EXIT_SUCCESS; +} + +#if TARGET_OS_IPHONE +# define main exceptionsServer +#endif + +int +main(int argc, char* argv[]) +{ + int status; + @autoreleasepool + { + id<ICECommunicator> communicator = nil; + + @try + { + ICEInitializationData* initData = [ICEInitializationData initializationData]; + initData.properties = defaultServerProperties(&argc, argv); + [initData.properties setProperty:@"Ice.MessageSizeMax" value:@"10"]; // 10KB max + [initData.properties setProperty:@"Ice.Warn.Dispatch" value:@"0"]; + [initData.properties setProperty:@"Ice.Warn.Connections" value:@"0"]; + +#if TARGET_OS_IPHONE + initData.prefixTable__ = [NSDictionary dictionaryWithObjectsAndKeys: + @"TestExceptions", @"::Test", + @"TestExceptionsMod", @"::Test::Mod", + nil]; +#endif + + communicator = [ICEUtil createCommunicator:&argc argv:argv initData:initData]; + status = run(communicator); + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + + if(communicator) + { + @try + { + [communicator destroy]; + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + } + } + return status; +} diff --git a/objective-c/test/Ice/exceptions/ExceptionsTest.ice b/objective-c/test/Ice/exceptions/ExceptionsTest.ice new file mode 100644 index 00000000000..7cdc47b8bcf --- /dev/null +++ b/objective-c/test/Ice/exceptions/ExceptionsTest.ice @@ -0,0 +1,88 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#pragma once + +#include <Ice/BuiltinSequences.ice> + +["objc:prefix:TestExceptions"] +module Test +{ + +interface Empty +{ +}; + +interface Thrower; + +exception A +{ + int aMem; +}; + +exception B extends A +{ + int bMem; +}; + +exception C extends B +{ + int cMem; +}; + +exception D +{ + int dMem; +}; + +["objc:prefix:TestExceptionsMod"] +module Mod +{ + exception A extends ::Test::A + { + int a2Mem; + }; +}; + + +interface Thrower +{ + void shutdown(); + bool supportsUndeclaredExceptions(); + bool supportsAssertException(); + + void throwAasA(int a) throws A; + void throwAorDasAorD(int a) throws A, D; + void throwBasA(int a, int b) throws A; + void throwCasA(int a, int b, int c) throws A; + void throwBasB(int a, int b) throws B; + void throwCasB(int a, int b, int c) throws B; + void throwCasC(int a, int b, int c) throws C; + + void throwModA(int a, int a2) throws Mod::A; + + void throwUndeclaredA(int a); + void throwUndeclaredB(int a, int b); + void throwUndeclaredC(int a, int b, int c); + void throwLocalException(); + void throwNonIceException(); + void throwAssertException(); + Ice::ByteSeq throwMemoryLimitException(Ice::ByteSeq seq); + idempotent void throwLocalExceptionIdempotent(); + + void throwAfterResponse(); + void throwAfterException() throws A; +}; + +interface WrongOperation +{ + void noSuchOperation(); +}; + +}; diff --git a/objective-c/test/Ice/exceptions/Makefile b/objective-c/test/Ice/exceptions/Makefile new file mode 100644 index 00000000000..55f32b2a5c2 --- /dev/null +++ b/objective-c/test/Ice/exceptions/Makefile @@ -0,0 +1,46 @@ +# ********************************************************************** +# +# Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +# +# This copy of Ice is licensed to you under the terms described in the +# ICE_LICENSE file included in this distribution. +# +# ********************************************************************** + +top_srcdir = ../../.. + +CLIENT = client +SERVER = server +COLLOCATED = collocated + +TARGETS = $(CLIENT) $(SERVER) $(COLLOCATED) + +SLICE_OBJS = ExceptionsTest.o + +COBJS = Client.o \ + AllTests.o + +SOBJS = TestI.o \ + Server.o + +COLOBJS = Collocated.o \ + TestI.o \ + AllTests.o + +OBJS = $(COBJS) $(SOBJS) $(COLOBJS) $(SLICE_OBJS) + +include $(top_srcdir)/config/Make.rules + +CPPFLAGS := -I. -I.. -I../../include $(CPPFLAGS) + +$(CLIENT): $(COBJS) $(SLICE_OBJS) + rm -f $@ + $(CXX) $(LDFLAGS) $(LDEXEFLAGS) -o $@ $(COBJS) $(SLICE_OBJS) $(TEST_LIBS) + +$(SERVER): $(SOBJS) $(SLICE_OBJS) + rm -f $@ + $(CXX) $(LDFLAGS) $(LDEXEFLAGS) -o $@ $(SOBJS) $(SLICE_OBJS) $(TEST_LIBS) + +$(COLLOCATED): $(COLOBJS) $(SLICE_OBJS) + rm -f $@ + $(CXX) $(LDFLAGS) $(LDEXEFLAGS) -o $@ $(COLOBJS) $(SLICE_OBJS) $(TEST_LIBS) diff --git a/objective-c/test/Ice/exceptions/Server.m b/objective-c/test/Ice/exceptions/Server.m new file mode 100644 index 00000000000..59bf900786d --- /dev/null +++ b/objective-c/test/Ice/exceptions/Server.m @@ -0,0 +1,90 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <exceptions/TestI.h> +#import <TestCommon.h> + +static int +run(id<ICECommunicator> communicator) +{ + [[communicator getProperties] setProperty:@"Ice.Warn.Dispatch" value:@"0"]; + [[communicator getProperties] setProperty:@"TestAdapter.Endpoints" value:@"default -p 12010:udp"]; + [[communicator getProperties] setProperty:@"TestAdapter2.Endpoints" value:@"default -p 12011"]; + [[communicator getProperties] setProperty:@"TestAdapter2.MessageSizeMax" value:@"0"]; + [[communicator getProperties] setProperty:@"TestAdapter3.Endpoints" value:@"default -p 12012"]; + [[communicator getProperties] setProperty:@"TestAdapter3.MessageSizeMax" value:@"1"]; + id<ICEObjectAdapter> adapter = [communicator createObjectAdapter:@"TestAdapter"]; + id<ICEObjectAdapter> adapter2 = [communicator createObjectAdapter:@"TestAdapter2"]; + id<ICEObjectAdapter> adapter3 = [communicator createObjectAdapter:@"TestAdapter3"]; + ICEObject* object = [ThrowerI thrower]; + [adapter add:object identity:[communicator stringToIdentity:@"thrower"]]; + [adapter2 add:object identity:[communicator stringToIdentity:@"thrower"]]; + [adapter3 add:object identity:[communicator stringToIdentity:@"thrower"]]; + [adapter activate]; + [adapter2 activate]; + [adapter3 activate]; + + serverReady(communicator); + + [communicator waitForShutdown]; + return EXIT_SUCCESS; +} + +#if TARGET_OS_IPHONE +# define main exceptionsServer +#endif + +int +main(int argc, char* argv[]) +{ + int status; + @autoreleasepool + { + id<ICECommunicator> communicator = nil; + + @try + { + ICEInitializationData* initData = [ICEInitializationData initializationData]; + initData.properties = defaultServerProperties(&argc, argv); + [initData.properties setProperty:@"Ice.MessageSizeMax" value:@"10"]; // 10KB max + [initData.properties setProperty:@"Ice.Warn.Dispatch" value:@"0"]; + [initData.properties setProperty:@"Ice.Warn.Connections" value:@"0"]; + +#if TARGET_OS_IPHONE + initData.prefixTable__ = [NSDictionary dictionaryWithObjectsAndKeys: + @"TestExceptions", @"::Test", + @"TestExceptionsMod", @"::Test::Mod", + nil]; +#endif + + communicator = [ICEUtil createCommunicator:&argc argv:argv initData:initData]; + status = run(communicator); + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + + if(communicator) + { + @try + { + [communicator destroy]; + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + } + } + return status; +} diff --git a/objective-c/test/Ice/exceptions/TestI.h b/objective-c/test/Ice/exceptions/TestI.h new file mode 100644 index 00000000000..902d695dafe --- /dev/null +++ b/objective-c/test/Ice/exceptions/TestI.h @@ -0,0 +1,16 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <ExceptionsTest.h> + +@interface ThrowerI : TestExceptionsThrower<TestExceptionsThrower> +{ +} + +@end diff --git a/objective-c/test/Ice/exceptions/TestI.m b/objective-c/test/Ice/exceptions/TestI.m new file mode 100644 index 00000000000..14730261070 --- /dev/null +++ b/objective-c/test/Ice/exceptions/TestI.m @@ -0,0 +1,149 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> + +#import <exceptions/TestI.h> +#import <TestCommon.h> +#import <Foundation/NSException.h> + +@interface FooException : NSException +@end + +@implementation FooException +-(id)init +{ + self = [super initWithName:@"FooException" reason:@"no reason" userInfo:nil]; + if(!self) + { + return nil; + } + return self; +} +@end + +@implementation ThrowerI + +-(void) shutdown:(ICECurrent*)current +{ + [[current.adapter getCommunicator] shutdown]; +} + +-(BOOL) supportsUndeclaredExceptions:(ICECurrent*)current +{ + return YES; +} + +-(BOOL) supportsAssertException:(ICECurrent*)current +{ + return NO; +} + +-(void) throwAasA:(ICEInt)a current:(ICECurrent*)current +{ + @throw [TestExceptionsA a:a]; +} + +-(void) throwAorDasAorD:(ICEInt)a current:(ICECurrent*)current +{ + if(a > 0) + { + @throw [TestExceptionsA a:a]; + } + else + { + @throw [TestExceptionsD d:a]; + } +} + +-(void) throwBasA:(ICEInt)a b:(ICEInt)b current:(ICECurrent*)current +{ + [self throwBasB:a b:b current:current]; +} + +-(void) throwCasA:(ICEInt)a b:(ICEInt)b c:(ICEInt) c current:(ICECurrent*)current +{ + [self throwCasC:a b:b c:c current:current]; +} + +-(void) throwBasB:(ICEInt)a b:(ICEInt)b current:(ICECurrent*)current +{ + @throw [TestExceptionsB b:a bMem:b]; +} + +-(void) throwCasB:(ICEInt)a b:(ICEInt)b c:(ICEInt)c current:(ICECurrent*)current +{ + [self throwCasC:a b:b c:c current:current]; +} + +-(void) throwCasC:(ICEInt)a b:(ICEInt)b c:(ICEInt)c current:(ICECurrent*)current +{ + @throw [TestExceptionsC c:a bMem:b cMem:c]; +} + +-(void) throwModA:(ICEInt)a a2:(ICEInt)a2 current:(ICECurrent*)current +{ + @throw [TestExceptionsModA a:a a2Mem:a2]; +} + +-(void) throwUndeclaredA:(ICEInt)a current:(ICECurrent*)current +{ + @throw [TestExceptionsA a:a]; +} + +-(void) throwUndeclaredB:(ICEInt)a b:(ICEInt)b current:(ICECurrent*)current +{ + @throw [TestExceptionsB b:a bMem:b]; +} + +-(void) throwUndeclaredC:(ICEInt)a b:(ICEInt)b c:(ICEInt)c current:(ICECurrent*)current +{ + @throw [TestExceptionsC c:a bMem:b cMem:c]; +} + +-(void) throwLocalException:(ICECurrent*)current +{ + @throw [ICETimeoutException timeoutException:__FILE__ line:__LINE__]; +} + +-(ICEByteSeq*) throwMemoryLimitException:(ICEMutableByteSeq*)bs current:(ICECurrent*)current +{ + int limit = 20 * 1024; + ICEMutableByteSeq *r = [NSMutableData dataWithLength:limit]; + ICEByte *p = (ICEByte *)[r bytes]; + while(--limit > 0) + { + *p++ = limit % 0x80; + } + return r; +} + +-(void) throwNonIceException:(ICECurrent*)current +{ + @throw ICE_AUTORELEASE([[FooException alloc] init]); +} + +-(void) throwAssertException:(ICECurrent*)current +{ + // Not supported. +} + +-(void) throwLocalExceptionIdempotent:(ICECurrent*)current +{ + @throw [ICETimeoutException timeoutException:__FILE__ line:__LINE__]; +} +-(void) throwAfterResponse:(ICECurrent*)current +{ + // Only relevant for AMD +} +-(void) throwAfterException:(ICECurrent*)current +{ + // Only relevant for AMD +} +@end diff --git a/objective-c/test/Ice/exceptions/run.py b/objective-c/test/Ice/exceptions/run.py new file mode 100755 index 00000000000..6014ec1878d --- /dev/null +++ b/objective-c/test/Ice/exceptions/run.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python +# ********************************************************************** +# +# Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +# +# This copy of Ice is licensed to you under the terms described in the +# ICE_LICENSE file included in this distribution. +# +# ********************************************************************** + +import os, sys + +path = [ ".", "..", "../..", "../../..", "../../../..", "../../../../.." ] +head = os.path.dirname(sys.argv[0]) +if len(head) > 0: + path = [os.path.join(head, p) for p in path] +path = [os.path.abspath(p) for p in path if os.path.exists(os.path.join(p, "scripts", "TestUtil.py")) ] +if len(path) == 0: + raise RuntimeError("can't find toplevel directory!") +sys.path.append(os.path.join(path[0], "scripts")) +import TestUtil + +print("Running test with compact (default) format.") +TestUtil.clientServerTest() + +print("Running test with sliced format.") +TestUtil.clientServerTest(additionalClientOptions="--Ice.Default.SlicedFormat", + additionalServerOptions="--Ice.Default.SlicedFormat") + +print("Running test with 1.0 encoding.") +TestUtil.clientServerTest(additionalClientOptions="--Ice.Default.EncodingVersion=1.0", + additionalServerOptions="--Ice.Default.EncodingVersion=1.0") + +print("Running collocated test.") +TestUtil.collocatedTest() diff --git a/objective-c/test/Ice/facets/.gitignore b/objective-c/test/Ice/facets/.gitignore new file mode 100644 index 00000000000..461935cd9dd --- /dev/null +++ b/objective-c/test/Ice/facets/.gitignore @@ -0,0 +1,9 @@ +// Generated by makegitignore.py + +// IMPORTANT: Do not edit this file -- any edits made here will be lost! +client +server +collocated +.depend +FacetsTest.m +FacetsTest.h diff --git a/objective-c/test/Ice/facets/AllTests.m b/objective-c/test/Ice/facets/AllTests.m new file mode 100644 index 00000000000..97d4e366003 --- /dev/null +++ b/objective-c/test/Ice/facets/AllTests.m @@ -0,0 +1,186 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <TestCommon.h> +#import <FacetsTest.h> + + +@interface FacetsEmptyI : TestFacetsEmpty +@end + +@implementation FacetsEmptyI +@end + +id<TestFacetsGPrx> +facetsAllTests(id<ICECommunicator> communicator) +{ +// tprintf("testing Ice.Admin.Facets property... "); +// test([[[communicator getProperties] getPropertyAsList:@"Ice.Admin.Facets"] length] > 0); +// [[communicator getProperties] setProperty:@"Ice.Admin.Facets" value:@"foobar"]; +// ICEStringSeq facetFilter = [[communicator getProperties] getPropertyAsList:@"Ice.Admin.Facets"]; +// test([[facetFilter count] == 1 && [facetFilter objectAtIndex:0] isEqualToString:@"foobar"]); +// [[communicator getProperties] setProperty:@"Ice.Admin.Facets" value:@"foo'bar"]; +// facetFilter = [[communicator getProperties] getPropertyAsList:@"Ice.Admin.Facets"]; +// test([[facetFilter count] == 1 && [facetFilter objectAtIndex:0] isEqualToString:@"foo'bar"]); +// [[communicator getProperties] setProperty:@"Ice.Admin.Facets" value:@"'foo bar' toto 'titi'"]; +// facetFilter = [[communicator getProperties] getPropertyAsList:@"Ice.Admin.Facets"]; +// test([[facetFilter count] == 3 && [facetFilter objectAtIndex:0] isEqualToString:@"foo bar" && [facetFilter objectAtIndex:1]:isEqualToString:@"toto" && [facetFilter objectAtIndex:2]:isEqualToString:@"titi"]); +// [[communicator getProperties] setProperty:@"Ice.Admin.Facets" value:@"'foo bar\\' toto' 'titi'"]; +// facetFilter = [[communicator getProperties] getPropertyAsList:@"Ice.Admin.Facets"]; +// test([[facetFilter count] == 2 && [facetFilter objectAtIndex:0] isEqualToString:@"foo bar' toto" && [facetFilter objectAtIndex:1]:isEqualToString:@"titi"]); +// // [[communicator getProperties] setProperty:@"Ice.Admin.Facets" value:@"'foo bar' 'toto titi"]; +// // facetFilter = [[communicator getProperties] getPropertyAsList:@"Ice.Admin.Facets"]; +// // test([facetFilter count] == 0); +// [[communicator getProperties] setProperty:@"Ice.Admin.Facets" value:@""]; +// tprintf("ok\n"); + + tprintf("testing facet registration exceptions... "); + [[communicator getProperties] setProperty:@"FacetExceptionTestAdapter.Endpoints" value:@"default"]; + id<ICEObjectAdapter> adapter = [communicator createObjectAdapter:@"FacetExceptionTestAdapter"]; + ICEObject* obj = [FacetsEmptyI empty]; + [adapter add:obj identity:[communicator stringToIdentity:@"d"]]; + [adapter addFacet:obj identity:[communicator stringToIdentity:@"d"] facet:@"facetABCD"]; + @try + { + [adapter addFacet:obj identity:[communicator stringToIdentity:@"d"] facet:@"facetABCD"]; + test(NO); + } + @catch(ICEAlreadyRegisteredException*) + { + } + [adapter removeFacet:[communicator stringToIdentity:@"d"] facet:@"facetABCD"]; + @try + { + [adapter removeFacet:[communicator stringToIdentity:@"d"] facet:@"facetABCD"]; + test(NO); + } + @catch(ICENotRegisteredException*) + { + } + tprintf("ok\n"); + + tprintf("testing removeAllFacets... "); + ICEObject* obj1 = [FacetsEmptyI empty]; + ICEObject* obj2 = [FacetsEmptyI empty]; + + [adapter addFacet:obj1 identity:[communicator stringToIdentity:@"id1"] facet:@"f1"]; + [adapter addFacet:obj2 identity:[communicator stringToIdentity:@"id1"] facet:@"f2"]; + + ICEObject* obj3 = [FacetsEmptyI empty]; + + [adapter addFacet:obj1 identity:[communicator stringToIdentity:@"id2"] facet:@"f1"]; + [adapter addFacet:obj2 identity:[communicator stringToIdentity:@"id2"] facet:@"f2"]; + [adapter addFacet:obj3 identity:[communicator stringToIdentity:@"id2"] facet:@""]; + NSDictionary* fm = [adapter removeAllFacets:[communicator stringToIdentity:@"id1"]]; + test([fm count] == 2); + test([fm objectForKey:@"f1"] == obj1); + test([fm objectForKey:@"f2"] == obj2); + @try + { + [adapter removeAllFacets:[communicator stringToIdentity:@"id1"]]; + test(NO); + } + @catch(ICENotRegisteredException*) + { + } + fm = [adapter removeAllFacets:[communicator stringToIdentity:@"id2"]]; + test([fm count] == 3); + test([fm objectForKey:@"f1"] == obj1); + test([fm objectForKey:@"f2"] == obj2); + test([fm objectForKey:@""] == obj3); + tprintf("ok\n"); + + [adapter deactivate]; + + tprintf("testing stringToProxy... "); + NSString* ref = @"d:default -p 12010"; + id<ICEObjectPrx> db = [communicator stringToProxy:ref]; + test(db); + tprintf("ok\n"); + + tprintf("testing unchecked cast... "); + id<ICEObjectPrx> prx = [ICEObjectPrx uncheckedCast:db]; + test([[prx ice_getFacet] length] == 0); + prx = [ICEObjectPrx uncheckedCast:db facet:@"facetABCD"]; + test([[prx ice_getFacet] isEqualToString:@"facetABCD"]); + id<ICEObjectPrx> prx2 = [ICEObjectPrx uncheckedCast:prx]; + test([[prx2 ice_getFacet] isEqualToString:@"facetABCD"]); + id<ICEObjectPrx> prx3 = [ICEObjectPrx uncheckedCast:prx facet:@""]; + test([[prx3 ice_getFacet] length] == 0); + id<TestFacetsDPrx> d = [TestFacetsDPrx uncheckedCast:db]; + test([[d ice_getFacet] length] == 0); + id<TestFacetsDPrx> df = [TestFacetsDPrx uncheckedCast:db facet:@"facetABCD"]; + test([[df ice_getFacet] isEqualToString:@"facetABCD"]); + id<TestFacetsDPrx> df2 = [TestFacetsDPrx uncheckedCast:df]; + test([[df2 ice_getFacet] isEqualToString:@"facetABCD"]); + id<TestFacetsDPrx> df3 = [TestFacetsDPrx uncheckedCast:df facet:@""]; + test([[df3 ice_getFacet] length] == 0); + tprintf("ok\n"); + + tprintf("testing checked cast... "); + prx = [ICEObjectPrx checkedCast:db]; + test([[prx ice_getFacet] length] == 0); + prx = [ICEObjectPrx checkedCast:db facet:@"facetABCD"]; + test([[prx ice_getFacet] isEqualToString:@"facetABCD"]); + prx2 = [ICEObjectPrx checkedCast:prx]; + test([[prx2 ice_getFacet] isEqualToString:@"facetABCD"]); + prx3 = [ICEObjectPrx checkedCast:prx facet:@""]; + test([[prx3 ice_getFacet] length] == 0); + d = [TestFacetsDPrx checkedCast:db]; + test([[d ice_getFacet] length] == 0); + df = [TestFacetsDPrx checkedCast:db facet:@"facetABCD"]; + test([[df ice_getFacet] isEqualToString:@"facetABCD"]); + df2 = [TestFacetsDPrx checkedCast:df]; + test([[df2 ice_getFacet] isEqualToString:@"facetABCD"]); + df3 = [TestFacetsDPrx checkedCast:df facet:@""]; + test([[df3 ice_getFacet] length] == 0); + tprintf("ok\n"); + + tprintf("testing non-facets A, B, C, and D... "); + d = [TestFacetsDPrx checkedCast:db]; + test(d); + test([d isEqual:db]); + test([[d callA] isEqualToString:@"A"]); + test([[d callB] isEqualToString:@"B"]); + test([[d callC] isEqualToString:@"C"]); + test([[d callD] isEqualToString:@"D"]); + tprintf("ok\n"); + + tprintf("testing facets A, B, C, and D... "); + df = [TestFacetsDPrx checkedCast:d facet:@"facetABCD"]; + test(df); + test([[df callA] isEqualToString:@"A"]); + test([[df callB] isEqualToString:@"B"]); + test([[df callC] isEqualToString:@"C"]); + test([[df callD] isEqualToString:@"D"]); + tprintf("ok\n"); + + tprintf("testing facets E and F... "); + id<TestFacetsFPrx> ff = [TestFacetsFPrx checkedCast:d facet:@"facetEF"]; + test(ff); + test([[ff callE] isEqualToString:@"E"]); + test([[ff callF] isEqualToString:@"F"]); + tprintf("ok\n"); + + tprintf("testing facet G... "); + id<TestFacetsGPrx> gf = [TestFacetsGPrx checkedCast:ff facet:@"facetGH"]; + test(gf); + test([[gf callG] isEqualToString:@"G"]); + tprintf("ok\n"); + + tprintf("testing whether casting preserves the facet... "); + id<TestFacetsHPrx> hf = [TestFacetsHPrx checkedCast:gf]; + test(hf); + test([[hf callG] isEqualToString:@"G"]); + test([[hf callH] isEqualToString:@"H"]); + tprintf("ok\n"); + + return gf; +} diff --git a/objective-c/test/Ice/facets/Client.m b/objective-c/test/Ice/facets/Client.m new file mode 100644 index 00000000000..715e578fcc5 --- /dev/null +++ b/objective-c/test/Ice/facets/Client.m @@ -0,0 +1,71 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <TestCommon.h> +#import <FacetsTest.h> + +static int +run(id<ICECommunicator> communicator) +{ + id<TestFacetsGPrx> facetsAllTests(id<ICECommunicator>); + id<TestFacetsGPrx> g = facetsAllTests(communicator); + [g shutdown]; + return EXIT_SUCCESS; +} + +#if TARGET_OS_IPHONE +# define main facetsClient +#endif + +int +main(int argc, char* argv[]) +{ + int status; + @autoreleasepool + { + id<ICECommunicator> communicator = nil; + + @try + { + ICEInitializationData* initData = [ICEInitializationData initializationData]; + initData.properties = defaultClientProperties(&argc, argv); +#if TARGET_OS_IPHONE + initData.prefixTable__ = [NSDictionary dictionaryWithObjectsAndKeys: + @"TestFacets", @"::Test", + nil]; +#endif + communicator = [ICEUtil createCommunicator:&argc argv:argv initData:initData]; + status = run(communicator); + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + @catch(TestFailedException* ex) + { + status = EXIT_FAILURE; + } + + if(communicator) + { + @try + { + [communicator destroy]; + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + } + } + return status; +} diff --git a/objective-c/test/Ice/facets/Collocated.m b/objective-c/test/Ice/facets/Collocated.m new file mode 100644 index 00000000000..99227d99e5a --- /dev/null +++ b/objective-c/test/Ice/facets/Collocated.m @@ -0,0 +1,76 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <facets/TestI.h> +#import <TestCommon.h> + +static int +run(id<ICECommunicator> communicator) +{ + [[communicator getProperties] setProperty:@"TestAdapter.Endpoints" value:@"default -p 12010"]; + id<ICEObjectAdapter> adapter = [communicator createObjectAdapter:@"TestAdapter"]; + ICEObject* d = [TestFacetsDI d]; + ICEObject* f = [TestFacetsFI f]; + ICEObject* h = [TestFacetsHI h]; + [adapter add:d identity:[communicator stringToIdentity:@"d"]]; + [adapter addFacet:d identity:[communicator stringToIdentity:@"d"] facet:@"facetABCD"]; + [adapter addFacet:f identity:[communicator stringToIdentity:@"d"] facet:@"facetEF"]; + [adapter addFacet:h identity:[communicator stringToIdentity:@"d"] facet:@"facetGH"]; + + id<TestFacetsGPrx> facetsAllTests(id<ICECommunicator>); + facetsAllTests(communicator); + + return EXIT_SUCCESS; +} + +#if TARGET_OS_IPHONE +# define main facetsServer +#endif + +int +main(int argc, char* argv[]) +{ + int status; + @autoreleasepool + { + id<ICECommunicator> communicator = nil; + @try + { + ICEInitializationData* initData = [ICEInitializationData initializationData]; + initData.properties = defaultServerProperties(&argc, argv); +#if TARGET_OS_IPHONE + initData.prefixTable__ = [NSDictionary dictionaryWithObjectsAndKeys: + @"TestFacets", @"::Test", + nil]; +#endif + communicator = [ICEUtil createCommunicator:&argc argv:argv initData:initData]; + status = run(communicator); + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + + if(communicator) + { + @try + { + [communicator destroy]; + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + } + } + return status; +} diff --git a/objective-c/test/Ice/facets/FacetsTest.ice b/objective-c/test/Ice/facets/FacetsTest.ice new file mode 100644 index 00000000000..216108d235c --- /dev/null +++ b/objective-c/test/Ice/facets/FacetsTest.ice @@ -0,0 +1,61 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#pragma once + +["objc:prefix:TestFacets"] +module Test +{ + +interface Empty +{ +}; + +interface A +{ + string callA(); +}; + +interface B extends A +{ + string callB(); +}; + +interface C extends A +{ + string callC(); +}; + +interface D extends B, C +{ + string callD(); +}; + +interface E +{ + string callE(); +}; + +interface F extends E +{ + string callF(); +}; + +interface G +{ + void shutdown(); + string callG(); +}; + +interface H extends G +{ + string callH(); +}; + +}; diff --git a/objective-c/test/Ice/facets/Makefile b/objective-c/test/Ice/facets/Makefile new file mode 100644 index 00000000000..1ed32b66172 --- /dev/null +++ b/objective-c/test/Ice/facets/Makefile @@ -0,0 +1,46 @@ +# ********************************************************************** +# +# Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +# +# This copy of Ice is licensed to you under the terms described in the +# ICE_LICENSE file included in this distribution. +# +# ********************************************************************** + +top_srcdir = ../../.. + +CLIENT = client +SERVER = server +COLLOCATED = collocated + +TARGETS = $(CLIENT) $(SERVER) $(COLLOCATED) + +SLICE_OBJS = FacetsTest.o + +COBJS = Client.o \ + AllTests.o + +SOBJS = TestI.o \ + Server.o + +COLOBJS = Collocated.o \ + TestI.o \ + AllTests.o + +OBJS = $(COBJS) $(SOBJS) $(COLOBJS) $(SLICE_OBJS) + +include $(top_srcdir)/config/Make.rules + +CPPFLAGS := -I. -I.. -I../../include $(CPPFLAGS) + +$(CLIENT): $(COBJS) $(SLICE_OBJS) + rm -f $@ + $(CXX) $(LDFLAGS) $(LDEXEFLAGS) -o $@ $(COBJS) $(SLICE_OBJS) $(TEST_LIBS) + +$(SERVER): $(SOBJS) $(SLICE_OBJS) + rm -f $@ + $(CXX) $(LDFLAGS) $(LDEXEFLAGS) -o $@ $(SOBJS) $(SLICE_OBJS) $(TEST_LIBS) + +$(COLLOCATED): $(COLOBJS) $(SLICE_OBJS) + rm -f $@ + $(CXX) $(LDFLAGS) $(LDEXEFLAGS) -o $@ $(COLOBJS) $(SLICE_OBJS) $(TEST_LIBS) diff --git a/objective-c/test/Ice/facets/Server.m b/objective-c/test/Ice/facets/Server.m new file mode 100644 index 00000000000..257a70be27d --- /dev/null +++ b/objective-c/test/Ice/facets/Server.m @@ -0,0 +1,79 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <facets/TestI.h> +#import <TestCommon.h> + +static int +run(id<ICECommunicator> communicator) +{ + [[communicator getProperties] setProperty:@"TestAdapter.Endpoints" value:@"default -p 12010"]; + id<ICEObjectAdapter> adapter = [communicator createObjectAdapter:@"TestAdapter"]; + ICEObject* d = [TestFacetsDI d]; + ICEObject* f = [TestFacetsFI f]; + ICEObject* h = [TestFacetsHI h]; + [adapter add:d identity:[communicator stringToIdentity:@"d"]]; + [adapter addFacet:d identity:[communicator stringToIdentity:@"d"] facet:@"facetABCD"]; + [adapter addFacet:f identity:[communicator stringToIdentity:@"d"] facet:@"facetEF"]; + [adapter addFacet:h identity:[communicator stringToIdentity:@"d"] facet:@"facetGH"]; + + [adapter activate]; + + serverReady(communicator); + + [communicator waitForShutdown]; + + return EXIT_SUCCESS; +} + +#if TARGET_OS_IPHONE +# define main facetsServer +#endif + +int +main(int argc, char* argv[]) +{ + int status; + @autoreleasepool + { + id<ICECommunicator> communicator = nil; + @try + { + ICEInitializationData* initData = [ICEInitializationData initializationData]; + initData.properties = defaultServerProperties(&argc, argv); +#if TARGET_OS_IPHONE + initData.prefixTable__ = [NSDictionary dictionaryWithObjectsAndKeys: + @"TestFacets", @"::Test", + nil]; +#endif + communicator = [ICEUtil createCommunicator:&argc argv:argv initData:initData]; + status = run(communicator); + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + + if(communicator) + { + @try + { + [communicator destroy]; + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + } + } + return status; +} diff --git a/objective-c/test/Ice/facets/TestI.h b/objective-c/test/Ice/facets/TestI.h new file mode 100644 index 00000000000..f0a7d73a5c6 --- /dev/null +++ b/objective-c/test/Ice/facets/TestI.h @@ -0,0 +1,40 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <FacetsTest.h> + +@interface TestFacetsAI : TestFacetsA<TestFacetsA> +@end + +@interface TestFacetsBI : TestFacetsB<TestFacetsB> +@end + +@interface TestFacetsCI : TestFacetsC<TestFacetsC> +@end + +@interface TestFacetsDI : TestFacetsD<TestFacetsD> +@end + +@interface TestFacetsEI : TestFacetsE<TestFacetsE> +@end + +@interface TestFacetsFI : TestFacetsF<TestFacetsF> +@end + +@interface TestFacetsGI : TestFacetsG<TestFacetsG> +{ + id<ICECommunicator> communicator_; +} +-(void) shutdown:(ICECurrent*)current; +-(NSString*) callG:(ICECurrent*)current; +@end + +@interface TestFacetsHI : TestFacetsH<TestFacetsH> +-(NSString*) callH:(ICECurrent*)current; +@end diff --git a/objective-c/test/Ice/facets/TestI.m b/objective-c/test/Ice/facets/TestI.m new file mode 100644 index 00000000000..d46d0518725 --- /dev/null +++ b/objective-c/test/Ice/facets/TestI.m @@ -0,0 +1,103 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <facets/TestI.h> + +@implementation TestFacetsAI +-(NSString*) callA:(ICECurrent*)current +{ + return @"A"; +} +@end + +@implementation TestFacetsBI +-(NSString*) callA:(ICECurrent*)current +{ + return @"A"; +} +-(NSString*) callB:(ICECurrent*)current +{ + return @"B"; +} +@end + +@implementation TestFacetsCI +-(NSString*) callA:(ICECurrent*)current +{ + return @"A"; +} +-(NSString*) callC:(ICECurrent*)current +{ + return @"C"; +} +@end + +@implementation TestFacetsDI +-(NSString*) callA:(ICECurrent*)current +{ + return @"A"; +} +-(NSString*) callB:(ICECurrent*)current +{ + return @"B"; +} +-(NSString*) callC:(ICECurrent*)current +{ + return @"C"; +} +-(NSString*) callD:(ICECurrent*)current +{ + return @"D"; +} +@end + +@implementation TestFacetsEI +-(NSString*) callE:(ICECurrent*)current +{ + return @"E"; +} +@end + +@implementation TestFacetsFI +-(NSString*) callE:(ICECurrent*)current +{ + return @"E"; +} +-(NSString*) callF:(ICECurrent*)current +{ + return @"F"; +} +@end + +@implementation TestFacetsGI +-(void) shutdown:(ICECurrent*)current +{ + [[current.adapter getCommunicator] shutdown]; +} +-(NSString*) callG:(ICECurrent*)current +{ + return @"G"; +} +@end + +@implementation TestFacetsHI +-(void) shutdown:(ICECurrent*)current +{ + [[current.adapter getCommunicator] shutdown]; +} +-(NSString*) callG:(ICECurrent*)current +{ + return @"G"; +} +-(NSString*) callH:(ICECurrent*)current +{ + return @"H"; +} +@end diff --git a/objective-c/test/Ice/facets/run.py b/objective-c/test/Ice/facets/run.py new file mode 100755 index 00000000000..0816938a196 --- /dev/null +++ b/objective-c/test/Ice/facets/run.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python +# ********************************************************************** +# +# Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +# +# This copy of Ice is licensed to you under the terms described in the +# ICE_LICENSE file included in this distribution. +# +# ********************************************************************** + +import os, sys + +path = [ ".", "..", "../..", "../../..", "../../../..", "../../../../.." ] +head = os.path.dirname(sys.argv[0]) +if len(head) > 0: + path = [os.path.join(head, p) for p in path] +path = [os.path.abspath(p) for p in path if os.path.exists(os.path.join(p, "scripts", "TestUtil.py")) ] +if len(path) == 0: + raise RuntimeError("can't find toplevel directory!") +sys.path.append(os.path.join(path[0], "scripts")) +import TestUtil + +print("tests with regular server.") +TestUtil.clientServerTest() +print("tests with collocated server.") +TestUtil.collocatedTest() diff --git a/objective-c/test/Ice/faultTolerance/.gitignore b/objective-c/test/Ice/faultTolerance/.gitignore new file mode 100644 index 00000000000..aa38efcc5dc --- /dev/null +++ b/objective-c/test/Ice/faultTolerance/.gitignore @@ -0,0 +1,8 @@ +// Generated by makegitignore.py + +// IMPORTANT: Do not edit this file -- any edits made here will be lost! +client +server +.depend +Test.m +Test.h diff --git a/objective-c/test/Ice/faultTolerance/AllTests.m b/objective-c/test/Ice/faultTolerance/AllTests.m new file mode 100644 index 00000000000..767816d2d74 --- /dev/null +++ b/objective-c/test/Ice/faultTolerance/AllTests.m @@ -0,0 +1,284 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <TestCommon.h> +#import <faultTolerance/Test.h> + +#import <Foundation/Foundation.h> + +@interface Callback : NSObject +{ + BOOL called; + NSCondition* cond; + ICEInt pid; +} +-(void) check; +-(void) called; +-(ICEInt) pid; +@end + +@implementation Callback +-(id) init +{ + if(![super init]) + { + return nil; + } + cond = [[NSCondition alloc] init]; + return self; +} + +#if defined(__clang__) && !__has_feature(objc_arc) +-(void) dealloc +{ + [cond release]; + [super dealloc]; +} +#endif + +-(void) check +{ + [cond lock]; + while(!called) + { + [cond wait]; + } + called = NO; + [cond unlock]; +} +-(void) called +{ + [cond lock]; + called = YES; + [cond signal]; + [cond unlock]; +} +-(void) pidResponse:(ICEInt)p +{ + pid = p; + [self called]; +} + +-(void) pidException:(ICEException*)ex +{ + test(NO); +} +-(ICEInt) pid +{ + return pid; +} +-(void) shutdownResponse +{ + [self called]; +} + +-(void) shutdownException:(ICEException*)ex +{ + test(NO); +} +-(void) abortResponse +{ + test(NO); +} +-(void) abortException:(ICEException*)ex +{ + @try + { + @throw ex; + } + @catch(ICEConnectionLostException*) + { + } + @catch(ICEConnectFailedException*) + { + } + @catch(ICEException* ex) + { + NSLog(@"%@", ex); + test(NO); + } + [self called]; +} +-(void) idempotentAbortResponse +{ + test(NO); +} +-(void) idempotentAbortException:(ICEException*)ex +{ + @try + { + @throw ex; + } + @catch(ICEConnectionLostException*) + { + } + @catch(ICEConnectFailedException*) + { + } + @catch(ICEException* ex) + { + NSLog(@"%@", ex); + test(NO); + } + [self called]; +} +@end + +void +allTests(id<ICECommunicator> communicator, NSArray* ports) +{ + tprintf("testing stringToProxy... "); + NSString* ref = @"test"; + for(NSString* p in ports) + { + ref = [ref stringByAppendingString:@":default -p "]; + ref = [ref stringByAppendingString:p]; + } + id<ICEObjectPrx> base = [communicator stringToProxy:ref]; + test(base); + tprintf("ok\n"); + + tprintf("testing checked cast... "); + id<TestTestIntfPrx> obj = [TestTestIntfPrx checkedCast:base]; + test(obj); + test([obj isEqual:base]); + tprintf("ok\n"); + + int oldPid = 0; + BOOL ami = NO; + unsigned int i, j; + for(i = 1, j = 0; i <= [ports count]; ++i, ++j) + { + if(j > 3) + { + j = 0; + ami = !ami; + } + + if(!ami) + { + tprintf("testing server %d... ", i); + int pid = [obj pid]; + test(pid != oldPid); + tprintf("ok\n"); + oldPid = pid; + } + else + { + tprintf("testing server %d with AMI... ", i); + Callback* cb = [[Callback alloc] init]; + [obj begin_pid:^(ICEInt pid) { [cb pidResponse:pid]; } + exception:^(ICEException* ex) { [cb pidException:ex]; } ]; + [cb check]; + int pid = [cb pid]; + test(pid != oldPid); + oldPid = pid; + ICE_RELEASE(cb); + tprintf("ok\n"); + } + + if(j == 0) + { + if(!ami) + { + tprintf("shutting down server %d... ", i); + [obj shutdown]; + tprintf("ok\n"); + } + else + { + tprintf("shutting down server %d with AMI... ", i); + Callback* cb = [[Callback alloc] init]; + [obj begin_shutdown:^{ [cb shutdownResponse]; } + exception:^(ICEException* ex) { [cb shutdownException:ex]; }]; + [cb check]; + ICE_RELEASE(cb); + tprintf("ok\n"); + } + } + else if(j == 1 || i + 1 > [ports count]) + { + if(!ami) + { + tprintf("aborting server %d... ", i); + @try + { + [obj abort]; + test(NO); + } + @catch(ICEConnectionLostException*) + { + tprintf("ok\n"); + } + @catch(ICEConnectFailedException*) + { + tprintf("ok\n"); + } + } + else + { + tprintf("aborting server %d with AMI... ", i); + Callback* cb = [[Callback alloc] init]; + [obj begin_abort:^{ [cb abortResponse]; } exception:^(ICEException* ex) { [cb abortException:ex]; }]; + [cb check]; + ICE_RELEASE(cb); + tprintf("ok\n"); + } + } + else if(j == 2 || j == 3) + { + if(!ami) + { + tprintf("aborting server %d and #%d with idempotent call... ", i, i + 1); + @try + { + [obj idempotentAbort]; + test(NO); + } + @catch(ICEConnectionLostException*) + { + tprintf("ok\n"); + } + @catch(ICEConnectFailedException*) + { + tprintf("ok\n"); + } + } + else + { + tprintf("aborting server %d and #%d with idempotent AMI call... ", i, i + 1); + Callback* cb = [[Callback alloc] init]; + [obj begin_idempotentAbort:^{ [cb idempotentAbortResponse]; } + exception:^(ICEException* ex) { [cb idempotentAbortException:ex]; }]; + [cb check]; + ICE_RELEASE(cb); + tprintf("ok\n"); + } + + ++i; + } + else + { + test(NO); + } + } + + tprintf("testing whether all servers are gone... "); + @try + { + [obj ice_ping]; + test(NO); + } + @catch(ICELocalException*) + { + tprintf("ok\n"); + } +} + diff --git a/objective-c/test/Ice/faultTolerance/Client.m b/objective-c/test/Ice/faultTolerance/Client.m new file mode 100644 index 00000000000..6875b4f46c3 --- /dev/null +++ b/objective-c/test/Ice/faultTolerance/Client.m @@ -0,0 +1,100 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <TestCommon.h> +#import <faultTolerance/Test.h> +#import <stdio.h> + +void +usage(const char* n) +{ + printf("Usage: %s port\n", n); +} + +int +run(int argc, char* argv[], id<ICECommunicator> communicator) +{ + NSMutableArray* ports = [NSMutableArray array]; + int i; + for(i = 1; i < argc; ++i) + { + if(argv[i][0] == '-') + { + fprintf(stderr, "%s: unknown option `%s'", argv[0], argv[i]); + usage(argv[0]); + return EXIT_FAILURE; + } + + [ports addObject:[NSString stringWithUTF8String:argv[i]]]; + } + + if([ports count] == 0) + { + fprintf(stderr, "%s: no ports specified", argv[0]); + usage(argv[0]); + return EXIT_FAILURE; + } + + @try + { + void allTests(id<ICECommunicator>, NSArray*); + allTests(communicator, ports); + } + @catch(ICEException* ex) + { + NSLog(@"%@", ex); + test(NO); + } + + return EXIT_SUCCESS; +} + +int +main(int argc, char* argv[]) +{ + int status; + @autoreleasepool + { + id<ICECommunicator> communicator = nil; + @try + { + ICEInitializationData* initData = [ICEInitializationData initializationData]; + initData.properties = defaultClientProperties(&argc, argv); + + // + // This test aborts servers, so we don't want warnings. + // + [initData.properties setProperty:@"Ice.Warn.Connections" value:@"0"]; + + communicator = [ICEUtil createCommunicator:&argc argv:argv initData:initData]; + + status = run(argc, argv, communicator); + } + @catch(ICEException* ex) + { + NSLog(@"%@", ex); + status = EXIT_FAILURE; + } + + if(communicator) + { + @try + { + [communicator destroy]; + } + @catch(ICEException* ex) + { + NSLog(@"%@", ex); + status = EXIT_FAILURE; + } + } + } + return status; +} diff --git a/objective-c/test/Ice/faultTolerance/Makefile b/objective-c/test/Ice/faultTolerance/Makefile new file mode 100644 index 00000000000..4c7d3b3c6e1 --- /dev/null +++ b/objective-c/test/Ice/faultTolerance/Makefile @@ -0,0 +1,37 @@ +# ********************************************************************** +# +# Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +# +# This copy of Ice is licensed to you under the terms described in the +# ICE_LICENSE file included in this distribution. +# +# ********************************************************************** + +top_srcdir = ../../.. + +CLIENT = client +SERVER = server + +TARGETS = $(CLIENT) $(SERVER) + +SLICE_OBJS = Test.o + +COBJS = Client.o \ + AllTests.o + +SOBJS = TestI.o \ + Server.o + +OBJS = $(COBJS) $(SOBJS) $(SLICE_OBJS) + +include $(top_srcdir)/config/Make.rules + +CPPFLAGS := -I. -I.. -I../../include $(CPPFLAGS) + +$(CLIENT): $(COBJS) $(SLICE_OBJS) + rm -f $@ + $(CXX) $(LDFLAGS) $(LDEXEFLAGS) -o $@ $(COBJS) $(SLICE_OBJS) $(TEST_LIBS) + +$(SERVER): $(SOBJS) $(SLICE_OBJS) + rm -f $@ + $(CXX) $(LDFLAGS) $(LDEXEFLAGS) -o $@ $(SOBJS) $(SLICE_OBJS) $(TEST_LIBS) diff --git a/objective-c/test/Ice/faultTolerance/Server.m b/objective-c/test/Ice/faultTolerance/Server.m new file mode 100644 index 00000000000..4e31bd74eb8 --- /dev/null +++ b/objective-c/test/Ice/faultTolerance/Server.m @@ -0,0 +1,105 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <faultTolerance/TestI.h> + +#import <stdio.h> + +static void +usage(const char* n) +{ + printf("Usage: %s port\n", n); +} + +static int +run(int argc, char** argv, id<ICECommunicator> communicator) +{ + int port = 0; + int i; + for(i = 1; i < argc; ++i) + { + if(argv[i][0] == '-') + { + fprintf(stderr, "%s: unknown option `%s'", argv[0], argv[i]); + usage(argv[0]); + return EXIT_FAILURE; + } + + if(port > 0) + { + fprintf(stderr, "%s: only one port can be specified", argv[0]); + usage(argv[0]); + return EXIT_FAILURE; + } + + port = atoi(argv[i]); + } + + if(port <= 0) + { + fprintf(stderr, "%s: no port specified", argv[0]); + usage(argv[0]); + return EXIT_FAILURE; + } + + NSString* endpts = [NSString stringWithFormat:@"default -p %d:udp", port]; + [[communicator getProperties] setProperty:@"TestAdapter.Endpoints" value:endpts]; + id<ICEObjectAdapter> adapter = [communicator createObjectAdapter:@"TestAdapter"]; + + ICEObject* object = [TestI testIntf]; + [adapter add:object identity:[communicator stringToIdentity:@"test"]]; + [adapter activate]; + [communicator waitForShutdown]; + return EXIT_SUCCESS; +} + +int +main(int argc, char* argv[]) +{ + int status; + @autoreleasepool + { + id<ICECommunicator> communicator = nil; + + @try + { + // + // In this test, we need a longer server idle time, otherwise + // our test servers may time out before they are used in the + // test. + // + ICEInitializationData* initData = [ICEInitializationData initializationData]; + initData.properties = [ICEUtil createProperties:&argc argv:argv]; + [initData.properties setProperty:@"Ice.ServerIdleTime" value:@"120"]; // Two minutes. + + communicator = [ICEUtil createCommunicator:&argc argv:argv initData:initData]; + status = run(argc, argv, communicator); + } + @catch(ICEException* ex) + { + NSLog(@"%@", ex); + status = EXIT_FAILURE; + } + + if(communicator) + { + @try + { + [communicator destroy]; + } + @catch(ICEException* ex) + { + NSLog(@"%@", ex); + status = EXIT_FAILURE; + } + } + } + return status; +} diff --git a/objective-c/test/Ice/faultTolerance/Test.ice b/objective-c/test/Ice/faultTolerance/Test.ice new file mode 100644 index 00000000000..d5488ad5726 --- /dev/null +++ b/objective-c/test/Ice/faultTolerance/Test.ice @@ -0,0 +1,23 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#pragma once + +module Test +{ + +interface TestIntf +{ + void shutdown(); + void abort(); + idempotent void idempotentAbort(); + idempotent int pid(); +}; + +}; diff --git a/objective-c/test/Ice/faultTolerance/TestI.h b/objective-c/test/Ice/faultTolerance/TestI.h new file mode 100644 index 00000000000..dc238000725 --- /dev/null +++ b/objective-c/test/Ice/faultTolerance/TestI.h @@ -0,0 +1,14 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <faultTolerance/Test.h> + +@interface TestI : TestTestIntf<TestTestIntf> +@end + diff --git a/objective-c/test/Ice/faultTolerance/TestI.m b/objective-c/test/Ice/faultTolerance/TestI.m new file mode 100644 index 00000000000..22045e610d7 --- /dev/null +++ b/objective-c/test/Ice/faultTolerance/TestI.m @@ -0,0 +1,36 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <faultTolerance/TestI.h> + +#include <unistd.h> + +@implementation TestI +-(void) shutdown:(ICECurrent*)current +{ + [[current.adapter getCommunicator] shutdown]; +} + +-(void) abort:(ICECurrent*)current +{ + exit(0); +} + +-(void) idempotentAbort:(ICECurrent*)current +{ + exit(0); +} + +-(ICEInt) pid:(ICECurrent*)current +{ + return getpid(); +} +@end + diff --git a/objective-c/test/Ice/faultTolerance/run.py b/objective-c/test/Ice/faultTolerance/run.py new file mode 100755 index 00000000000..440686d85ed --- /dev/null +++ b/objective-c/test/Ice/faultTolerance/run.py @@ -0,0 +1,46 @@ +#!/usr/bin/env python +# ********************************************************************** +# +# Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +# +# This copy of Ice is licensed to you under the terms described in the +# ICE_LICENSE file included in this distribution. +# +# ********************************************************************** + +import os, sys + +path = [ ".", "..", "../..", "../../..", "../../../..", "../../../../.." ] +head = os.path.dirname(sys.argv[0]) +if len(head) > 0: + path = [os.path.join(head, p) for p in path] +path = [os.path.abspath(p) for p in path if os.path.exists(os.path.join(p, "scripts", "TestUtil.py")) ] +if len(path) == 0: + raise RuntimeError("can't find toplevel directory!") +sys.path.append(os.path.join(path[0], "scripts")) +import TestUtil + +server = os.path.join(os.getcwd(), "server") +client = os.path.join(os.getcwd(), "client") + +num = 12 +base = 13340 + +serverProc = [] +for i in range(0, num): + print "starting server #%d..." % (i + 1), + serverProc.append(TestUtil.startServer(server, "%d" % (base + i))) + print "ok" + +ports = "" +for i in range(0, num): + ports = "%s %d" % (ports, base + i) + +print "starting client...", +clientProc = TestUtil.startClient(client, ports + " " + "--Ice.Trace.Network=0", startReader = False) +print "ok" +clientProc.startReader() + +clientProc.waitTestSuccess() +for p in serverProc: + p.waitTestSuccess() diff --git a/objective-c/test/Ice/hash/.gitignore b/objective-c/test/Ice/hash/.gitignore new file mode 100644 index 00000000000..be837f9fdf3 --- /dev/null +++ b/objective-c/test/Ice/hash/.gitignore @@ -0,0 +1,7 @@ +// Generated by makegitignore.py + +// IMPORTANT: Do not edit this file -- any edits made here will be lost! +client +.depend +HashTest.m +HashTest.h diff --git a/objective-c/test/Ice/hash/AllTests.m b/objective-c/test/Ice/hash/AllTests.m new file mode 100644 index 00000000000..79bed007c11 --- /dev/null +++ b/objective-c/test/Ice/hash/AllTests.m @@ -0,0 +1,155 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <TestCommon.h> +#import <HashTest.h> + +#import <Foundation/Foundation.h> + +void +hashAllTests() +{ + int maxCollisions = 10; + int maxIterations = 10000; + + { + tprintf("testing proxy hash algorithm collisions... "); + int collisions = 0; + ICEInitializationData* initData = [ICEInitializationData initializationData]; + initData.properties = [ICEUtil createProperties]; + id<ICECommunicator> communicator = [ICEUtil createCommunicator:initData]; + NSMutableDictionary* seenObject = [[NSMutableDictionary alloc] init]; + for(int i = 0; collisions < maxCollisions && i < maxIterations; ++i) + { + NSString* s = [NSString stringWithFormat:@"%i:tcp -p %i -t 10%i:udp -p %i -h %i", + i, arc4random() % 65536, arc4random() % 1000000, + arc4random() % 65536, arc4random() % 100]; + ICEObjectPrx* obj = [communicator stringToProxy:s]; + + NSNumber* hash = [NSNumber numberWithUnsignedInteger:[obj hash]]; + + if([seenObject objectForKey:hash]) + { + if([obj isEqual:[seenObject objectForKey:hash]]) + { + continue; + } + ++collisions; + } + else + { + [seenObject setObject:obj forKey:hash]; + } + // + // Test the same object produce always the same hash. + // + test([obj hash] == [obj hash]); + test(collisions < maxCollisions); + } + [seenObject removeAllObjects]; + [communicator destroy]; + ICE_RELEASE(seenObject); + tprintf("ok\n"); + } + + tprintf("testing struct hash algorithm collisions... "); + { + int collisions = 0; + NSMutableDictionary* seenObject = [[NSMutableDictionary alloc] init]; + for(int i = 0; collisions < maxCollisions && i < maxIterations; ++i) + { + TestHashPoint* obj = [TestHashPoint point:(arc4random() % 1000) + y:(arc4random() % 1000)]; + NSNumber* hash = [NSNumber numberWithUnsignedInteger:[obj hash]]; + if([seenObject objectForKey:hash]) + { + if([obj isEqual:[seenObject objectForKey:hash]]) + { + continue; + } + ++collisions; + } + else + { + [seenObject setObject:obj forKey:hash]; + } + // + // Test the same object produce always the same hash. + // + test([obj hash] == [obj hash]); + test(collisions < maxCollisions); + } + [seenObject removeAllObjects]; + ICE_RELEASE(seenObject); + } + { + int collisions = 0; + NSMutableDictionary* seenObject = [[NSMutableDictionary alloc] init]; + for(int i = 0; collisions < maxCollisions && i < maxIterations; ++i) + { + TestHashPointF* obj = [TestHashPointF pointF:(arc4random() % 1000)/3 + y:(arc4random() % 1000)/5 + z:(arc4random() % 1000)/7]; + + NSNumber* hash = [NSNumber numberWithUnsignedInteger:[obj hash]]; + if([seenObject objectForKey:hash]) + { + if([obj isEqual:[seenObject objectForKey:hash]]) + { + continue; + } + ++collisions; + } + else + { + [seenObject setObject:obj forKey:hash]; + } + // + // Test the same object produce always the same hash. + // + test([obj hash] == [obj hash]); + test(collisions < maxCollisions); + } + [seenObject removeAllObjects]; + ICE_RELEASE(seenObject); + } + + { + int collisions = 0; + NSMutableDictionary* seenObject = [[NSMutableDictionary alloc] init]; + for(int i = 0; collisions < maxCollisions && i < maxIterations; ++i) + { + TestHashPointD* obj = [TestHashPointD pointD:(arc4random() % 1000)/3 + y:(arc4random() % 1000)/5 + z:(arc4random() % 1000)/7]; + NSNumber* hash = [NSNumber numberWithUnsignedInteger:[obj hash]]; + if([seenObject objectForKey:hash]) + { + if([obj isEqual:[seenObject objectForKey:hash]]) + { + continue; + } + ++collisions; + } + else + { + [seenObject setObject:obj forKey:hash]; + } + // + // Test the same object produce always the same hash. + // + test([obj hash] == [obj hash]); + test(collisions < maxCollisions); + } + [seenObject removeAllObjects]; + ICE_RELEASE(seenObject); + } + tprintf("ok\n"); +} diff --git a/objective-c/test/Ice/hash/Client.m b/objective-c/test/Ice/hash/Client.m new file mode 100644 index 00000000000..e13461b3759 --- /dev/null +++ b/objective-c/test/Ice/hash/Client.m @@ -0,0 +1,47 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <TestCommon.h> +#import <HashTest.h> + +static int +run() +{ + void hashAllTests(); + hashAllTests(); + return EXIT_SUCCESS; +} + +#if TARGET_OS_IPHONE +# define main hashClient +#endif + +int +main(int argc, char* argv[]) +{ + int status; + @autoreleasepool + { + @try + { + status = run(); + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + @catch(TestFailedException* ex) + { + status = EXIT_FAILURE; + } + } + return status; +} diff --git a/objective-c/test/Ice/hash/HashTest.ice b/objective-c/test/Ice/hash/HashTest.ice new file mode 100644 index 00000000000..15af694446f --- /dev/null +++ b/objective-c/test/Ice/hash/HashTest.ice @@ -0,0 +1,93 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#pragma once + +["objc:prefix:TestHash"] +module Test +{ + + +exception BaseException +{ +}; + +exception InvalidPointException extends BaseException +{ + int index; +}; + +exception InvalidLengthException extends BaseException +{ + int length; +}; + +exception OtherException +{ + int x; + int y; + int z; + bool b; +}; + + +struct PointF +{ + float x; + float y; + float z; +}; + +struct PointD +{ + double x; + double y; + double z; +}; + +struct Point +{ + int x; + int y; +}; +sequence<Point> Points; + +struct Polyline +{ + Points vertices; +}; + +struct Color +{ + int r; + int g; + int b; + int a; +}; +dictionary<int, Color> StringColorMap; + +struct ColorPalette +{ + StringColorMap colors; +}; + +class Pen +{ + int thickness; + Test::Color color; +}; + +struct Draw +{ + Test::Color backgroundColor; + Test::Pen pen; + bool shared; +}; + +}; diff --git a/objective-c/test/Ice/hash/Makefile b/objective-c/test/Ice/hash/Makefile new file mode 100644 index 00000000000..36e3431b261 --- /dev/null +++ b/objective-c/test/Ice/hash/Makefile @@ -0,0 +1,29 @@ +# ********************************************************************** +# +# Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +# +# This copy of Ice is licensed to you under the terms described in the +# ICE_LICENSE file included in this distribution. +# +# ********************************************************************** + +top_srcdir = ../../.. + +CLIENT = client + +TARGETS = $(CLIENT) + +SLICE_OBJS = HashTest.o + +COBJS = Client.o \ + AllTests.o + +OBJS = $(COBJS) $(SLICE_OBJS) + +include $(top_srcdir)/config/Make.rules + +CPPFLAGS := -I. -I.. -I../../include $(CPPFLAGS) + +$(CLIENT): $(COBJS) $(SLICE_OBJS) + rm -f $@ + $(CXX) $(LDFLAGS) $(LDEXEFLAGS) -o $@ $(COBJS) $(SLICE_OBJS) $(TEST_LIBS) diff --git a/objective-c/test/Ice/hash/run.py b/objective-c/test/Ice/hash/run.py new file mode 100755 index 00000000000..e925f3c7010 --- /dev/null +++ b/objective-c/test/Ice/hash/run.py @@ -0,0 +1,24 @@ +#!/usr/bin/env python +# ********************************************************************** +# +# Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +# +# This copy of Ice is licensed to you under the terms described in the +# ICE_LICENSE file included in this distribution. +# +# ********************************************************************** + +import os, sys + +path = [ ".", "..", "../..", "../../..", "../../../..", "../../../../.." ] +head = os.path.dirname(sys.argv[0]) +if len(head) > 0: + path = [os.path.join(head, p) for p in path] +path = [os.path.abspath(p) for p in path if os.path.exists(os.path.join(p, "scripts", "TestUtil.py")) ] +if len(path) == 0: + raise RuntimeError("can't find toplevel directory!") +sys.path.append(os.path.join(path[0], "scripts")) +import TestUtil + +client = os.path.join(os.getcwd(), "client") +TestUtil.simpleTest(client) diff --git a/objective-c/test/Ice/hold/.gitignore b/objective-c/test/Ice/hold/.gitignore new file mode 100644 index 00000000000..4e573bb9e5f --- /dev/null +++ b/objective-c/test/Ice/hold/.gitignore @@ -0,0 +1,8 @@ +// Generated by makegitignore.py + +// IMPORTANT: Do not edit this file -- any edits made here will be lost! +client +server +.depend +HoldTest.m +HoldTest.h diff --git a/objective-c/test/Ice/hold/AllTests.m b/objective-c/test/Ice/hold/AllTests.m new file mode 100644 index 00000000000..43ca15c5b90 --- /dev/null +++ b/objective-c/test/Ice/hold/AllTests.m @@ -0,0 +1,246 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <TestCommon.h> +#import <HoldTest.h> + +#import <Foundation/Foundation.h> + +@interface Condition : NSObject +{ + BOOL value; +} +-(id) initWithValue:(BOOL)value; +@property (assign) BOOL value; +@end + +@implementation Condition + +@synthesize value; + +-(id) initWithValue:(BOOL)v +{ + self = [super init]; + if(!self) + { + return nil; + } + value = v; + return self; +} +@end + +@interface AMICheckSetValue : NSObject +{ + Condition* condition; + ICEInt expected; + BOOL sent; + NSCondition* cond; +} +-(id)init:(Condition*)cond expected:(ICEInt)expected; +-(void) waitForSent; +@end + +@implementation AMICheckSetValue +-(id)init:(Condition*)c expected:(ICEInt)e +{ + self = [super init]; + if(!self) + { + return nil; + } + cond = [[NSCondition alloc] init]; + condition = ICE_RETAIN(c); + expected = e; + return self; +} + +#if defined(__clang__) && !__has_feature(objc_arc) +-(void) dealloc +{ + [cond release]; + [condition release]; + [super dealloc]; +} +#endif + +-(void) ice_response:(ICEInt)value +{ + if(value != expected) + { + condition.value = NO; + } +} +-(void) ice_exception:(ICEException*)ex +{ + tprintf("unexpected exception: %@", ex); + test(false); +} +-(void) ice_sent +{ + [cond lock]; + sent = YES; + [cond signal]; + [cond unlock]; +} +-(void) waitForSent +{ + [cond lock]; + while(!sent) + { + [cond wait]; + } + [cond unlock]; +} +@end + +void +allTests(id<ICECommunicator> communicator) +{ + tprintf("testing stringToProxy... "); + NSString* ref = @"hold:default -p 12010 -t 30000"; + id<ICEObjectPrx> base = [communicator stringToProxy:ref]; + test(base); + NSString* refSerialized = @"hold:default -p 12011 -t 60000"; + id<ICEObjectPrx> baseSerialized = [communicator stringToProxy:refSerialized]; + test(base); + tprintf("ok\n"); + + tprintf("testing checked cast... "); + id<TestHoldHoldPrx> hold = [TestHoldHoldPrx checkedCast:base]; + test(hold); + test([hold isEqual:base]); + id<TestHoldHoldPrx> holdSerialized = [TestHoldHoldPrx checkedCast:baseSerialized]; + test(holdSerialized); + test([holdSerialized isEqual:baseSerialized]); + tprintf("ok\n"); + + tprintf("changing state between active and hold rapidly... "); + int i; + for(i = 0; i < 100; ++i) + { + [hold putOnHold:0]; + } + for(i = 0; i < 100; ++i) + { + [[hold ice_oneway] putOnHold:0]; + } + for(i = 0; i < 100; ++i) + { + [holdSerialized putOnHold:0]; + } + for(i = 0; i < 100; ++i) + { + [[holdSerialized ice_oneway] putOnHold:0]; + } + tprintf("ok\n"); + + tprintf("testing without serialize mode... "); + { + Condition* cond = ICE_AUTORELEASE([[Condition alloc] initWithValue:YES]); + int value = 0; + AMICheckSetValue* cb; + while([cond value]) + { + cb = ICE_AUTORELEASE([[AMICheckSetValue alloc] init:cond expected:value]); + if([hold begin_set:++value delay:(random() % 5 + 1) response:^(ICEInt r) { [cb ice_response:r]; } + exception:^(ICEException* ex) { [cb ice_exception:ex]; } sent:^(BOOL ss) { [cb ice_sent]; }]) + { + cb = 0; + } + if(value % 100 == 0) + { + if(cb) + { + [cb waitForSent]; + cb = 0; + } + } + } + if(cb) + { + [cb waitForSent]; + cb = 0; + } + } + tprintf("ok\n"); + + tprintf("testing with serialize mode... "); + { + Condition* cond = ICE_AUTORELEASE([[Condition alloc] initWithValue:YES]); + int value = 0; + AMICheckSetValue* cb; +#if TARGET_OS_IPHONE && !TARGET_IPHONE_SIMULATOR + while(value < 300 && [cond value]) +#else + while(value < 3000 && [cond value]) +#endif + { + cb = ICE_AUTORELEASE([[AMICheckSetValue alloc] init:cond expected:value]); + if([holdSerialized begin_set:++value delay:0 response:^(ICEInt r) { [cb ice_response:r]; } + exception:^(ICEException* ex) { [cb ice_exception:ex]; } sent:^(BOOL ss) { [cb ice_sent]; }]) + { + cb = 0; + } + if(value % 100 == 0) + { + if(cb) + { + [cb waitForSent]; + cb = 0; + } + } + } + if(cb) + { + [cb waitForSent]; + cb = 0; + } + test([cond value]); + int i; +#if TARGET_OS_IPHONE && !TARGET_IPHONE_SIMULATOR + for(i = 0; i < 400; ++i) +#else + for(i = 0; i < 20000; ++i) +#endif + { + [[holdSerialized ice_oneway] setOneway:(value + 1) expected:value]; + ++value; + if((i % 100) == 0) + { + [[holdSerialized ice_oneway] putOnHold:1]; + } + } + } + tprintf("ok\n"); + + tprintf("testing waitForHold... "); + { + [hold waitForHold]; + [hold waitForHold]; + for(i = 0; i < 1000; ++i) + { + [[hold ice_oneway] ice_ping]; + if((i % 20) == 0) + { + [hold putOnHold:0]; + } + } + [hold putOnHold:-1]; + [hold ice_ping]; + [hold putOnHold:-1]; + [hold ice_ping]; + } + tprintf("ok\n"); + + tprintf("changing state to hold and shutting down server... "); + [hold shutdown]; + tprintf("ok\n"); +} diff --git a/objective-c/test/Ice/hold/Client.m b/objective-c/test/Ice/hold/Client.m new file mode 100644 index 00000000000..2e426594e95 --- /dev/null +++ b/objective-c/test/Ice/hold/Client.m @@ -0,0 +1,70 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <TestCommon.h> +#import <HoldTest.h> + +int +run(id<ICECommunicator> communicator) +{ + void allTests(id<ICECommunicator>); + allTests(communicator); + return EXIT_SUCCESS; +} + +#if TARGET_OS_IPHONE +# define main holdClient +#endif + +int +main(int argc, char* argv[]) +{ + int status; + @autoreleasepool + { + id<ICECommunicator> communicator; + + @try + { + ICEInitializationData* initData = [ICEInitializationData initializationData]; + initData.properties = defaultClientProperties(&argc, argv); +#if TARGET_OS_IPHONE + initData.prefixTable__ = [NSDictionary dictionaryWithObjectsAndKeys: + @"TestHold", @"::Test", + nil]; +#endif + communicator = [ICEUtil createCommunicator:&argc argv:argv initData:initData]; + status = run(communicator); + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + @catch(TestFailedException* ex) + { + status = EXIT_FAILURE; + } + + if(communicator) + { + @try + { + [communicator destroy]; + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + } + } + return status; +} diff --git a/objective-c/test/Ice/hold/HoldTest.ice b/objective-c/test/Ice/hold/HoldTest.ice new file mode 100644 index 00000000000..f872dec06a3 --- /dev/null +++ b/objective-c/test/Ice/hold/HoldTest.ice @@ -0,0 +1,25 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#pragma once + +["objc:prefix:TestHold"] +module Test +{ + +interface Hold +{ + void putOnHold(int seconds); + void waitForHold(); + int set(int value, int delay); + void setOneway(int value, int expected); + void shutdown(); +}; + +}; diff --git a/objective-c/test/Ice/hold/Makefile b/objective-c/test/Ice/hold/Makefile new file mode 100644 index 00000000000..c3a2e3766ea --- /dev/null +++ b/objective-c/test/Ice/hold/Makefile @@ -0,0 +1,37 @@ +# ********************************************************************** +# +# Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +# +# This copy of Ice is licensed to you under the terms described in the +# ICE_LICENSE file included in this distribution. +# +# ********************************************************************** + +top_srcdir = ../../.. + +CLIENT = client +SERVER = server + +TARGETS = $(CLIENT) $(SERVER) + +SLICE_OBJS = HoldTest.o + +COBJS = Client.o \ + AllTests.o + +SOBJS = TestI.o \ + Server.o + +OBJS = $(COBJS) $(SOBJS) $(SLICE_OBJS) + +include $(top_srcdir)/config/Make.rules + +CPPFLAGS := -I. -I.. -I../../include $(CPPFLAGS) + +$(CLIENT): $(COBJS) $(SLICE_OBJS) + rm -f $@ + $(CXX) $(LDFLAGS) $(LDEXEFLAGS) -o $@ $(COBJS) $(SLICE_OBJS) $(TEST_LIBS) + +$(SERVER): $(SOBJS) $(SLICE_OBJS) + rm -f $@ + $(CXX) $(LDFLAGS) $(LDEXEFLAGS) -o $@ $(SOBJS) $(SLICE_OBJS) $(TEST_LIBS) diff --git a/objective-c/test/Ice/hold/Server.m b/objective-c/test/Ice/hold/Server.m new file mode 100644 index 00000000000..aa9c9d99530 --- /dev/null +++ b/objective-c/test/Ice/hold/Server.m @@ -0,0 +1,90 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <hold/TestI.h> +#import <TestCommon.h> + +static int +run(id<ICECommunicator> communicator) +{ + [[communicator getProperties] setProperty:@"TestAdapter1.Endpoints" value:@"default -p 12010 -t 10000:udp"]; + [[communicator getProperties] setProperty:@"TestAdapter1.ThreadPool.Size" value:@"5"]; + [[communicator getProperties] setProperty:@"TestAdapter1.ThreadPool.SizeMax" value:@"5"]; + [[communicator getProperties] setProperty:@"TestAdapter1.ThreadPool.SizeWarn" value:@"0"]; + [[communicator getProperties] setProperty:@"TestAdapter1.ThreadPool.Serialize" value:@"0"]; + id<ICEObjectAdapter> adapter1 = [communicator createObjectAdapter:@"TestAdapter1"]; + + + [[communicator getProperties] setProperty:@"TestAdapter2.Endpoints" value:@"default -p 12011 -t 10000:udp"]; + [[communicator getProperties] setProperty:@"TestAdapter2.ThreadPool.Size" value:@"5"]; + [[communicator getProperties] setProperty:@"TestAdapter2.ThreadPool.SizeMax" value:@"5"]; + [[communicator getProperties] setProperty:@"TestAdapter2.ThreadPool.SizeWarn" value:@"0"]; + [[communicator getProperties] setProperty:@"TestAdapter2.ThreadPool.Serialize" value:@"1"]; + id<ICEObjectAdapter> adapter2 = [communicator createObjectAdapter:@"TestAdapter2"]; + + [adapter1 add:[HoldI hold] identity:[communicator stringToIdentity:@"hold"]]; + [adapter2 add:[HoldI hold] identity:[communicator stringToIdentity:@"hold"]]; + + [adapter1 activate]; + [adapter2 activate]; + + serverReady(communicator); + + [communicator waitForShutdown]; + + return EXIT_SUCCESS; +} + +#if TARGET_OS_IPHONE +# define main holdServer +#endif + +int +main(int argc, char* argv[]) +{ + @autoreleasepool + { + int status; + id<ICECommunicator> communicator = nil; + + @try + { + ICEInitializationData* initData = [ICEInitializationData initializationData]; + initData.properties = defaultServerProperties(&argc, argv); +#if TARGET_OS_IPHONE + initData.prefixTable__ = [NSDictionary dictionaryWithObjectsAndKeys: + @"TestHold", @"::Test", + nil]; +#endif + + communicator = [ICEUtil createCommunicator:&argc argv:argv initData:initData]; + status = run(communicator); + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + + if(communicator) + { + @try + { + [communicator destroy]; + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + } + return status; + } +} diff --git a/objective-c/test/Ice/hold/TestI.h b/objective-c/test/Ice/hold/TestI.h new file mode 100644 index 00000000000..a07d2f49f17 --- /dev/null +++ b/objective-c/test/Ice/hold/TestI.h @@ -0,0 +1,28 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + + +#import <HoldTest.h> + +#include <dispatch/dispatch.h> + +@interface Timer : NSObject +{ + dispatch_queue_t queue; +} +-(void) schedule:(void(^)())callback timeout:(ICEInt)timeout; +@end + +@interface HoldI : TestHoldHold<TestHoldHold> +{ + ICEInt last; + Timer* timer; +} + +@end diff --git a/objective-c/test/Ice/hold/TestI.m b/objective-c/test/Ice/hold/TestI.m new file mode 100644 index 00000000000..e91f5690e54 --- /dev/null +++ b/objective-c/test/Ice/hold/TestI.m @@ -0,0 +1,142 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <hold/TestI.h> +#import <TestCommon.h> + +#import <Foundation/Foundation.h> + +@implementation Timer +-(id) init +{ + self = [super init]; + if(self != nil) + { + queue = dispatch_queue_create("timer", NULL); + } + return self; +} +#if defined(__clang__) && !__has_feature(objc_arc) +-(void) dealloc +{ + dispatch_release(queue); + [super dealloc]; +} +#endif +-(void) schedule:(void(^)())callback timeout:(ICEInt)t +{ + dispatch_source_t timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, queue); + dispatch_source_set_timer(timer, dispatch_time(DISPATCH_TIME_NOW, t * NSEC_PER_MSEC), DISPATCH_TIME_FOREVER, 0); + dispatch_source_set_event_handler(timer, ^{ + callback(); + dispatch_source_cancel(timer); +#if defined(__clang__) && !__has_feature(objc_arc) + dispatch_release(timer); +#endif + }); + dispatch_resume(timer); +} +@end + +@implementation HoldI +-(id) init +{ + self = [super init]; + if(self != nil) + { + timer = [Timer new]; + } + return self; +} +#if defined(__clang__) && !__has_feature(objc_arc) +-(void) dealloc +{ + [timer release]; + [super dealloc]; +} +#endif +-(void) putOnHold:(ICEInt)milliSeconds current:(ICECurrent*)current +{ + if(milliSeconds < 0) + { + [current.adapter hold]; + } + else if(milliSeconds == 0) + { + [current.adapter hold]; + [current.adapter activate]; + } + else + { + [timer schedule:^{ + @try + { + [current.adapter hold]; + [current.adapter activate]; + } + @catch(ICEObjectAdapterDeactivatedException* ex) + { + } + @catch(id ex) + { + test(NO); + } + } timeout:milliSeconds]; + } +} + +-(void) waitForHold:(ICECurrent*)current +{ + [timer schedule:^{ + @try + { + [current.adapter waitForHold]; + [current.adapter activate]; + } + @catch(ICEObjectAdapterDeactivatedException* ex) + { + test(NO); + } + @catch(id ex) + { + test(NO); + } + } timeout:0]; +} + +-(ICEInt) set:(ICEInt)value delay:(ICEInt)delay current:(ICECurrent*)current +{ + [NSThread sleepForTimeInterval:delay / 1000.0]; + @synchronized(self) + { + ICEInt tmp = last; + last = value; + return tmp; + } + return 0; +} + + +-(void) setOneway:(ICEInt)value expected:(ICEInt)expected current:(ICECurrent*)current +{ + @synchronized(self) + { + test(last == expected); + last = value; + } +} + +-(void) shutdown:(ICECurrent*)current +{ + [current.adapter hold]; + [[current.adapter getCommunicator] shutdown]; +} + +@end diff --git a/objective-c/test/Ice/hold/run.py b/objective-c/test/Ice/hold/run.py new file mode 100755 index 00000000000..ce8c5dd4b18 --- /dev/null +++ b/objective-c/test/Ice/hold/run.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python +# ********************************************************************** +# +# Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +# +# This copy of Ice is licensed to you under the terms described in the +# ICE_LICENSE file included in this distribution. +# +# ********************************************************************** + +import os, sys + +path = [ ".", "..", "../..", "../../..", "../../../..", "../../../../.." ] +head = os.path.dirname(sys.argv[0]) +if len(head) > 0: + path = [os.path.join(head, p) for p in path] +path = [os.path.abspath(p) for p in path if os.path.exists(os.path.join(p, "scripts", "TestUtil.py")) ] +if len(path) == 0: + raise RuntimeError("can't find toplevel directory!") +sys.path.append(os.path.join(path[0], "scripts")) +import TestUtil + +TestUtil.clientServerTest() diff --git a/objective-c/test/Ice/info/.gitignore b/objective-c/test/Ice/info/.gitignore new file mode 100644 index 00000000000..23a7fa22453 --- /dev/null +++ b/objective-c/test/Ice/info/.gitignore @@ -0,0 +1,8 @@ +// Generated by makegitignore.py + +// IMPORTANT: Do not edit this file -- any edits made here will be lost! +client +server +.depend +InfoTest.m +InfoTest.h diff --git a/objective-c/test/Ice/info/AllTests.m b/objective-c/test/Ice/info/AllTests.m new file mode 100644 index 00000000000..d320287b6fe --- /dev/null +++ b/objective-c/test/Ice/info/AllTests.m @@ -0,0 +1,209 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <objc/IceSSL.h> +#import <TestCommon.h> +#import <InfoTest.h> + + +TestInfoTestIntfPrx* +infoAllTests(id<ICECommunicator> communicator) +{ + tprintf("testing proxy endpoint information... "); + { + ICEObjectPrx* p1 = + [communicator stringToProxy:@"test -t:default -h tcphost -p 10000 -t 1200 -z --sourceAddress 10.10.10.10:" + "udp -h udphost -p 10001 --interface eth0 --ttl 5 --sourceAddress 10.10.10.10:" + "opaque -e 1.8 -t 100 -v ABCD"]; + + ICEEndpointSeq* endps = [p1 ice_getEndpoints]; + id<ICEEndpoint> endpoint = [endps objectAtIndex:0]; + ICEIPEndpointInfo<ICEEndpointInfo>* ipEndpoint = (ICEIPEndpointInfo<ICEEndpointInfo>*)[endpoint getInfo]; + test([ipEndpoint isKindOfClass:[ICEIPEndpointInfo class]]); + test([[ipEndpoint host] isEqualToString:@"tcphost"]); + test(ipEndpoint.port == 10000); + test(ipEndpoint.timeout == 1200); + test([[ipEndpoint sourceAddress] isEqualToString:@"10.10.10.10"]); + test(ipEndpoint.compress); + test(![ipEndpoint datagram]); + test(([ipEndpoint type] == ICETCPEndpointType && ![ipEndpoint secure]) || + ([ipEndpoint type] == ICESSLEndpointType && [ipEndpoint secure]) || + ([ipEndpoint type] == ICEWSEndpointType && ![ipEndpoint secure]) || + ([ipEndpoint type] == ICEWSSEndpointType && [ipEndpoint secure])); + + test(([ipEndpoint type] == ICETCPEndpointType && [ipEndpoint isKindOfClass:[ICETCPEndpointInfo class]]) || + ([ipEndpoint type] == ICESSLEndpointType && [ipEndpoint isKindOfClass:[ICESSLEndpointInfo class]]) || + ([ipEndpoint type] == ICEWSEndpointType && [ipEndpoint isKindOfClass:[ICEWSEndpointInfo class]]) || + ([ipEndpoint type] == ICEWSSEndpointType && [ipEndpoint isKindOfClass:[ICEWSEndpointInfo class]])); + + + endpoint = [endps objectAtIndex:1]; + ICEUDPEndpointInfo<ICEEndpointInfo>* udpEndpoint = (ICEUDPEndpointInfo<ICEEndpointInfo>*)[endpoint getInfo]; + test([udpEndpoint isKindOfClass:[ICEUDPEndpointInfo class]]); + test([udpEndpoint.host isEqualToString:@"udphost"]); + test(udpEndpoint.port == 10001); + test([[udpEndpoint sourceAddress] isEqualToString:@"10.10.10.10"]); + test([udpEndpoint.mcastInterface isEqualToString:@"eth0"]); + test(udpEndpoint.mcastTtl == 5); + test(udpEndpoint.timeout == -1); + test(!udpEndpoint.compress); + test(![udpEndpoint secure]); + test([udpEndpoint datagram]); + test([udpEndpoint type] == ICEUDPEndpointType); + + endpoint = [endps objectAtIndex:2]; + ICEOpaqueEndpointInfo* opaqueEndpoint = (ICEOpaqueEndpointInfo*)[endpoint getInfo]; + test([opaqueEndpoint isKindOfClass:[ICEOpaqueEndpointInfo class]]); + ICEEncodingVersion* rev = ICE_AUTORELEASE([[ICEEncodingVersion alloc] init:1 minor:8]); + test([opaqueEndpoint.rawEncoding isEqual:rev]); + } + tprintf("ok\n"); + + NSString* defaultHost = [[communicator getProperties] getProperty:@"Ice.Default.Host"]; + tprintf("test object adapter endpoint information... "); + { + [[communicator getProperties] setProperty:@"TestAdapter.Endpoints" value:@"default -t 15000:udp"]; + id<ICEObjectAdapter> adapter = [communicator createObjectAdapter:@"TestAdapter"]; + + ICEEndpointSeq* endpoints = [adapter getEndpoints]; + test([endpoints count] == 2); + ICEEndpointSeq* publishedEndpoints = [adapter getPublishedEndpoints]; + test([endpoints isEqualToArray:publishedEndpoints]); + + id<ICEEndpoint> endpoint = [endpoints objectAtIndex:0]; + ICEIPEndpointInfo<ICEEndpointInfo>* ipEndpoint = (ICEIPEndpointInfo<ICEEndpointInfo>*)[endpoint getInfo]; + test([ipEndpoint isKindOfClass:[ICEIPEndpointInfo class]]); + test([ipEndpoint type] == ICETCPEndpointType || [ipEndpoint type] == ICESSLEndpointType || + [ipEndpoint type] == ICEWSEndpointType || [ipEndpoint type] == ICEWSSEndpointType); + test([ipEndpoint.host isEqualToString:defaultHost]); + test(ipEndpoint.port > 0); + test(ipEndpoint.timeout == 15000); + + endpoint = [endpoints objectAtIndex:1]; + ICEUDPEndpointInfo<ICEEndpointInfo>* udpEndpoint = (ICEUDPEndpointInfo<ICEEndpointInfo>*)[endpoint getInfo]; + test([udpEndpoint isKindOfClass:[ICEUDPEndpointInfo class]]); + test([udpEndpoint.host isEqualToString:defaultHost]); + test([udpEndpoint datagram]); + test(udpEndpoint.port > 0); + + [adapter destroy]; + + [[communicator getProperties] setProperty:@"TestAdapter.Endpoints" value:@"default -h * -p 12020"]; + [[communicator getProperties] setProperty:@"TestAdapter.PublishedEndpoints" value:@"default -h 127.0.0.1 -p 12020"]; + adapter = [communicator createObjectAdapter:@"TestAdapter"]; + + endpoints = [adapter getEndpoints]; + test([endpoints count] >= 1); + publishedEndpoints = [adapter getPublishedEndpoints]; + test([publishedEndpoints count] == 1); + + for(id object in endpoints) + { + endpoint = (id<ICEEndpoint>)object; + ipEndpoint = (ICEIPEndpointInfo<ICEEndpointInfo>*)[endpoint getInfo]; + test(ipEndpoint.port == 12020); + } + + ipEndpoint = (ICEIPEndpointInfo<ICEEndpointInfo>*)[[publishedEndpoints objectAtIndex:0] getInfo]; + test([ipEndpoint.host isEqualToString:@"127.0.0.1"]); + test(ipEndpoint.port == 12020); + + [adapter destroy]; + } + tprintf("ok\n"); + + ICEObjectPrx* base = [communicator stringToProxy:@"test:default -p 12010:udp -p 12010"]; + TestInfoTestIntfPrx* testIntf = [TestInfoTestIntfPrx checkedCast:base]; + + tprintf("test connection endpoint information... "); + { + ICEEndpointInfo* info = [[[base ice_getConnection] getEndpoint] getInfo]; + ICEIPEndpointInfo* ipinfo = (ICEIPEndpointInfo*)info; + test([ipinfo isKindOfClass:[ICEIPEndpointInfo class]]); + test(ipinfo.port == 12010); + test(!ipinfo.compress); + test([ipinfo.host isEqualToString:defaultHost]); + + ICEContext* ctx = [testIntf getEndpointInfoAsContext]; + test([[ctx objectForKey:@"host"] isEqualToString:ipinfo.host]); + test([[ctx objectForKey:@"compress"] isEqualToString:@"false"]); + test([[ctx objectForKey:@"port"] intValue] > 0); + + info = [[[[base ice_datagram] ice_getConnection] getEndpoint] getInfo]; + ICEUDPEndpointInfo* udp = (ICEUDPEndpointInfo*)info; + test([udp isKindOfClass:[ICEUDPEndpointInfo class]]); + test(udp.port == 12010); + test([udp.host isEqualToString:defaultHost]); + } + tprintf("ok\n"); + + tprintf("testing connection information... "); + { + id<ICEConnection> connection = [base ice_getConnection]; + [connection setBufferSize:1024 sndSize:2048]; + + ICEIPConnectionInfo* info = (ICEIPConnectionInfo*)[connection getInfo]; + test([info isKindOfClass:[ICEIPConnectionInfo class]]); + test(!info.incoming); + test([info.adapterName isEqualToString:@""]); + test(info.localPort > 0); + test(info.remotePort == 12010); + if([defaultHost isEqualToString:@"127.0.0.1"]) + { + test([info.remoteAddress isEqualToString:defaultHost]); + test([info.localAddress isEqualToString:defaultHost]); + } + test(info.rcvSize >= 1024); + test(info.sndSize >= 2048); + + ICEContext* ctx = [testIntf getConnectionInfoAsContext]; + test([[ctx objectForKey:@"incoming"] isEqualToString:@"true"]); + test([[ctx objectForKey:@"adapterName"] isEqualToString:@"TestAdapter"]); + test([[ctx objectForKey:@"remoteAddress"] isEqualToString:info.remoteAddress]); + test([[ctx objectForKey:@"localAddress"] isEqualToString:info.localAddress]); + test([[ctx objectForKey:@"remotePort"] intValue] == info.localPort); + test([[ctx objectForKey:@"localPort"] intValue] == info.remotePort); + + if([info isKindOfClass:[ICEWSConnectionInfo class]]) + { + ICEWSConnectionInfo* wsinfo = (ICEWSConnectionInfo*)info; + test([[wsinfo.headers objectForKey:@"Upgrade"] isEqualToString:@"websocket"]); + test([[wsinfo.headers objectForKey:@"Connection"] isEqualToString:@"Upgrade"]); + test([[wsinfo.headers objectForKey:@"Sec-WebSocket-Protocol"] isEqualToString:@"ice.zeroc.com"]); + test([wsinfo.headers objectForKey:@"Sec-WebSocket-Accept"] != nil); + + test([[ctx objectForKey:@"ws.Upgrade"] isEqualToString:@"websocket"]); + test([[ctx objectForKey:@"ws.Connection"] isEqualToString:@"Upgrade"]); + test([[ctx objectForKey:@"ws.Sec-WebSocket-Protocol"] isEqualToString:@"ice.zeroc.com"]); + test([[ctx objectForKey:@"ws.Sec-WebSocket-Version"] isEqualToString:@"13"]); + test([ctx objectForKey:@"ws.Sec-WebSocket-Key"] != nil); + } + + connection = [[base ice_datagram] ice_getConnection]; + [connection setBufferSize:2048 sndSize:1024]; + + info = (ICEIPConnectionInfo*)[connection getInfo]; + test([info isKindOfClass:[ICEIPConnectionInfo class]]); + test(!info.incoming); + test([info.adapterName isEqualToString:@""]); + test(info.localPort > 0); + test(info.remotePort == 12010); + if([defaultHost isEqualToString:@"127.0.0.1"]) + { + test([info.remoteAddress isEqualToString:defaultHost]); + test([info.localAddress isEqualToString:defaultHost]); + } + test(info.rcvSize >= 2048); + test(info.sndSize >= 1024); + } + tprintf("ok\n"); + + return testIntf; +} diff --git a/objective-c/test/Ice/info/Client.m b/objective-c/test/Ice/info/Client.m new file mode 100644 index 00000000000..7b9dc2e9b72 --- /dev/null +++ b/objective-c/test/Ice/info/Client.m @@ -0,0 +1,73 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution.. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <TestCommon.h> +#import <InfoTest.h> + +static int +run(id<ICECommunicator> communicator) +{ + TestInfoTestIntfPrx* infoAllTests(id<ICECommunicator>); + TestInfoTestIntfPrx* intf = infoAllTests(communicator); + + [intf shutdown]; + + return EXIT_SUCCESS; +} + +#if TARGET_OS_IPHONE +# define main infoClient +#endif + +int +main(int argc, char* argv[]) +{ + int status; + @autoreleasepool + { + id<ICECommunicator> communicator = nil; + + @try + { + ICEInitializationData* initData = [ICEInitializationData initializationData]; + initData.properties = defaultClientProperties(&argc, argv); +#if TARGET_OS_IPHONE + initData.prefixTable__ = [NSDictionary dictionaryWithObjectsAndKeys: + @"TestInfo", @"::Test", + nil]; +#endif + communicator = [ICEUtil createCommunicator:&argc argv:argv initData:initData]; + status = run(communicator); + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + @catch(TestFailedException* ex) + { + status = EXIT_FAILURE; + } + + if(communicator) + { + @try + { + [communicator destroy]; + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + } + } + return status; +} diff --git a/objective-c/test/Ice/info/InfoTest.ice b/objective-c/test/Ice/info/InfoTest.ice new file mode 100644 index 00000000000..fc209177419 --- /dev/null +++ b/objective-c/test/Ice/info/InfoTest.ice @@ -0,0 +1,27 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#pragma once + +#include <Ice/Current.ice> + +["objc:prefix:TestInfo"] +module Test +{ + +interface TestIntf +{ + void shutdown(); + + Ice::Context getEndpointInfoAsContext(); + + Ice::Context getConnectionInfoAsContext(); +}; + +}; diff --git a/objective-c/test/Ice/info/Makefile b/objective-c/test/Ice/info/Makefile new file mode 100644 index 00000000000..5c5a231ecc6 --- /dev/null +++ b/objective-c/test/Ice/info/Makefile @@ -0,0 +1,37 @@ +# ********************************************************************** +# +# Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +# +# This copy of Ice is licensed to you under the terms described in the +# ICE_LICENSE file included in this distribution. +# +# ********************************************************************** + +top_srcdir = ../../.. + +CLIENT = client +SERVER = server + +TARGETS = $(CLIENT) $(SERVER) + +SLICE_OBJS = InfoTest.o + +COBJS = Client.o \ + AllTests.o + +SOBJS = TestI.o \ + Server.o + +OBJS = $(COBJS) $(SOBJS) $(SLICE_OBJS) + +include $(top_srcdir)/config/Make.rules + +CPPFLAGS := -I. -I.. -I../../include $(CPPFLAGS) + +$(CLIENT): $(COBJS) $(SLICE_OBJS) + rm -f $@ + $(CXX) $(LDFLAGS) $(LDEXEFLAGS) -o $@ $(COBJS) $(SLICE_OBJS) $(ICESSL_LIBS) $(TEST_LIBS) + +$(SERVER): $(SOBJS) $(SLICE_OBJS) + rm -f $@ + $(CXX) $(LDFLAGS) $(LDEXEFLAGS) -o $@ $(SOBJS) $(SLICE_OBJS) $(ICESSL_LIBS) $(TEST_LIBS) diff --git a/objective-c/test/Ice/info/Server.m b/objective-c/test/Ice/info/Server.m new file mode 100644 index 00000000000..d93eea40179 --- /dev/null +++ b/objective-c/test/Ice/info/Server.m @@ -0,0 +1,72 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <info/TestI.h> +#import <TestCommon.h> + +static int +run(id<ICECommunicator> communicator) +{ + [[communicator getProperties] setProperty:@"TestAdapter.Endpoints" value:@"default -p 12010:udp"]; + id<ICEObjectAdapter> adapter = [communicator createObjectAdapter:@"TestAdapter"]; + [adapter add:[TestInfoTestIntfI testIntf] identity:[communicator stringToIdentity:@"test"]]; + [adapter activate]; + + serverReady(communicator); + + [communicator waitForShutdown]; + return EXIT_SUCCESS; +} + +#if TARGET_OS_IPHONE +# define main infoServer +#endif + +int +main(int argc, char* argv[]) +{ + int status; + @autoreleasepool + { + id<ICECommunicator> communicator = nil; + + @try + { + ICEInitializationData* initData = [ICEInitializationData initializationData]; + initData.properties = defaultServerProperties(&argc, argv); +#if TARGET_OS_IPHONE + initData.prefixTable__ = [NSDictionary dictionaryWithObjectsAndKeys: + @"TestProxy", @"::Test", + nil]; +#endif + communicator = [ICEUtil createCommunicator:&argc argv:argv initData:initData]; + status = run(communicator); + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + + if(communicator) + { + @try + { + [communicator destroy]; + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + } + } + return status; +} diff --git a/objective-c/test/Ice/info/TestI.h b/objective-c/test/Ice/info/TestI.h new file mode 100644 index 00000000000..9c30ba2081e --- /dev/null +++ b/objective-c/test/Ice/info/TestI.h @@ -0,0 +1,19 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <InfoTest.h> + +@interface TestInfoTestIntfI : TestInfoTestIntf<TestInfoTestIntf> +{ +} + +-(void) shutdown:(ICECurrent*)current; +-(ICEContext*) getEndpointInfoAsContext:(ICECurrent*)current; +-(ICEContext*) getConnectionInfoAsContext:(ICECurrent*)current; +@end diff --git a/objective-c/test/Ice/info/TestI.m b/objective-c/test/Ice/info/TestI.m new file mode 100644 index 00000000000..cbc6a257664 --- /dev/null +++ b/objective-c/test/Ice/info/TestI.m @@ -0,0 +1,68 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <info/TestI.h> +#import <TestCommon.h> + +@implementation TestInfoTestIntfI + + +-(void) shutdown:(ICECurrent*)c +{ + [[[c adapter] getCommunicator] shutdown]; +} + +-(ICEContext*) getEndpointInfoAsContext:(ICECurrent*)current +{ + id<ICEEndpoint> endpoint = [current.con getEndpoint]; + ICEEndpointInfo<ICEEndpointInfo>* info = [endpoint getInfo]; + + ICEMutableContext* ctx = [ICEMutableContext dictionaryWithObject:[NSString stringWithFormat:@"%d", [info timeout]] + forKey:@"timeout"]; + + [ctx setObject:info.compress ? @"true" : @"false" forKey:@"compress"]; + [ctx setObject:[info datagram] ? @"true" : @"false" forKey:@"datagram"]; + [ctx setObject:[info secure] ? @"true" : @"false" forKey:@"secure"]; + [ctx setObject:[NSString stringWithFormat:@"%d", [info type]] forKey:@"type"]; + + ICEIPEndpointInfo* ipinfo = (ICEIPEndpointInfo*)info; + [ctx setObject:ipinfo.host forKey:@"host"]; + [ctx setObject:[NSString stringWithFormat:@"%d", ipinfo.port] forKey:@"port"]; + + if([ipinfo isKindOfClass:[ICEUDPEndpointInfo class]]) + { + ICEUDPEndpointInfo* udp = (ICEUDPEndpointInfo*)ipinfo; + [ctx setObject:udp.mcastInterface forKey:@"mcastInterface"]; + [ctx setObject:[NSString stringWithFormat:@"%d", udp.mcastTtl] forKey:@"mcastTtl"]; + } + return ctx; +} + +-(ICEContext*) getConnectionInfoAsContext:(ICECurrent*)current +{ + ICEConnectionInfo* info = [[current con] getInfo]; + ICEMutableContext* ctx = [ICEMutableContext dictionaryWithObject:[info adapterName] forKey:@"adapterName"]; + [ctx setObject:info.incoming ? @"true" : @"false" forKey:@"incoming"]; + ICEIPConnectionInfo* ipinfo = (ICEIPConnectionInfo*)info; + [ctx setObject:ipinfo.localAddress forKey:@"localAddress"]; + [ctx setObject:[NSString stringWithFormat:@"%d", ipinfo.localPort] forKey:@"localPort"]; + [ctx setObject:ipinfo.remoteAddress forKey:@"remoteAddress"]; + [ctx setObject:[NSString stringWithFormat:@"%d", ipinfo.remotePort] forKey:@"remotePort"]; + if([info isKindOfClass:[ICEWSConnectionInfo class]]) + { + ICEWSConnectionInfo* wsinfo = (ICEWSConnectionInfo*)info; + for(NSString* key in wsinfo.headers) + { + [ctx setObject:[wsinfo.headers objectForKey:key] forKey:[NSString stringWithFormat:@"ws.%@", key]]; + } + } + return ctx; +} +@end diff --git a/objective-c/test/Ice/info/run.py b/objective-c/test/Ice/info/run.py new file mode 100755 index 00000000000..ce8c5dd4b18 --- /dev/null +++ b/objective-c/test/Ice/info/run.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python +# ********************************************************************** +# +# Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +# +# This copy of Ice is licensed to you under the terms described in the +# ICE_LICENSE file included in this distribution. +# +# ********************************************************************** + +import os, sys + +path = [ ".", "..", "../..", "../../..", "../../../..", "../../../../.." ] +head = os.path.dirname(sys.argv[0]) +if len(head) > 0: + path = [os.path.join(head, p) for p in path] +path = [os.path.abspath(p) for p in path if os.path.exists(os.path.join(p, "scripts", "TestUtil.py")) ] +if len(path) == 0: + raise RuntimeError("can't find toplevel directory!") +sys.path.append(os.path.join(path[0], "scripts")) +import TestUtil + +TestUtil.clientServerTest() diff --git a/objective-c/test/Ice/inheritance/.gitignore b/objective-c/test/Ice/inheritance/.gitignore new file mode 100644 index 00000000000..400a2a0d5c4 --- /dev/null +++ b/objective-c/test/Ice/inheritance/.gitignore @@ -0,0 +1,9 @@ +// Generated by makegitignore.py + +// IMPORTANT: Do not edit this file -- any edits made here will be lost! +client +server +collocated +.depend +InheritanceTest.m +InheritanceTest.h diff --git a/objective-c/test/Ice/inheritance/AllTests.m b/objective-c/test/Ice/inheritance/AllTests.m new file mode 100644 index 00000000000..546aac37184 --- /dev/null +++ b/objective-c/test/Ice/inheritance/AllTests.m @@ -0,0 +1,222 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <TestCommon.h> +#import <InheritanceTest.h> + + +id<TestInheritanceInitialPrx> +inheritanceAllTests(id<ICECommunicator> communicator) +{ + tprintf("testing stringToProxy... "); + NSString* ref = @"initial:default -p 12010"; + id<ICEObjectPrx> base = [communicator stringToProxy:ref]; + test(base); + tprintf("ok\n"); + + tprintf("testing checked cast... "); + id<TestInheritanceInitialPrx> initial = [TestInheritanceInitialPrx checkedCast:base]; + test(initial); + test([initial isEqual:base]); + tprintf("ok\n"); + + tprintf("getting proxies for class hierarchy... "); + id<TestInheritanceMACAPrx> ca = [initial caop]; + id<TestInheritanceMBCBPrx> cb = [initial cbop]; + id<TestInheritanceMACCPrx> cc = [initial ccop]; + id<TestInheritanceMACDPrx> cd = [initial cdop]; + test(ca != cb); + test(ca != cc); + test(ca != cd); + test(cb != cc); + test(cb != cd); + test(cc != cd); + tprintf("ok\n"); + + tprintf("getting proxies for interface hierarchy... "); + id<TestInheritanceMAIAPrx> ia = [initial iaop]; + id<TestInheritanceMBIB1Prx> ib1 = [initial ib1op]; + id<TestInheritanceMBIB2Prx> ib2 = [initial ib2op]; + id<TestInheritanceMAICPrx> ic = [initial icop]; + test(ia != ib1); + test(ia != ib2); + test(ia != ic); + test(ib1 != ic); + test(ib2 != ic); + tprintf("ok\n"); + + tprintf("invoking proxy operations on class hierarchy... "); + id<TestInheritanceMACAPrx> cao; + id<TestInheritanceMBCBPrx> cbo; + id<TestInheritanceMACCPrx> cco; + + cao = [ca caop:ca]; + test([cao isEqual:ca]); + cao = [ca caop:cb]; + test([cao isEqual:cb]); + cao = [ca caop:cc]; + test([cao isEqual:cc]); + cao = [cb caop:ca]; + test([cao isEqual:ca]); + cao = [cb caop:cb]; + test([cao isEqual:cb]); + cao = [cb caop:cc]; + test([cao isEqual:cc]); + cao = [cc caop:ca]; + test([cao isEqual:ca]); + cao = [cc caop:cb]; + test([cao isEqual:cb]); + cao = [cc caop:cc]; + test([cao isEqual:cc]); + + cao = [cb cbop:cb]; + test([cao isEqual:cb]); + cbo = [cb cbop:cb]; + test([cbo isEqual:cb]); + cao = [cb cbop:cc]; + test([cao isEqual:cc]); + cbo = [cb cbop:cc]; + test([cbo isEqual:cc]); + cao = [cc cbop:cb]; + test([cao isEqual:cb]); + cbo = [cc cbop:cb]; + test([cbo isEqual:cb]); + cao = [cc cbop:cc]; + test([cao isEqual:cc]); + cbo = [cc cbop:cc]; + test([cbo isEqual:cc]); + + cao = [cc ccop:cc]; + test([cao isEqual:cc]); + cbo = [cc ccop:cc]; + test([cbo isEqual:cc]); + cco = [cc ccop:cc]; + test([cco isEqual:cc]); + tprintf("ok\n"); + + tprintf("ditto, but for interface hierarchy... "); + id<TestInheritanceMAIAPrx> iao; + id<TestInheritanceMBIB1Prx> ib1o; + id<TestInheritanceMBIB2Prx> ib2o; + id<TestInheritanceMAICPrx> ico; + + iao = [ia iaop:ia]; + test([iao isEqual:ia]); + iao = [ia iaop:ib1]; + test([iao isEqual:ib1]); + iao = [ia iaop:ib2]; + test([iao isEqual:ib2]); + iao = [ia iaop:ic]; + test([iao isEqual:ic]); + iao = [ib1 iaop:ia]; + test([iao isEqual:ia]); + iao = [ib1 iaop:ib1]; + test([iao isEqual:ib1]); + iao = [ib1 iaop:ib2]; + test([iao isEqual:ib2]); + iao = [ib1 iaop:ic]; + test([iao isEqual:ic]); + iao = [ib2 iaop:ia]; + test([iao isEqual:ia]); + iao = [ib2 iaop:ib1]; + test([iao isEqual:ib1]); + iao = [ib2 iaop:ib2]; + test([iao isEqual:ib2]); + iao = [ib2 iaop:ic]; + test([iao isEqual:ic]); + iao = [ic iaop:ia]; + test([iao isEqual:ia]); + iao = [ic iaop:ib1]; + test([iao isEqual:ib1]); + iao = [ic iaop:ib2]; + test([iao isEqual:ib2]); + iao = [ic iaop:ic]; + test([iao isEqual:ic]); + + iao = [ib1 ib1op:ib1]; + test([iao isEqual:ib1]); + ib1o = [ib1 ib1op:ib1]; + test([ib1o isEqual:ib1]); + iao = [ib1 ib1op:ic]; + test([iao isEqual:ic]); + ib1o = [ib1 ib1op:ic]; + test([ib1o isEqual:ic]); + iao = [ic ib1op:ib1]; + test([iao isEqual:ib1]); + ib1o = [ic ib1op:ib1]; + test([ib1o isEqual:ib1]); + iao = [ic ib1op:ic]; + test([iao isEqual:ic]); + ib1o = [ic ib1op:ic]; + test([ib1o isEqual:ic]); + + iao = [ib2 ib2op:ib2]; + test([iao isEqual:ib2]); + ib2o = [ib2 ib2op:ib2]; + test([ib2o isEqual:ib2]); + iao = [ib2 ib2op:ic]; + test([iao isEqual:ic]); + ib2o = [ib2 ib2op:ic]; + test([ib2o isEqual:ic]); + iao = [ic ib2op:ib2]; + test([iao isEqual:ib2]); + ib2o = [ic ib2op:ib2]; + test([ib2o isEqual:ib2]); + iao = [ic ib2op:ic]; + test([iao isEqual:ic]); + ib2o = [ic ib2op:ic]; + test([ib2o isEqual:ic]); + + iao = [ic icop:ic]; + test([iao isEqual:ic]); + ib1o = [ic icop:ic]; + test([ib1o isEqual:ic]); + ib2o = [ic icop:ic]; + test([ib2o isEqual:ic]); + ico = [ic icop:ic]; + test([ico isEqual:ic]); + + tprintf("ok\n"); + + tprintf("ditto, but for class implementing interfaces... "); +// id<TestInheritanceMACDPrx> cdo; + + cao = [cd caop:cd]; + test([cao isEqual:cd]); + cbo = [cd cbop:cd]; + test([cbo isEqual:cd]); + cco = [cd ccop:cd]; + test([cco isEqual:cd]); + + iao = [cd iaop:cd]; + test([iao isEqual:cd]); + ib1o = [cd ib1op:cd]; + test([ib1o isEqual:cd]); + ib2o = [cd ib2op:cd]; + test([ib2o isEqual:cd]); + + cao = [cd cdop:cd]; + test([cao isEqual:cd]); + cbo = [cd cdop:cd]; + test([cbo isEqual:cd]); + cco = [cd cdop:cd]; + test([cco isEqual:cd]); + + iao = [cd cdop:cd]; + test([iao isEqual:cd]); + ib1o = [cd cdop:cd]; + test([ib1o isEqual:cd]); + ib2o = [cd cdop:cd]; + test([ib2o isEqual:cd]); + + tprintf("ok\n"); + + return initial; +} diff --git a/objective-c/test/Ice/inheritance/Client.m b/objective-c/test/Ice/inheritance/Client.m new file mode 100644 index 00000000000..61e79feab68 --- /dev/null +++ b/objective-c/test/Ice/inheritance/Client.m @@ -0,0 +1,71 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <TestCommon.h> +#import <InheritanceTest.h> + +static int +run(id<ICECommunicator> communicator) +{ + id<TestInheritanceInitialPrx> inheritanceAllTests(id<ICECommunicator>); + id<TestInheritanceInitialPrx> initial = inheritanceAllTests(communicator); + [initial shutdown]; + return EXIT_SUCCESS; +} + +#if TARGET_OS_IPHONE +# define main inheritanceClient +#endif + +int +main(int argc, char* argv[]) +{ + int status; + @autoreleasepool + { + id<ICECommunicator> communicator = nil; + + @try + { + ICEInitializationData* initData = [ICEInitializationData initializationData]; + initData.properties = defaultClientProperties(&argc, argv); +#if TARGET_OS_IPHONE + initData.prefixTable__ = [NSDictionary dictionaryWithObjectsAndKeys: + @"TestInheritance", @"::Test", + nil]; +#endif + communicator = [ICEUtil createCommunicator:&argc argv:argv initData:initData]; + status = run(communicator); + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + @catch(TestFailedException* ex) + { + status = EXIT_FAILURE; + } + + if(communicator) + { + @try + { + [communicator destroy]; + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + } + } + return status; +} diff --git a/objective-c/test/Ice/inheritance/Collocated.m b/objective-c/test/Ice/inheritance/Collocated.m new file mode 100644 index 00000000000..d851e2fb3e3 --- /dev/null +++ b/objective-c/test/Ice/inheritance/Collocated.m @@ -0,0 +1,72 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <inheritance/TestI.h> +#import <TestCommon.h> + +static int +run(id<ICECommunicator> communicator) +{ + [[communicator getProperties] setProperty:@"TestAdapter.Endpoints" value:@"default -p 12010"]; + id<ICEObjectAdapter> adapter = [communicator createObjectAdapter:@"TestAdapter"]; + ICEObject* object = ICE_AUTORELEASE([[TestInheritanceInitialI alloc] initWithAdapter:adapter]); + [adapter add:object identity:[communicator stringToIdentity:@"initial"]]; + + id<TestInheritanceInitialPrx> inheritanceAllTests(id<ICECommunicator>); + inheritanceAllTests(communicator); + + return EXIT_SUCCESS; +} + +#if TARGET_OS_IPHONE +# define main inheritanceServer +#endif + +int +main(int argc, char* argv[]) +{ + int status; + @autoreleasepool + { + id<ICECommunicator> communicator = nil; + + @try + { + ICEInitializationData* initData = [ICEInitializationData initializationData]; + initData.properties = defaultServerProperties(&argc, argv); +#if TARGET_OS_IPHONE + initData.prefixTable__ = [NSDictionary dictionaryWithObjectsAndKeys: + @"TestInheritance", @"::Test", + nil]; +#endif + communicator = [ICEUtil createCommunicator:&argc argv:argv initData:initData]; + status = run(communicator); + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + + if(communicator) + { + @try + { + [communicator destroy]; + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + } + } + return status; +} diff --git a/objective-c/test/Ice/inheritance/InheritanceTest.ice b/objective-c/test/Ice/inheritance/InheritanceTest.ice new file mode 100644 index 00000000000..84d41d9e571 --- /dev/null +++ b/objective-c/test/Ice/inheritance/InheritanceTest.ice @@ -0,0 +1,87 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#pragma once + +["objc:prefix:TestInheritance"] +module Test +{ + +["objc:prefix:TestInheritanceMA"] +module MA +{ + +interface IA +{ + IA* iaop(IA* p); +}; + +class CA +{ + CA* caop(CA* p); +}; + +}; + +["objc:prefix:TestInheritanceMB"] +module MB +{ + +interface IB1 extends MA::IA +{ + IB1* ib1op(IB1* p); +}; + +interface IB2 extends MA::IA +{ + IB2* ib2op(IB2* p); +}; + +class CB extends MA::CA +{ + CB* cbop(CB* p); +}; + +}; + +["objc:prefix:TestInheritanceMA"] +module MA +{ + +interface IC extends MB::IB1, MB::IB2 +{ + IC* icop(IC* p); +}; + +class CC extends MB::CB +{ + CC* ccop(CC* p); +}; + +class CD extends CC implements MB::IB1, MB::IB2 +{ + CD* cdop(CD* p); +}; + +}; + +interface Initial +{ + void shutdown(); + MA::CA* caop(); + MB::CB* cbop(); + MA::CC* ccop(); + MA::CD* cdop(); + MA::IA* iaop(); + MB::IB1* ib1op(); + MB::IB2* ib2op(); + MA::IC* icop(); +}; + +}; diff --git a/objective-c/test/Ice/inheritance/Makefile b/objective-c/test/Ice/inheritance/Makefile new file mode 100644 index 00000000000..19c3ee7806a --- /dev/null +++ b/objective-c/test/Ice/inheritance/Makefile @@ -0,0 +1,46 @@ +# ********************************************************************** +# +# Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +# +# This copy of Ice is licensed to you under the terms described in the +# ICE_LICENSE file included in this distribution. +# +# ********************************************************************** + +top_srcdir = ../../.. + +CLIENT = client +SERVER = server +COLLOCATED = collocated + +TARGETS = $(CLIENT) $(SERVER) $(COLLOCATED) + +SLICE_OBJS = InheritanceTest.o + +COBJS = Client.o \ + AllTests.o + +SOBJS = TestI.o \ + Server.o + +COLOBJS = Collocated.o \ + TestI.o \ + AllTests.o + +OBJS = $(COBJS) $(SOBJS) $(SLICE_OBJS) + +include $(top_srcdir)/config/Make.rules + +CPPFLAGS := -I. -I.. -I../../include $(CPPFLAGS) + +$(CLIENT): $(COBJS) $(SLICE_OBJS) + rm -f $@ + $(CXX) $(LDFLAGS) $(LDEXEFLAGS) -o $@ $(COBJS) $(SLICE_OBJS) $(TEST_LIBS) + +$(SERVER): $(SOBJS) $(SLICE_OBJS) + rm -f $@ + $(CXX) $(LDFLAGS) $(LDEXEFLAGS) -o $@ $(SOBJS) $(SLICE_OBJS) $(TEST_LIBS) + +$(COLLOCATED): $(COLOBJS) $(SLICE_OBJS) + rm -f $@ + $(CXX) $(LDFLAGS) $(LDEXEFLAGS) -o $@ $(COLOBJS) $(SLICE_OBJS) $(TEST_LIBS) diff --git a/objective-c/test/Ice/inheritance/Server.m b/objective-c/test/Ice/inheritance/Server.m new file mode 100644 index 00000000000..3d9fb79d3d8 --- /dev/null +++ b/objective-c/test/Ice/inheritance/Server.m @@ -0,0 +1,73 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <inheritance/TestI.h> +#import <TestCommon.h> + +static int +run(id<ICECommunicator> communicator) +{ + [[communicator getProperties] setProperty:@"TestAdapter.Endpoints" value:@"default -p 12010"]; + id<ICEObjectAdapter> adapter = [communicator createObjectAdapter:@"TestAdapter"]; + ICEObject* object = ICE_AUTORELEASE([[TestInheritanceInitialI alloc] initWithAdapter:adapter]); + [adapter add:object identity:[communicator stringToIdentity:@"initial"]]; + [adapter activate]; + + serverReady(communicator); + + [communicator waitForShutdown]; + return EXIT_SUCCESS; +} + +#if TARGET_OS_IPHONE +# define main inheritanceServer +#endif + +int +main(int argc, char* argv[]) +{ + int status; + @autoreleasepool + { + id<ICECommunicator> communicator = nil; + + @try + { + ICEInitializationData* initData = [ICEInitializationData initializationData]; + initData.properties = defaultServerProperties(&argc, argv); +#if TARGET_OS_IPHONE + initData.prefixTable__ = [NSDictionary dictionaryWithObjectsAndKeys: + @"TestInheritance", @"::Test", + nil]; +#endif + communicator = [ICEUtil createCommunicator:&argc argv:argv initData:initData]; + status = run(communicator); + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + + if(communicator) + { + @try + { + [communicator destroy]; + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + } + } + return status; +} diff --git a/objective-c/test/Ice/inheritance/TestI.h b/objective-c/test/Ice/inheritance/TestI.h new file mode 100644 index 00000000000..29cb798e6b0 --- /dev/null +++ b/objective-c/test/Ice/inheritance/TestI.h @@ -0,0 +1,50 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <InheritanceTest.h> + +@interface TestInheritanceInitialI : TestInheritanceInitial<TestInheritanceInitial> +{ + id<ICEObjectAdapter> adapter_; + id<TestInheritanceMACAPrx> ca_; + id<TestInheritanceMBCBPrx> cb_; + id<TestInheritanceMACCPrx> cc_; + id<TestInheritanceMACDPrx> cd_; + id<TestInheritanceMAIAPrx> ia_; + id<TestInheritanceMBIB1Prx> ib1_; + id<TestInheritanceMBIB2Prx> ib2_; + id<TestInheritanceMAICPrx> ic_; +} +-(id)initWithAdapter:(id<ICEObjectAdapter>) adapter; +@end + +@interface CAI : TestInheritanceMACA<TestInheritanceMACA> +@end + +@interface CBI : TestInheritanceMBCB<TestInheritanceMBCB> +@end + +@interface CCI : TestInheritanceMACC<TestInheritanceMACC> +@end + +@interface IAI : TestInheritanceMAIA<TestInheritanceMAIA> +@end + +@interface IB1I : TestInheritanceMBIB1<TestInheritanceMBIB1> +@end + +@interface IB2I : TestInheritanceMBIB2<TestInheritanceMBIB2> +@end + +@interface ICI : TestInheritanceMAIC<TestInheritanceMAIC> +@end + +@interface CDI : TestInheritanceMACD<TestInheritanceMACD> +@end + diff --git a/objective-c/test/Ice/inheritance/TestI.m b/objective-c/test/Ice/inheritance/TestI.m new file mode 100644 index 00000000000..a1fd4e0badf --- /dev/null +++ b/objective-c/test/Ice/inheritance/TestI.m @@ -0,0 +1,188 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <inheritance/TestI.h> + +@implementation CAI +-(id<TestInheritanceMACAPrx>) caop:(id<TestInheritanceMACAPrx>)p current:(ICECurrent*)current +{ + return p; +} +@end + +@implementation CBI +-(id<TestInheritanceMACAPrx>) caop:(id<TestInheritanceMACAPrx>)p current:(ICECurrent*)current +{ + return p; +} +-(id<TestInheritanceMBCBPrx>) cbop:(id<TestInheritanceMBCBPrx>)p current:(ICECurrent*)current +{ + return p; +} +@end + +@implementation CCI +-(id<TestInheritanceMACAPrx>) caop:(id<TestInheritanceMACAPrx>)p current:(ICECurrent*)current +{ + return p; +} +-(id<TestInheritanceMBCBPrx>) cbop:(id<TestInheritanceMBCBPrx>)p current:(ICECurrent*)current +{ + return p; +} +-(id<TestInheritanceMACCPrx>) ccop:(id<TestInheritanceMACCPrx>)p current:(ICECurrent*)current +{ + return p; +} +@end + +@implementation IAI +-(id<TestInheritanceMAIAPrx>) iaop:(id<TestInheritanceMAIAPrx>)p current:(ICECurrent*)current +{ + return p; +} +@end + +@implementation IB1I +-(id<TestInheritanceMAIAPrx>) iaop:(id<TestInheritanceMAIAPrx>)p current:(ICECurrent*)current +{ + return p; +} +-(id<TestInheritanceMBIB1Prx>) ib1op:(id<TestInheritanceMBIB1Prx>)p current:(ICECurrent*)current +{ + return p; +} +@end + +@implementation IB2I +-(id<TestInheritanceMAIAPrx>) iaop:(id<TestInheritanceMAIAPrx>)p current:(ICECurrent*)current +{ + return p; +} +-(id<TestInheritanceMBIB2Prx>) ib2op:(id<TestInheritanceMBIB2Prx>)p current:(ICECurrent*)current +{ + return p; +} +@end + +@implementation ICI +-(id<TestInheritanceMAIAPrx>) iaop:(id<TestInheritanceMAIAPrx>)p current:(ICECurrent*)current +{ + return p; +} +-(id<TestInheritanceMBIB1Prx>) ib1op:(id<TestInheritanceMBIB1Prx>)p current:(ICECurrent*)current +{ + return p; +} +-(id<TestInheritanceMBIB2Prx>) ib2op:(id<TestInheritanceMBIB2Prx>)p current:(ICECurrent*)current +{ + return p; +} +-(id<TestInheritanceMAICPrx>) icop:(id<TestInheritanceMAICPrx>)p current:(ICECurrent*)current +{ + return p; +} +@end + +@implementation CDI +-(id<TestInheritanceMACAPrx>) caop:(id<TestInheritanceMACAPrx>)p current:(ICECurrent*)current +{ + return p; +} +-(id<TestInheritanceMBCBPrx>) cbop:(id<TestInheritanceMBCBPrx>)p current:(ICECurrent*)current +{ + return p; +} +-(id<TestInheritanceMACCPrx>) ccop:(id<TestInheritanceMACCPrx>)p current:(ICECurrent*)current +{ + return p; +} +-(id<TestInheritanceMACDPrx>) cdop:(id<TestInheritanceMACDPrx>)p current:(ICECurrent*)current +{ + return p; +} +-(id<TestInheritanceMAIAPrx>) iaop:(id<TestInheritanceMAIAPrx>)p current:(ICECurrent*)current +{ + return p; +} +-(id<TestInheritanceMBIB1Prx>) ib1op:(id<TestInheritanceMBIB1Prx>)p current:(ICECurrent*)current +{ + return p; +} +-(id<TestInheritanceMBIB2Prx>) ib2op:(id<TestInheritanceMBIB2Prx>)p current:(ICECurrent*)current +{ + return p; +} +@end + +@implementation TestInheritanceInitialI +-(id) initWithAdapter:(id<ICEObjectAdapter>)adapter +{ + self = [super init]; + if(!self) + { + return nil; + } + ca_ = [TestInheritanceMACAPrx uncheckedCast:[adapter addWithUUID:[CAI ca]]]; + cb_ = [TestInheritanceMBCBPrx uncheckedCast:[adapter addWithUUID:[CBI cb]]]; + cc_ = [TestInheritanceMACCPrx uncheckedCast:[adapter addWithUUID:[CCI cc]]]; + cd_ = [TestInheritanceMACDPrx uncheckedCast:[adapter addWithUUID:[CDI cd]]]; + ia_ = [TestInheritanceMAIAPrx uncheckedCast:[adapter addWithUUID:[IAI ia]]]; + ib1_ = [TestInheritanceMBIB1Prx uncheckedCast:[adapter addWithUUID:[IB1I ib1]]]; + ib2_ = [TestInheritanceMBIB2Prx uncheckedCast:[adapter addWithUUID:[IB2I ib2]]]; + ic_ = [TestInheritanceMAICPrx uncheckedCast:[adapter addWithUUID:[ICI ic]]]; + + return self; +} +-(void) shutdown:(ICECurrent*)current +{ + [[current.adapter getCommunicator] shutdown]; +} + +-(id<TestInheritanceMACAPrx>) caop:(ICECurrent*)current +{ + return ca_; +} + +-(id<TestInheritanceMBCBPrx>) cbop:(ICECurrent*)current +{ + return cb_; +} + +-(id<TestInheritanceMACCPrx>) ccop:(ICECurrent*)current +{ + return cc_; +} + +-(id<TestInheritanceMACDPrx>) cdop:(ICECurrent*)current +{ + return cd_; +} + +-(id<TestInheritanceMAIAPrx>) iaop:(ICECurrent*)current +{ + return ia_; +} + +-(id<TestInheritanceMBIB1Prx>) ib1op:(ICECurrent*)current +{ + return ib1_; +} + +-(id<TestInheritanceMBIB2Prx>) ib2op:(ICECurrent*)current +{ + return ib2_; +} + +-(id<TestInheritanceMAICPrx>) icop:(ICECurrent*)current +{ + return ic_; +} +@end diff --git a/objective-c/test/Ice/inheritance/run.py b/objective-c/test/Ice/inheritance/run.py new file mode 100755 index 00000000000..0816938a196 --- /dev/null +++ b/objective-c/test/Ice/inheritance/run.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python +# ********************************************************************** +# +# Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +# +# This copy of Ice is licensed to you under the terms described in the +# ICE_LICENSE file included in this distribution. +# +# ********************************************************************** + +import os, sys + +path = [ ".", "..", "../..", "../../..", "../../../..", "../../../../.." ] +head = os.path.dirname(sys.argv[0]) +if len(head) > 0: + path = [os.path.join(head, p) for p in path] +path = [os.path.abspath(p) for p in path if os.path.exists(os.path.join(p, "scripts", "TestUtil.py")) ] +if len(path) == 0: + raise RuntimeError("can't find toplevel directory!") +sys.path.append(os.path.join(path[0], "scripts")) +import TestUtil + +print("tests with regular server.") +TestUtil.clientServerTest() +print("tests with collocated server.") +TestUtil.collocatedTest() diff --git a/objective-c/test/Ice/interceptor/.gitignore b/objective-c/test/Ice/interceptor/.gitignore new file mode 100644 index 00000000000..a7aee74ccef --- /dev/null +++ b/objective-c/test/Ice/interceptor/.gitignore @@ -0,0 +1,7 @@ +// Generated by makegitignore.py + +// IMPORTANT: Do not edit this file -- any edits made here will be lost! +client +.depend +InterceptorTest.m +InterceptorTest.h diff --git a/objective-c/test/Ice/interceptor/Client.m b/objective-c/test/Ice/interceptor/Client.m new file mode 100644 index 00000000000..520852aacbd --- /dev/null +++ b/objective-c/test/Ice/interceptor/Client.m @@ -0,0 +1,156 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <TestCommon.h> +#import <InterceptorTest.h> +#import <interceptor/MyObjectI.h> +#import <interceptor/InterceptorI.h> + +static int +run(id<ICECommunicator> communicator) +{ + // + // Create OA and servants + // + id<ICEObjectAdapter> oa = [communicator createObjectAdapterWithEndpoints:@"MyOA" endpoints:@"tcp -h localhost"]; + ICEObject* servant = [TestInterceptorMyObjectI myObject]; + InterceptorI* interceptor = ICE_AUTORELEASE([[InterceptorI alloc] init:servant]); + + id<TestInterceptorMyObjectPrx> prx = [TestInterceptorMyObjectPrx uncheckedCast:[oa addWithUUID:interceptor]]; + + [oa activate]; + + tprintf("testing simple interceptor... "); + test([[interceptor getLastOperation] length] == 0); + [prx ice_ping]; + test([[interceptor getLastOperation] isEqualToString:@"ice_ping"]); + test([interceptor getLastStatus]); + NSString* typeId = [prx ice_id]; + test([[interceptor getLastOperation] isEqualToString:@"ice_id"]); + test([interceptor getLastStatus]); + test([prx ice_isA:typeId]); + test([[interceptor getLastOperation] isEqualToString:@"ice_isA"]); + test([interceptor getLastStatus]); + test([prx add:33 y:12] == 45); + test([[interceptor getLastOperation] isEqualToString:@"add"]); + test([interceptor getLastStatus]); + tprintf("ok\n"); + + tprintf("testing retry... "); + test([prx addWithRetry:33 y:12] == 45); + test([[interceptor getLastOperation] isEqualToString:@"addWithRetry"]); + test([interceptor getLastStatus]); + tprintf("ok\n"); + + tprintf("testing user exception... "); + @try + { + [prx badAdd:33 y:12]; + test(NO); + } + @catch(TestInterceptorInvalidInputException*) + { + // expected + } + test([[interceptor getLastOperation] isEqualToString:@"badAdd"]); + test([interceptor getLastStatus] == NO); + tprintf("ok\n"); + tprintf("testing ONE... "); + + [interceptor clear]; + @try + { + [prx notExistAdd:33 y:12]; + test(NO); + } + @catch(ICEObjectNotExistException*) + { + // expected + } + test([[interceptor getLastOperation] isEqualToString:@"notExistAdd"]); + tprintf("ok\n"); + tprintf("testing system exception... "); + [interceptor clear]; + @try + { + [prx badSystemAdd:33 y:12]; + test(NO); + } + @catch(ICEUnknownLocalException*) + { + } + @catch(NSException*) + { + test(NO); + } + test([[interceptor getLastOperation] isEqualToString:@"badSystemAdd"]); + tprintf("ok\n"); + + return 0; +} + +#if TARGET_OS_IPHONE +# define main interceptorClient + +int +interceptorServer(int argc, char* argv[]) +{ + serverReady(nil); + return 0; +} +#endif + +int +main(int argc, char* argv[]) +{ + int status; + @autoreleasepool + { + id<ICECommunicator> communicator = nil; + + @try + { + ICEInitializationData* initData = [ICEInitializationData initializationData]; + initData.properties = defaultClientProperties(&argc, argv); + [initData.properties setProperty:@"Ice.Warn.Dispatch" value:@"0"]; +#if TARGET_OS_IPHONE + initData.prefixTable__ = [NSDictionary dictionaryWithObjectsAndKeys: + @"TestInterceptor", @"::Test", + nil]; +#endif + communicator = [ICEUtil createCommunicator:&argc argv:argv initData:initData]; + status = run(communicator); + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + @catch(TestFailedException* ex) + { + status = EXIT_FAILURE; + } + + if(communicator) + { + @try + { + [communicator destroy]; + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + } + } + return status; +} + diff --git a/objective-c/test/Ice/interceptor/InterceptorI.h b/objective-c/test/Ice/interceptor/InterceptorI.h new file mode 100644 index 00000000000..74b1b070488 --- /dev/null +++ b/objective-c/test/Ice/interceptor/InterceptorI.h @@ -0,0 +1,25 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> + +@interface InterceptorI : ICEDispatchInterceptor <ICEDispatchInterceptor> +{ + ICEObject* servant; + NSString* lastOperation; + BOOL lastStatus; +} + +-(id) init:(ICEObject*)servant; +-(BOOL) getLastStatus; +-(NSString*) getLastOperation; +-(void) clear; + +@end + diff --git a/objective-c/test/Ice/interceptor/InterceptorI.m b/objective-c/test/Ice/interceptor/InterceptorI.m new file mode 100644 index 00000000000..08bde68b89d --- /dev/null +++ b/objective-c/test/Ice/interceptor/InterceptorI.m @@ -0,0 +1,90 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <interceptor/InterceptorI.h> +#import <InterceptorTest.h> +#import <TestCommon.h> + +@implementation InterceptorI + +-(id) init:(ICEObject*) servant_ +{ + self = [super init]; + if(!self) + { + return nil; + } + servant = ICE_RETAIN(servant_); + return self; +} + +#if defined(__clang__) && !__has_feature(objc_arc) +-(void) dealloc +{ + [lastOperation release]; + [servant release]; + [super dealloc]; +} +#endif + +-(BOOL) dispatch:(id<ICERequest>) request +{ + ICECurrent* current = [request getCurrent]; + + ICE_RELEASE(lastOperation); + lastOperation = ICE_RETAIN(current.operation); + + if([lastOperation isEqualToString:@"addWithRetry"]) + { + int i = 0; + for(i = 0; i < 10; ++i) + { + @try + { + [servant ice_dispatch:request]; + test(NO); + } + @catch(TestInterceptorRetryException*) + { + // + // Expected, retry + // + } + } + + [(NSMutableDictionary*)current.ctx setObject:@"no" forKey:@"retry"]; + + // + // A successful dispatch that writes a result we discard + // + [servant ice_dispatch:request]; + } + + lastStatus = [servant ice_dispatch:request]; + return lastStatus; +} + +-(BOOL) getLastStatus +{ + return lastStatus; +} + +-(NSString*) getLastOperation +{ + return lastOperation; +} + +-(void) clear +{ + lastStatus = NO; + ICE_RELEASE(lastOperation); + lastOperation = nil; +} + +@end diff --git a/objective-c/test/Ice/interceptor/InterceptorTest.ice b/objective-c/test/Ice/interceptor/InterceptorTest.ice new file mode 100644 index 00000000000..08c11f392b7 --- /dev/null +++ b/objective-c/test/Ice/interceptor/InterceptorTest.ice @@ -0,0 +1,53 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#pragma once + +["objc:prefix:TestInterceptor"] +module Test +{ + +exception InvalidInputException +{ + string reason; +}; + +local exception RetryException +{ +}; + +interface MyObject +{ + // + // A simple addition + // + int add(int x, int y); + + // + // Will throw RetryException until current.ctx["retry"] is "no" + // + int addWithRetry(int x, int y); + + // + // Raise user exception + // + int badAdd(int x, int y) throws InvalidInputException; + + // + // Raise ONE + // + int notExistAdd(int x, int y); + + // + // Raise system exception + // + int badSystemAdd(int x, int y); +}; + +}; diff --git a/objective-c/test/Ice/interceptor/Makefile b/objective-c/test/Ice/interceptor/Makefile new file mode 100644 index 00000000000..5b75eed1931 --- /dev/null +++ b/objective-c/test/Ice/interceptor/Makefile @@ -0,0 +1,30 @@ +# ********************************************************************** +# +# Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +# +# This copy of Ice is licensed to you under the terms described in the +# ICE_LICENSE file included in this distribution. +# +# ********************************************************************** + +top_srcdir = ../../.. + +CLIENT = client + +TARGETS = $(CLIENT) + +SLICE_OBJS = InterceptorTest.o + +COBJS = Client.o \ + InterceptorI.o \ + MyObjectI.o \ + +OBJS = $(COBJS) $(SLICE_OBJS) + +include $(top_srcdir)/config/Make.rules + +CPPFLAGS := -I. -I.. -I../../include $(CPPFLAGS) + +$(CLIENT): $(COBJS) $(SLICE_OBJS) + rm -f $@ + $(CXX) $(LDFLAGS) $(LDEXEFLAGS) -o $@ $(COBJS) $(SLICE_OBJS) $(TEST_LIBS) diff --git a/objective-c/test/Ice/interceptor/MyObjectI.h b/objective-c/test/Ice/interceptor/MyObjectI.h new file mode 100644 index 00000000000..913e8068c63 --- /dev/null +++ b/objective-c/test/Ice/interceptor/MyObjectI.h @@ -0,0 +1,13 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <InterceptorTest.h> + +@interface TestInterceptorMyObjectI : TestInterceptorMyObject<TestInterceptorMyObject> +@end diff --git a/objective-c/test/Ice/interceptor/MyObjectI.m b/objective-c/test/Ice/interceptor/MyObjectI.m new file mode 100644 index 00000000000..7932e828d1f --- /dev/null +++ b/objective-c/test/Ice/interceptor/MyObjectI.m @@ -0,0 +1,46 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <interceptor/MyObjectI.h> +#import <TestCommon.h> + +@implementation TestInterceptorMyObjectI +-(int) add:(int)x y:(int)y current:(ICECurrent*)current +{ + return x + y; +} + +-(int) addWithRetry:(int)x y:(int)y current:(ICECurrent*)current +{ + id val = [current.ctx objectForKey:@"retry"]; + + if(val == nil || ![(NSString*)val isEqualToString:@"no"]) + { + @throw [TestInterceptorRetryException retryException:__FILE__ line:__LINE__]; + } + return x + y; +} + +-(int) badAdd:(int)x y:(int)y current:(ICECurrent*)current +{ + @throw [TestInterceptorInvalidInputException invalidInputException]; +} + +-(int) notExistAdd:(int)x y:(int)y current:(ICECurrent*)current +{ + @throw [ICEObjectNotExistException objectNotExistException:__FILE__ line:__LINE__]; +} + +-(int) badSystemAdd:(int)x y:(int)y current:(ICECurrent*)current +{ + @throw [ICEInitializationException initializationException:__FILE__ line:__LINE__ reason:@"testing"]; +} + +@end diff --git a/objective-c/test/Ice/interceptor/run.py b/objective-c/test/Ice/interceptor/run.py new file mode 100755 index 00000000000..e7ab1bd2fe0 --- /dev/null +++ b/objective-c/test/Ice/interceptor/run.py @@ -0,0 +1,25 @@ +#!/usr/bin/env python +# ********************************************************************** +# +# Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +# +# This copy of Ice is licensed to you under the terms described in the +# ICE_LICENSE file included in this distribution. +# +# ********************************************************************** + +import os, sys + +path = [ ".", "..", "../..", "../../..", "../../../..", "../../../../.." ] +head = os.path.dirname(sys.argv[0]) +if len(head) > 0: + path = [os.path.join(head, p) for p in path] +path = [os.path.abspath(p) for p in path if os.path.exists(os.path.join(p, "scripts", "TestUtil.py")) ] +if len(path) == 0: + raise RuntimeError("can't find toplevel directory!") +sys.path.append(os.path.join(path[0], "scripts")) +import TestUtil + +client = os.path.join(os.getcwd(), "client") + +TestUtil.simpleTest(client, " --Ice.Warn.Dispatch=0") diff --git a/objective-c/test/Ice/invoke/.gitignore b/objective-c/test/Ice/invoke/.gitignore new file mode 100644 index 00000000000..76608e6287a --- /dev/null +++ b/objective-c/test/Ice/invoke/.gitignore @@ -0,0 +1,8 @@ +// Generated by makegitignore.py + +// IMPORTANT: Do not edit this file -- any edits made here will be lost! +client +server +.depend +InvokeTest.m +InvokeTest.h diff --git a/objective-c/test/Ice/invoke/AllTests.m b/objective-c/test/Ice/invoke/AllTests.m new file mode 100644 index 00000000000..f6108bef90d --- /dev/null +++ b/objective-c/test/Ice/invoke/AllTests.m @@ -0,0 +1,281 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <TestCommon.h> +#import <InvokeTest.h> + +#import <Foundation/Foundation.h> + +static NSString* testString = @"This is a test string"; + +@interface TestInvokeCallback : NSObject +{ + BOOL called; + NSCondition* cond; + id<ICECommunicator> communicator; +} +-(BOOL) check; +-(void) called; +@end + +@implementation TestInvokeCallback +-(id) initWithCommunicator:(id<ICECommunicator>)c +{ + self = [super init]; + if(!self) + { + return nil; + } + cond = [[NSCondition alloc] init]; + communicator = c; + return self; +} + +#if defined(__clang__) && !__has_feature(objc_arc) +-(void) dealloc +{ + [cond release]; + [super dealloc]; +} +#endif + +-(BOOL) check +{ + [cond lock]; + while(!called) + { + if(![cond waitUntilDate:[NSDate dateWithTimeIntervalSinceNow:50]]) + { + return NO; + } + } + called = NO; + [cond unlock]; + return YES; +} +-(void) called +{ + [cond lock]; + called = YES; + [cond signal]; + [cond unlock]; +} +-(void) opString:(BOOL)ok outEncaps:(NSMutableData*)outEncaps +{ + if(ok) + { + id<ICEInputStream> inS = [ICEUtil createInputStream:communicator data:outEncaps]; + [inS startEncapsulation]; + NSString* s; + s = [inS readString]; + test([s isEqualToString:testString]); + s = [inS readString]; + test([s isEqualToString:testString]); + [inS endEncapsulation]; + [self called]; + } + else + { + test(NO); + } +} + +-(void) opException:(BOOL)ok outEncaps:(NSMutableData*)outEncaps +{ + if(ok) + { + test(NO); + } + else + { + id<ICEInputStream> inS = [ICEUtil createInputStream:communicator data:outEncaps]; + [inS startEncapsulation]; + @try + { + [inS throwException]; + } + @catch(TestInvokeMyException*) + { + [inS endEncapsulation]; + [self called]; + } + @catch(NSException*) + { + test(NO); + } + } +} +@end + +id<TestInvokeMyClassPrx> +invokeAllTests(id<ICECommunicator> communicator) +{ + NSString* ref = @"test:default -p 12010"; + id<ICEObjectPrx> base = [communicator stringToProxy:ref]; + test(base); + + id<TestInvokeMyClassPrx> cl = [TestInvokeMyClassPrx checkedCast:base]; + test(cl); + + id<TestInvokeMyClassPrx> onewayCl = [cl ice_oneway]; + id<TestInvokeMyClassPrx> batchOneway = [cl ice_batchOneway]; + + tprintf("testing ice_invoke... "); + + { + NSData* inEncaps = [NSData data]; + NSMutableData* outEncaps; + if(![onewayCl ice_invoke:@"opOneway" mode:ICENormal inEncaps:inEncaps outEncaps:&outEncaps]) + { + test(NO); + } + + test([batchOneway ice_invoke:@"opOneway" mode:ICENormal inEncaps:inEncaps outEncaps:&outEncaps]); + test([batchOneway ice_invoke:@"opOneway" mode:ICENormal inEncaps:inEncaps outEncaps:&outEncaps]); + test([batchOneway ice_invoke:@"opOneway" mode:ICENormal inEncaps:inEncaps outEncaps:&outEncaps]); + test([batchOneway ice_invoke:@"opOneway" mode:ICENormal inEncaps:inEncaps outEncaps:&outEncaps]); + [batchOneway ice_flushBatchRequests]; + + id<ICEOutputStream> outS = [ICEUtil createOutputStream:communicator]; + [outS startEncapsulation]; + [outS writeString:testString]; + [outS endEncapsulation]; + inEncaps = [outS finished]; + // ice_invoke + if([cl ice_invoke:@"opString" mode:ICENormal inEncaps:inEncaps outEncaps:&outEncaps]) + { + id<ICEInputStream> inS = [ICEUtil createInputStream:communicator data:outEncaps]; + [inS startEncapsulation]; + NSString* s; + s = [inS readString]; + test([s isEqualToString:testString]); + s = [inS readString]; + test([s isEqualToString:testString]); + [inS endEncapsulation]; + } + else + { + test(NO); + } + } + + { + NSData* inEncaps = [NSData data]; + NSMutableData* outEncaps; + if([cl ice_invoke:@"opException" mode:ICENormal inEncaps:inEncaps outEncaps:&outEncaps]) + { + test(NO); + } + else + { + id<ICEInputStream> inS = [ICEUtil createInputStream:communicator data:outEncaps]; + [inS startEncapsulation]; + @try + { + [inS throwException]; + } + @catch(TestInvokeMyException*) + { + } + @catch(NSException*) + { + test(NO); + } + [inS endEncapsulation]; + } + } + + tprintf("ok\n"); + + tprintf("testing asynchronous ice_invoke... "); + + { + NSData* inEncaps = [NSData data]; + NSMutableData* outEncaps; + id<ICEAsyncResult> result = [onewayCl begin_ice_invoke:@"opOneway" mode:ICENormal inEncaps:inEncaps]; + if(![onewayCl end_ice_invoke:&outEncaps result:result]) + { + test(NO); + } + + id<ICEOutputStream> outS = [ICEUtil createOutputStream:communicator]; + [outS startEncapsulation]; + [outS writeString:testString]; + [outS endEncapsulation]; + inEncaps = [outS finished]; + + // begin_ice_invoke with no callback + result = [cl begin_ice_invoke:@"opString" mode:ICENormal inEncaps:inEncaps]; + if([cl end_ice_invoke:&outEncaps result:result]) + { + id<ICEInputStream> inS = [ICEUtil createInputStream:communicator data:outEncaps]; + [inS startEncapsulation]; + NSString* s; + s = [inS readString]; + test([s isEqualToString:testString]); + s = [inS readString]; + test([s isEqualToString:testString]); + [inS endEncapsulation]; + } + else + { + test(NO); + }; + + TestInvokeCallback* cb = [[TestInvokeCallback alloc] initWithCommunicator:communicator]; + [cl begin_ice_invoke:@"opString" mode:ICENormal inEncaps:inEncaps + response:^(BOOL ok, NSMutableData* outEncaps) { [cb opString:ok outEncaps:outEncaps]; } + exception:^(ICEException* ex) { test(NO); }]; + [cb check]; + ICE_RELEASE(cb); + } + + { + NSData* inEncaps = [NSData data]; + NSMutableData* outEncaps; + + // begin_ice_invoke with no callback + id<ICEAsyncResult> result = [cl begin_ice_invoke:@"opException" mode:ICENormal inEncaps:inEncaps]; + if([cl end_ice_invoke:&outEncaps result:result]) + { + test(NO); + } + else + { + id<ICEInputStream> inS = [ICEUtil createInputStream:communicator data:outEncaps]; + [inS startEncapsulation]; + @try + { + [inS throwException]; + } + @catch(TestInvokeMyException*) + { + } + @catch(NSException*) + { + test(NO); + } + [inS endEncapsulation]; + } + + // begin_ice_invoke with Callback_Object_ice_invoke + TestInvokeCallback* cb = [[TestInvokeCallback alloc] initWithCommunicator:communicator]; + [cl begin_ice_invoke:@"opException" mode:ICENormal inEncaps:inEncaps + response:^(BOOL ok, NSMutableData* outP) { [cb opException:ok outEncaps:outP]; } + exception:^(ICEException* ex) { test(NO); }]; + [cb check]; + ICE_RELEASE(cb); + } + + tprintf("ok\n"); + + return cl; + +} diff --git a/objective-c/test/Ice/invoke/BlobjectI.h b/objective-c/test/Ice/invoke/BlobjectI.h new file mode 100644 index 00000000000..1291c2eebf7 --- /dev/null +++ b/objective-c/test/Ice/invoke/BlobjectI.h @@ -0,0 +1,14 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <InvokeTest.h> + +@interface BlobjectI : ICEBlobject<ICEBlobject> +-(BOOL) ice_invoke:(NSData*)inEncaps outEncaps:(NSMutableData**)outEncaps current:(ICECurrent*)current; +@end diff --git a/objective-c/test/Ice/invoke/BlobjectI.m b/objective-c/test/Ice/invoke/BlobjectI.m new file mode 100644 index 00000000000..7c043bc768a --- /dev/null +++ b/objective-c/test/Ice/invoke/BlobjectI.m @@ -0,0 +1,76 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <invoke/BlobjectI.h> + +@implementation BlobjectI +-(BOOL) ice_invoke:(NSData*)inEncaps outEncaps:(NSMutableData**)outEncaps current:(ICECurrent*)current +{ + id<ICECommunicator> communicator = [current.adapter getCommunicator]; + id<ICEInputStream> inS = [ICEUtil createInputStream:communicator data:inEncaps]; + id<ICEOutputStream> outS = [ICEUtil createOutputStream:communicator]; + [outS startEncapsulation]; + if([current.operation isEqualToString:@"opOneway"]) + { + return YES; + } + else if([current.operation isEqualToString:@"opString"]) + { + [inS startEncapsulation]; + NSString* s = [inS readString]; + [inS endEncapsulation]; + [outS writeString:s]; + [outS writeString:s]; + [outS endEncapsulation]; + *outEncaps = [outS finished]; + return YES; + } + else if([current.operation isEqualToString:@"opException"]) + { + TestInvokeMyException* ex = [TestInvokeMyException myException]; + [outS writeException:ex]; + [outS endEncapsulation]; + *outEncaps = [outS finished]; + return NO; + } + else if([current.operation isEqualToString:@"shutdown"]) + { + [outS endEncapsulation]; + *outEncaps = [outS finished]; + [communicator shutdown]; + return YES; + } + else if([current.operation isEqualToString:@"ice_isA"]) + { + [inS startEncapsulation]; + NSString* s = [inS readString]; + [inS endEncapsulation]; + if([s isEqualToString:[TestInvokeMyClass ice_staticId]]) + { + [outS writeBool:YES]; + } + else + { + [outS writeBool:NO]; + } + [outS endEncapsulation]; + *outEncaps = [outS finished]; + return YES; + } + else + { + @throw [ICEOperationNotExistException operationNotExistException:__FILE__ + line:__LINE__ + id:current.id_ + facet:current.facet + operation:current.operation]; + } +} +@end diff --git a/objective-c/test/Ice/invoke/Client.m b/objective-c/test/Ice/invoke/Client.m new file mode 100644 index 00000000000..c8a9d74a779 --- /dev/null +++ b/objective-c/test/Ice/invoke/Client.m @@ -0,0 +1,71 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <TestCommon.h> +#import <InvokeTest.h> + +static int +run(id<ICECommunicator> communicator) +{ + TestInvokeMyClassPrx* invokeAllTests(id<ICECommunicator>); + TestInvokeMyClassPrx* invoke = invokeAllTests(communicator); + [invoke shutdown]; + return EXIT_SUCCESS; +} + +#if TARGET_OS_IPHONE +# define main invokeClient +#endif + +int +main(int argc, char* argv[]) +{ + int status; + @autoreleasepool + { + id<ICECommunicator> communicator = nil; + + @try + { + ICEInitializationData* initData = [ICEInitializationData initializationData]; + initData.properties = defaultClientProperties(&argc, argv); +#if TARGET_OS_IPHONE + initData.prefixTable__ = [NSDictionary dictionaryWithObjectsAndKeys: + @"TestInvoke", @"::Test", + nil]; +#endif + communicator = [ICEUtil createCommunicator:&argc argv:argv initData:initData]; + status = run(communicator); + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + @catch(TestFailedException* ex) + { + status = EXIT_FAILURE; + } + + if(communicator) + { + @try + { + [communicator destroy]; + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + } + } + return status; +} diff --git a/objective-c/test/Ice/invoke/InvokeTest.ice b/objective-c/test/Ice/invoke/InvokeTest.ice new file mode 100644 index 00000000000..c8e28f400ff --- /dev/null +++ b/objective-c/test/Ice/invoke/InvokeTest.ice @@ -0,0 +1,31 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#pragma once + +["objc:prefix:TestInvoke"] +module Test +{ + +exception MyException +{ +}; + +class MyClass +{ + void opOneway(); + + string opString(string s1, out string s2); + + void opException() throws MyException; + + void shutdown(); +}; + +}; diff --git a/objective-c/test/Ice/invoke/Makefile b/objective-c/test/Ice/invoke/Makefile new file mode 100644 index 00000000000..4131daa6bf3 --- /dev/null +++ b/objective-c/test/Ice/invoke/Makefile @@ -0,0 +1,37 @@ +# ********************************************************************** +# +# Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +# +# This copy of Ice is licensed to you under the terms described in the +# ICE_LICENSE file included in this distribution. +# +# ********************************************************************** + +top_srcdir = ../../.. + +CLIENT = client +SERVER = server + +TARGETS = $(CLIENT) $(SERVER) + +SLICE_OBJS = InvokeTest.o + +COBJS = Client.o \ + AllTests.o + +SOBJS = BlobjectI.o \ + Server.o + +OBJS = $(COBJS) $(SOBJS) $(SLICE_OBJS) + +include $(top_srcdir)/config/Make.rules + +CPPFLAGS := -I. -I.. -I../../include $(CPPFLAGS) + +$(CLIENT): $(COBJS) $(SLICE_OBJS) + rm -f $@ + $(CXX) $(LDFLAGS) $(LDEXEFLAGS) -o $@ $(COBJS) $(SLICE_OBJS) $(TEST_LIBS) + +$(SERVER): $(SOBJS) $(SLICE_OBJS) + rm -f $@ + $(CXX) $(LDFLAGS) $(LDEXEFLAGS) -o $@ $(SOBJS) $(SLICE_OBJS) $(TEST_LIBS) diff --git a/objective-c/test/Ice/invoke/Server.m b/objective-c/test/Ice/invoke/Server.m new file mode 100644 index 00000000000..648b68b59b0 --- /dev/null +++ b/objective-c/test/Ice/invoke/Server.m @@ -0,0 +1,71 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <invoke/BlobjectI.h> +#import <TestCommon.h> + +static int +run(id<ICECommunicator> communicator) +{ + [[communicator getProperties] setProperty:@"TestAdapter.Endpoints" value:@"default -p 12010:udp"]; + id<ICEObjectAdapter> adapter = [communicator createObjectAdapter:@"TestAdapter"]; + [adapter addDefaultServant:ICE_AUTORELEASE([[BlobjectI alloc] init]) category:@""]; + [adapter activate]; + + serverReady(communicator); + + [communicator waitForShutdown]; + return EXIT_SUCCESS; +} + +#if TARGET_OS_IPHONE +# define main invokeServer +#endif + +int +main(int argc, char* argv[]) +{ + int status; + @autoreleasepool + { + id<ICECommunicator> communicator = nil; + @try + { + ICEInitializationData* initData = [ICEInitializationData initializationData]; + initData.properties = defaultServerProperties(&argc, argv); +#if TARGET_OS_IPHONE + initData.prefixTable__ = [NSDictionary dictionaryWithObjectsAndKeys: + @"TestInvoke", @"::Test", + nil]; +#endif + communicator = [ICEUtil createCommunicator:&argc argv:argv initData:initData]; + status = run(communicator); + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + + if(communicator) + { + @try + { + [communicator destroy]; + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + } + } + return status; +} diff --git a/objective-c/test/Ice/invoke/run.py b/objective-c/test/Ice/invoke/run.py new file mode 100755 index 00000000000..ce8c5dd4b18 --- /dev/null +++ b/objective-c/test/Ice/invoke/run.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python +# ********************************************************************** +# +# Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +# +# This copy of Ice is licensed to you under the terms described in the +# ICE_LICENSE file included in this distribution. +# +# ********************************************************************** + +import os, sys + +path = [ ".", "..", "../..", "../../..", "../../../..", "../../../../.." ] +head = os.path.dirname(sys.argv[0]) +if len(head) > 0: + path = [os.path.join(head, p) for p in path] +path = [os.path.abspath(p) for p in path if os.path.exists(os.path.join(p, "scripts", "TestUtil.py")) ] +if len(path) == 0: + raise RuntimeError("can't find toplevel directory!") +sys.path.append(os.path.join(path[0], "scripts")) +import TestUtil + +TestUtil.clientServerTest() diff --git a/objective-c/test/Ice/location/.gitignore b/objective-c/test/Ice/location/.gitignore new file mode 100644 index 00000000000..cd321e6c61d --- /dev/null +++ b/objective-c/test/Ice/location/.gitignore @@ -0,0 +1,8 @@ +// Generated by makegitignore.py + +// IMPORTANT: Do not edit this file -- any edits made here will be lost! +client +server +.depend +LocationTest.m +LocationTest.h diff --git a/objective-c/test/Ice/location/AllTests.m b/objective-c/test/Ice/location/AllTests.m new file mode 100644 index 00000000000..515a5209909 --- /dev/null +++ b/objective-c/test/Ice/location/AllTests.m @@ -0,0 +1,479 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <TestCommon.h> +#import <LocationTest.h> + +#include <Foundation/NSThread.h> + +@interface DummyHelloI : TestLocationHello +@end + +@implementation DummyHelloI +-(void) sayHello:(ICECurrent*)current +{ + // Do nothing, this is just a dummy servant. +} +@end + +void +locationAllTests(id<ICECommunicator> communicator, NSString* ref) +{ + id<TestLocationServerManagerPrx> manager = + [TestLocationServerManagerPrx checkedCast:[communicator stringToProxy:ref]]; + id<TestLocationTestLocatorPrx> locator = + [TestLocationTestLocatorPrx uncheckedCast:[communicator getDefaultLocator]]; + test(manager); + + id<TestLocationTestLocatorRegistryPrx> registry = + [TestLocationTestLocatorRegistryPrx checkedCast:[locator getRegistry]]; + test(registry); + + tprintf("testing stringToProxy... "); + id<ICEObjectPrx> base = [communicator stringToProxy:@"test @ TestAdapter"]; + id<ICEObjectPrx> base2 = [communicator stringToProxy:@"test @ TestAdapter"]; + id<ICEObjectPrx> base3 = [communicator stringToProxy:@"test"]; + id<ICEObjectPrx> base4 = [communicator stringToProxy:@"ServerManager"]; + id<ICEObjectPrx> base5 = [communicator stringToProxy:@"test2"]; + id<ICEObjectPrx> base6 = [communicator stringToProxy:@"test @ ReplicatedAdapter"]; + tprintf("ok\n"); + + tprintf("testing ice_locator and ice_getLocator... "); + test([[base ice_getLocator] compareIdentity:[communicator getDefaultLocator]] == NSOrderedSame); + id<ICELocatorPrx> anotherLocator = [ICELocatorPrx uncheckedCast:[communicator stringToProxy:@"anotherLocator"]]; + base = [base ice_locator:anotherLocator]; + test([[base ice_getLocator] compareIdentity:anotherLocator] == NSOrderedSame); + [communicator setDefaultLocator:0]; + base = [communicator stringToProxy:@"test @ TestAdapter"]; + test(![base ice_getLocator]); + base = [base ice_locator:anotherLocator]; + test([[base ice_getLocator] compareIdentity:anotherLocator] == NSOrderedSame); + [communicator setDefaultLocator:locator]; + base = [communicator stringToProxy:@"test @ TestAdapter"]; + test([[base ice_getLocator] compareIdentity:[communicator getDefaultLocator]] == NSOrderedSame); + + // + // We also test ice_router/ice_getRouter (perhaps we should add a + // test/Ice/router test?) + // + test(![base ice_getRouter]); + id<ICERouterPrx> anotherRouter = [ICERouterPrx uncheckedCast:[communicator stringToProxy:@"anotherRouter"]]; + base = [base ice_router:anotherRouter]; + test([[base ice_getRouter] compareIdentity:anotherRouter] == NSOrderedSame); + id<ICERouterPrx> router = [ICERouterPrx uncheckedCast:[communicator stringToProxy:@"dummyrouter"]]; + [communicator setDefaultRouter:router]; + base = [communicator stringToProxy:@"test @ TestAdapter"]; + test([[base ice_getRouter] compareIdentity:[communicator getDefaultRouter]] == NSOrderedSame); + [communicator setDefaultRouter:0]; + base = [communicator stringToProxy:@"test @ TestAdapter"]; + test(![base ice_getRouter]); + tprintf("ok\n"); + + tprintf("starting server... "); + [manager startServer]; + tprintf("ok\n"); + + tprintf("testing checked cast... "); + id<TestLocationTestIntfPrx> obj = [TestLocationTestIntfPrx checkedCast:base]; + obj = [TestLocationTestIntfPrx checkedCast:[communicator stringToProxy:@"test@TestAdapter"]]; + obj = [TestLocationTestIntfPrx checkedCast:[communicator stringToProxy:@"test @TestAdapter"]]; + obj = [TestLocationTestIntfPrx checkedCast:[communicator stringToProxy:@"test@ TestAdapter"]]; + test(obj); + id<TestLocationTestIntfPrx> obj2 = [TestLocationTestIntfPrx checkedCast:base2]; + test(obj2); + id<TestLocationTestIntfPrx> obj3 = [TestLocationTestIntfPrx checkedCast:base3]; + test(obj3); + id<TestLocationServerManagerPrx> obj4 = [TestLocationServerManagerPrx checkedCast:base4]; + test(obj4); + id<TestLocationTestIntfPrx> obj5 = [TestLocationTestIntfPrx checkedCast:base5]; + test(obj5); + id<TestLocationTestIntfPrx> obj6 = [TestLocationTestIntfPrx checkedCast:base6]; + test(obj6); + tprintf("ok\n"); + + tprintf("testing id@AdapterId indirect proxy... "); + [obj shutdown]; + [manager startServer]; + @try + { + obj2 = [TestLocationTestIntfPrx checkedCast:base2]; + [obj2 ice_ping]; + } + @catch(ICELocalException* ex) + { + NSLog(@"%@", ex); + test(NO); + } + tprintf("ok\n"); + + tprintf("testing id@ReplicaGroupId indirect proxy... "); + [obj shutdown]; + [manager startServer]; + @try + { + obj6 = [TestLocationTestIntfPrx checkedCast:base6]; + [obj6 ice_ping]; + } + @catch(ICELocalException* ex) + { + NSLog(@"%@", ex); + test(NO); + } + tprintf("ok\n"); + + tprintf("testing identity indirect proxy... "); + [obj shutdown]; + [manager startServer]; + @try + { + obj3 = [TestLocationTestIntfPrx checkedCast:base3]; + [obj3 ice_ping]; + } + @catch(ICELocalException* ex) + { + NSLog(@"%@", ex); + test(NO); + } + @try + { + obj2 = [TestLocationTestIntfPrx checkedCast:base2]; + [obj2 ice_ping]; + } + @catch(ICELocalException* ex) + { + NSLog(@"%@", ex); + test(NO); + } + [obj shutdown]; + [manager startServer]; + @try + { + obj2 = [TestLocationTestIntfPrx checkedCast:base2]; + [obj2 ice_ping]; + } + @catch(ICELocalException* ex) + { + NSLog(@"%@", ex); + test(NO); + } + @try + { + obj3 = [TestLocationTestIntfPrx checkedCast:base3]; + [obj3 ice_ping]; + } + @catch(ICELocalException* ex) + { + NSLog(@"%@", ex); + test(NO); + } + [obj shutdown]; + [manager startServer]; + + @try + { + obj2 = [TestLocationTestIntfPrx checkedCast:base2]; + [obj2 ice_ping]; + } + @catch(ICELocalException* ex) + { + NSLog(@"%@", ex); + test(NO); + } + [obj shutdown]; + [manager startServer]; + @try + { + obj3 = [TestLocationTestIntfPrx checkedCast:base3]; + [obj3 ice_ping]; + } + @catch(ICELocalException* ex) + { + NSLog(@"%@", ex); + test(NO); + } + [obj shutdown]; + [manager startServer]; + @try + { + obj2 = [TestLocationTestIntfPrx checkedCast:base2]; + [obj2 ice_ping]; + } + @catch(ICELocalException* ex) + { + NSLog(@"%@", ex); + test(NO); + } + [obj shutdown]; + [manager startServer]; + + @try + { + obj5 = [TestLocationTestIntfPrx checkedCast:base5]; + [obj5 ice_ping]; + } + @catch(ICELocalException* ex) + { + NSLog(@"%@", ex); + test(NO); + } + tprintf("ok\n"); + + tprintf("testing proxy with unknown identity... "); + @try + { + base = [communicator stringToProxy:@"unknown/unknown"]; + [base ice_ping]; + test(NO); + } + @catch(ICENotRegisteredException* ex) + { + test([ex.kindOfObject isEqualToString:@"object"]); + test([ex.id_ isEqualToString:@"unknown/unknown"]); + } + tprintf("ok\n"); + + tprintf("testing proxy with unknown adapter... "); + @try + { + base = [communicator stringToProxy:@"test @ TestAdapterUnknown"]; + [base ice_ping]; + test(NO); + } + @catch(ICENotRegisteredException* ex) + { + test([ex.kindOfObject isEqualToString:@"object adapter"]); + test([ex.id_ isEqualToString:@"TestAdapterUnknown"]); + } + tprintf("ok\n"); + + tprintf("testing locator cache timeout... "); + + int count = [locator getRequestCount]; + [[[communicator stringToProxy:@"test@TestAdapter"] ice_locatorCacheTimeout:0] ice_ping]; // No locator cache. + test(++count == [locator getRequestCount]); + [[[communicator stringToProxy:@"test@TestAdapter"] ice_locatorCacheTimeout:0] ice_ping]; // No locator cache. + test(++count == [locator getRequestCount]); + [[[communicator stringToProxy:@"test@TestAdapter"] ice_locatorCacheTimeout:1] ice_ping]; // 1s timeout. + test(count == [locator getRequestCount]); + [NSThread sleepForTimeInterval:1.2]; + [[[communicator stringToProxy:@"test@TestAdapter"] ice_locatorCacheTimeout:1] ice_ping]; // 1s timeout. + test(++count == [locator getRequestCount]); + + [[[communicator stringToProxy:@"test"] ice_locatorCacheTimeout:0] ice_ping]; // No locator cache. + count += 2; + test(count == [locator getRequestCount]); + [[[communicator stringToProxy:@"test"] ice_locatorCacheTimeout:1] ice_ping]; // 1s timeout + test(count == [locator getRequestCount]); + [NSThread sleepForTimeInterval:1.2]; + [[[communicator stringToProxy:@"test"] ice_locatorCacheTimeout:1] ice_ping]; // 1s timeout + count += 2; + test(count == [locator getRequestCount]); + + [[[communicator stringToProxy:@"test@TestAdapter"] ice_locatorCacheTimeout:-1] ice_ping]; + test(count == [locator getRequestCount]); + [[[communicator stringToProxy:@"test"] ice_locatorCacheTimeout:-1] ice_ping]; + test(count == [locator getRequestCount]); + [[communicator stringToProxy:@"test@TestAdapter"] ice_ping]; + test(count == [locator getRequestCount]); + [[communicator stringToProxy:@"test"] ice_ping]; + test(count == [locator getRequestCount]); + + test([[[communicator stringToProxy:@"test"] ice_locatorCacheTimeout:99] ice_getLocatorCacheTimeout] == 99); + + tprintf("ok\n"); + + tprintf("testing proxy from server... "); + id<TestLocationHelloPrx> hello = [obj getHello]; + test([[hello ice_getAdapterId] isEqualToString:@"TestAdapter"]); + [hello sayHello]; + hello = [obj getReplicatedHello]; + test([[hello ice_getAdapterId] isEqualToString:@"ReplicatedAdapter"]); + [hello sayHello]; + tprintf("ok\n"); + + tprintf("testing well-known object locator cache... "); + + [registry addObject:[communicator stringToProxy:@"test3@TestUnknown"]]; + @try + { + [[communicator stringToProxy:@"test3"] ice_ping]; + test(NO); + } + @catch(ICENotRegisteredException* ex) + { + test([ex.kindOfObject isEqualToString:@"object adapter"]); + test([ex.id_ isEqualToString:@"TestUnknown"]); + } + [registry addObject:[communicator stringToProxy:@"test3@TestAdapter4"]]; // Update + [registry setAdapterDirectProxy:@"TestAdapter4" proxy:[communicator stringToProxy:@"dummy:tcp"]]; + @try + { + [[communicator stringToProxy:@"test3"] ice_ping]; + test(NO); + } + @catch(ICELocalException* ex) + { + } + [registry setAdapterDirectProxy:@"TestAdapter4" proxy:[locator findAdapterById:@"TestAdapter"]]; + @try + { + [[communicator stringToProxy:@"test3"] ice_ping]; + } + @catch(ICELocalException* ex) + { + test(NO); + } + + [registry setAdapterDirectProxy:@"TestAdapter4" proxy:[communicator stringToProxy:@"dummy:tcp"]]; + @try + { + [[communicator stringToProxy:@"test3"] ice_ping]; + } + @catch(ICELocalException* ex) + { + test(NO); + } + + @try + { + [[[communicator stringToProxy:@"test@TestAdapter4"] ice_locatorCacheTimeout:0] ice_ping]; + test(NO); + } + @catch(ICELocalException* ex) + { + } + @try + { + [[communicator stringToProxy:@"test@TestAdapter4"] ice_ping]; + test(NO); + } + @catch(ICELocalException* ex) + { + } + @try + { + [[communicator stringToProxy:@"test3"] ice_ping]; + test(NO); + } + @catch(ICELocalException* ex) + { + } + [registry addObject:[communicator stringToProxy:@"test3@TestAdapter"]]; + @try + { + [[communicator stringToProxy:@"test3"] ice_ping]; + } + @catch(ICELocalException* ex) + { + test(NO); + } + + [registry addObject:[communicator stringToProxy:@"test4"]]; + @try + { + [[communicator stringToProxy:@"test4"] ice_ping]; + test(NO); + } + @catch(ICENoEndpointException* ex) + { + } + tprintf("ok\n"); + + tprintf("testing proxy from server after shutdown... "); + [obj shutdown]; + [manager startServer]; + [hello sayHello]; + tprintf("ok\n"); + + tprintf("testing object migration... "); + hello = [TestLocationHelloPrx checkedCast:[communicator stringToProxy:@"hello"]]; + [obj migrateHello]; + [hello sayHello]; + [obj migrateHello]; + [hello sayHello]; + [obj migrateHello]; + [hello sayHello]; + tprintf("ok\n"); + + tprintf("testing locator encoding resolution... "); + hello = [TestLocationHelloPrx checkedCast:[communicator stringToProxy:@"hello"]]; + count = [locator getRequestCount]; + [[[communicator stringToProxy:@"test@TestAdapter"] ice_encodingVersion:ICEEncoding_1_1] ice_ping]; + test(count == [locator getRequestCount]); + [[[communicator stringToProxy:@"test@TestAdapter10"] ice_encodingVersion:ICEEncoding_1_0] ice_ping]; + test(++count == [locator getRequestCount]); + [[communicator stringToProxy:@"test -e 1.0@TestAdapter10-2"] ice_ping]; + test(++count == [locator getRequestCount]); + tprintf("ok\n"); + + tprintf("shutdown server... "); + [obj shutdown]; + tprintf("ok\n"); + + tprintf("testing whether server is gone... "); + @try + { + [obj2 ice_ping]; + test(NO); + } + @catch(ICELocalException*) + { + } + @try + { + [obj3 ice_ping]; + test(NO); + } + @catch(ICELocalException*) + { + } + @try + { + [obj5 ice_ping]; + test(NO); + } + @catch(ICELocalException*) + { + } + tprintf("ok\n"); + +// tprintf("testing indirect proxies to collocated objects... "); +// // +// // Set up test for calling a collocated object through an indirect, adapterless reference. +// // +// id<ICEProperties> properties = [communicator getProperties]; +// [properties setProperty:@"Ice.PrintAdapterReady" value:@"0"]; +// id<ICEObjectAdapter> adapter = [communicator createObjectAdapterWithEndpoints:@"Hello" endpoints:@"default"]; +// [adapter setLocator:locator]; + +// id<TestLocationTestLocatorRegistryPrx> registry = [TestLocationTestLocatorRegistryPrx checkedCast:[locator getRegistry]]; +// test(registry); + +// ICEIdentity* ident = [ICEIdentity identity:[ICEUtil generateUUID] category:@""]; +// [registry addObject:[adapter add:[DummyHelloI hello] identity:ident]]; +// [adapter activate]; + +// @try +// { +// id<TestLocationHelloPrx> helloPrx = [TestLocationHelloPrx checkedCast:[communicator stringToProxy: +// [communicator identityToString:ident]]]; +// [helloPrx ice_getConnection]; +// test(NO); +// } +// @catch(ICECollocationOptimizationException*) +// { +// } +// [adapter deactivate]; +// tprintf("ok\n"); + + tprintf("shutdown server manager... "); + [manager shutdown]; + tprintf("ok\n"); +} diff --git a/objective-c/test/Ice/location/Client.m b/objective-c/test/Ice/location/Client.m new file mode 100644 index 00000000000..7e4b548a124 --- /dev/null +++ b/objective-c/test/Ice/location/Client.m @@ -0,0 +1,72 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <TestCommon.h> +#import <LocationTest.h> + +static int +run(id<ICECommunicator> communicator) +{ + void locationAllTests(id<ICECommunicator>, NSString*); + locationAllTests(communicator, @"ServerManager:default -p 12010"); + return EXIT_SUCCESS; +} + +#if TARGET_OS_IPHONE +# define main locationClient +#endif + +int +main(int argc, char* argv[]) +{ + int status; + @autoreleasepool + { + id<ICECommunicator> communicator = nil; + + @try + { + ICEInitializationData* initData = [ICEInitializationData initializationData]; + initData.properties = defaultClientProperties(&argc, argv); + [initData.properties setProperty:@"Ice.Default.Locator" value:@"locator:default -p 12010"]; +#if TARGET_OS_IPHONE + initData.prefixTable__ = [NSDictionary dictionaryWithObjectsAndKeys: + @"TestLocation", @"::Test", + nil]; +#endif + communicator = [ICEUtil createCommunicator:&argc argv:argv initData:initData]; + + status = run(communicator); + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + @catch(TestFailedException* ex) + { + status = EXIT_FAILURE; + } + + if(communicator) + { + @try + { + [communicator destroy]; + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + } + } + return status; +} diff --git a/objective-c/test/Ice/location/LocationTest.ice b/objective-c/test/Ice/location/LocationTest.ice new file mode 100644 index 00000000000..41ba5f39410 --- /dev/null +++ b/objective-c/test/Ice/location/LocationTest.ice @@ -0,0 +1,56 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#pragma once + +#include <Ice/Locator.ice> + +["objc:prefix:TestLocation"] +module Test +{ + +interface TestLocatorRegistry extends ::Ice::LocatorRegistry +{ + // + // Allow remote addition of objects to the locator registry. + // + void addObject(Object* obj); +}; + +interface TestLocator extends ::Ice::Locator +{ + // + // Returns the number of request on the locator interface. + // + ["cpp:const"] idempotent int getRequestCount(); +}; + +interface ServerManager +{ + void startServer(); + void shutdown(); +}; + +interface Hello +{ + void sayHello(); +}; + +interface TestIntf +{ + void shutdown(); + + Hello* getHello(); + + Hello* getReplicatedHello(); + + void migrateHello(); +}; + +}; diff --git a/objective-c/test/Ice/location/Makefile b/objective-c/test/Ice/location/Makefile new file mode 100644 index 00000000000..aedb3040ca3 --- /dev/null +++ b/objective-c/test/Ice/location/Makefile @@ -0,0 +1,38 @@ +# ********************************************************************** +# +# Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +# +# This copy of Ice is licensed to you under the terms described in the +# ICE_LICENSE file included in this distribution. +# +# ********************************************************************** + +top_srcdir = ../../.. + +CLIENT = client +SERVER = server + +TARGETS = $(CLIENT) $(SERVER) + +SLICE_OBJS = LocationTest.o + +COBJS = Client.o \ + AllTests.o + +SOBJS = TestI.o \ + ServerLocator.o \ + Server.o + +OBJS = $(COBJS) $(SOBJS) $(SLICE_OBJS) + +include $(top_srcdir)/config/Make.rules + +CPPFLAGS := -I. -I.. -I../../include $(CPPFLAGS) + +$(CLIENT): $(COBJS) $(SLICE_OBJS) + rm -f $@ + $(CXX) $(LDFLAGS) $(LDEXEFLAGS) -o $@ $(COBJS) $(SLICE_OBJS) $(TEST_LIBS) + +$(SERVER): $(SOBJS) $(SLICE_OBJS) + rm -f $@ + $(CXX) $(LDFLAGS) $(LDEXEFLAGS) -o $@ $(SOBJS) $(SLICE_OBJS) $(TEST_LIBS) diff --git a/objective-c/test/Ice/location/Server.m b/objective-c/test/Ice/location/Server.m new file mode 100644 index 00000000000..a676af82932 --- /dev/null +++ b/objective-c/test/Ice/location/Server.m @@ -0,0 +1,99 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <location/ServerLocator.h> +#import <location/TestI.h> +#import <TestCommon.h> + +static int +run(id<ICECommunicator> communicator, ICEInitializationData* initData) +{ + // + // Register the server manager. The server manager creates a new + // 'server' (a server isn't a different process, it's just a new + // communicator and object adapter). + // + [[communicator getProperties] setProperty:@"Ice.ThreadPool.Server.Size" value:@"2"]; + [[communicator getProperties] setProperty:@"ServerManager.Endpoints" value:@"default -p 12010:udp"]; + + id<ICEObjectAdapter> adapter = [communicator createObjectAdapter:@"ServerManager"]; + + // + // We also register a sample server locator which implements the + // locator interface, this locator is used by the clients and the + // 'servers' created with the server manager interface. + // + ServerLocatorRegistry* registry = ICE_AUTORELEASE([[ServerLocatorRegistry alloc] init]); + ServerManagerI* serverManager = ICE_AUTORELEASE([[ServerManagerI alloc] init:registry initData:initData]); + + [registry addObject:[adapter createProxy:[communicator stringToIdentity:@"ServerManager"]]]; + [adapter add:serverManager identity:[communicator stringToIdentity:@"ServerManager"]]; + + id<ICELocatorRegistryPrx> registryPrx = + [ICELocatorRegistryPrx uncheckedCast:[adapter add:registry + identity:[communicator stringToIdentity:@"registry"]]]; + + ServerLocator* locator = ICE_AUTORELEASE([[ServerLocator alloc] init:registry proxy:registryPrx]); + [adapter add:locator identity:[communicator stringToIdentity:@"locator"]]; + + [adapter activate]; + + serverReady(communicator); + + [communicator waitForShutdown]; + [serverManager terminate]; + + return EXIT_SUCCESS; +} + +#if TARGET_OS_IPHONE +# define main locationServer +#endif + +int +main(int argc, char* argv[]) +{ + int status; + @autoreleasepool + { + id<ICECommunicator> communicator = nil; + @try + { + ICEInitializationData* initData = [ICEInitializationData initializationData]; + initData.properties = defaultServerProperties(&argc, argv); +#if TARGET_OS_IPHONE + initData.prefixTable__ = [NSDictionary dictionaryWithObjectsAndKeys: + @"TestLocation", @"::Test", + nil]; +#endif + communicator = [ICEUtil createCommunicator:&argc argv:argv initData:initData]; + status = run(communicator, initData); + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + + if(communicator) + { + @try + { + [communicator destroy]; + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + } + } + return status; +} diff --git a/objective-c/test/Ice/location/ServerLocator.h b/objective-c/test/Ice/location/ServerLocator.h new file mode 100644 index 00000000000..d9d9447469d --- /dev/null +++ b/objective-c/test/Ice/location/ServerLocator.h @@ -0,0 +1,29 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <LocationTest.h> + +@interface ServerLocatorRegistry : TestLocationTestLocatorRegistry<TestLocationTestLocatorRegistry> +{ + NSMutableDictionary* adapters_; + NSMutableDictionary* objects_; +} +-(id<ICEObjectPrx>) getAdapter:(NSString*)adapterId; +-(id<ICEObjectPrx>) getObject:(ICEIdentity*)ident; +-(void) addObject:(id<ICEObjectPrx>)prx; +@end + +@interface ServerLocator : TestLocationTestLocator<TestLocationTestLocator> +{ + ServerLocatorRegistry* registry_; + id<ICELocatorRegistryPrx> registryPrx_; + int requestCount_; +} +-(id) init:(ServerLocatorRegistry*)registry proxy:(id<ICELocatorRegistryPrx>)proxy; +@end diff --git a/objective-c/test/Ice/location/ServerLocator.m b/objective-c/test/Ice/location/ServerLocator.m new file mode 100644 index 00000000000..6363f2c849b --- /dev/null +++ b/objective-c/test/Ice/location/ServerLocator.m @@ -0,0 +1,129 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <location/ServerLocator.h> + +@implementation ServerLocatorRegistry +-(id) init +{ + self = [super init]; + if(!self) + { + return nil; + } + adapters_ = [[NSMutableDictionary alloc] init]; + objects_ = [[NSMutableDictionary alloc] init]; + return self; +} + +#if defined(__clang__) && !__has_feature(objc_arc) +-(void) dealloc +{ + [adapters_ release]; + [objects_ release]; + [super dealloc]; +} +#endif + +-(void) setAdapterDirectProxy:(NSMutableString *)adapter proxy:(id<ICEObjectPrx>)proxy current:(ICECurrent *)current +{ + if(proxy == nil) + { + [adapters_ removeObjectForKey:adapter]; + } + else + { + [adapters_ setObject:proxy forKey:adapter]; + } +} +-(void) setReplicatedAdapterDirectProxy:(NSMutableString *)adapterId + replicaGroupId:(NSMutableString *)replicaGroupId + p:(id<ICEObjectPrx>)p + current:(ICECurrent *)current +{ + if(p == nil) + { + [adapters_ removeObjectForKey:adapterId]; + [adapters_ removeObjectForKey:replicaGroupId]; + } + else + { + [adapters_ setObject:p forKey:adapterId]; + [adapters_ setObject:p forKey:replicaGroupId]; + } +} +-(void) setServerProcessProxy:(NSMutableString *)id_ proxy:(id<ICEProcessPrx>)proxy current:(ICECurrent *)current +{ +} +-(void) addObject:(id<ICEObjectPrx>)object current:(ICECurrent*)current +{ + [self addObject:object]; +} +-(id<ICEObjectPrx>) getAdapter:(NSString*)adapterId +{ + id<ICEObjectPrx> proxy = [adapters_ objectForKey:adapterId]; + if(proxy == nil) + { + @throw [ICEAdapterNotFoundException adapterNotFoundException]; + } + return proxy; +} +-(id<ICEObjectPrx>) getObject:(ICEIdentity*)ident +{ + id<ICEObjectPrx> proxy = [objects_ objectForKey:ident]; + if(proxy == nil) + { + @throw [ICEObjectNotFoundException objectNotFoundException]; + } + return proxy; +} +-(void) addObject:(id<ICEObjectPrx>)object +{ + [objects_ setObject:object forKey:[object ice_getIdentity]]; +} +@end + +@implementation ServerLocator +-(id) init:(ServerLocatorRegistry*)registry proxy:(id<ICELocatorRegistryPrx>)registryPrx +{ + self = [super init]; + if(!self) + { + return nil; + } + registry_ = registry; + registryPrx_ = registryPrx; + requestCount_ = 0; + return self; +} +-(id<ICEObjectPrx>) findObjectById:(ICEIdentity *)id_ current:(ICECurrent *)current +{ + ++requestCount_; + return [registry_ getObject:id_]; +} +-(id<ICEObjectPrx>) findAdapterById:(NSMutableString *)id_ current:(ICECurrent *)current +{ + ++requestCount_; + if([id_ isEqualToString:@"TestAdapter10"] || [id_ isEqualToString:@"TestAdapter10-2"]) + { + NSAssert([current.encoding isEqual:ICEEncoding_1_0], @"unexpected encoding"); + return [registry_ getAdapter:@"TestAdapter"]; + } + return [registry_ getAdapter:id_]; +} +-(id<ICELocatorRegistryPrx>) getRegistry:(ICECurrent *)current +{ + return registryPrx_; +} +-(int) getRequestCount:(ICECurrent*)current +{ + return requestCount_; +} +@end diff --git a/objective-c/test/Ice/location/TestI.h b/objective-c/test/Ice/location/TestI.h new file mode 100644 index 00000000000..daa5bd9268f --- /dev/null +++ b/objective-c/test/Ice/location/TestI.h @@ -0,0 +1,34 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <LocationTest.h> +#import <location/ServerLocator.h> + +@interface ServerManagerI : TestLocationServerManager<TestLocationServerManager> +{ + NSMutableArray* communicators_; + ServerLocatorRegistry* registry_; + ICEInitializationData* initData_; +} +-(id)init:(ServerLocatorRegistry*)registry initData:(ICEInitializationData*)d; + +-(void)terminate; +@end + +@interface HelloI : TestLocationHello<TestLocationHello> +@end + +@interface TestLocationI : TestLocationTestIntf<TestLocationTestIntf> +{ + id<ICEObjectAdapter> adapter1_; + id<ICEObjectAdapter> adapter2_; + ServerLocatorRegistry* registry_; +} +-(id) init:(id<ICEObjectAdapter>)adapter1 adapter2:(id<ICEObjectAdapter>)adpt2 registry:(ServerLocatorRegistry*)r; +@end diff --git a/objective-c/test/Ice/location/TestI.m b/objective-c/test/Ice/location/TestI.m new file mode 100644 index 00000000000..37b8f6f655f --- /dev/null +++ b/objective-c/test/Ice/location/TestI.m @@ -0,0 +1,161 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <location/TestI.h> + +@implementation ServerManagerI +-(id) init:(ServerLocatorRegistry*)registry initData:(ICEInitializationData*)initData +{ + self = [super init]; + if(!self) + { + return nil; + } + registry_ = registry; + initData_ = initData; + + [initData_.properties setProperty:@"TestAdapter.Endpoints" value:@"default"]; + [initData_.properties setProperty:@"TestAdapter.AdapterId" value:@"TestAdapter"]; + [initData_.properties setProperty:@"TestAdapter.ReplicaGroupId" value:@"ReplicatedAdapter"]; + + [initData_.properties setProperty:@"TestAdapter2.Endpoints" value:@"default"]; + [initData_.properties setProperty:@"TestAdapter2.AdapterId" value:@"TestAdapter2"]; + + [initData_.properties setProperty:@"Ice.PrintAdapterReady" value:@"0"]; + return self; +} + +#if defined(__clang__) && !__has_feature(objc_arc) +-(void) dealloc +{ + [communicators_ release]; + [super dealloc]; +} +#endif + +-(void) startServer:(ICECurrent*)current +{ + for(id<ICECommunicator> c in communicators_) + { + [c waitForShutdown]; + [c destroy]; + } + ICE_RELEASE(communicators_); + communicators_ = [[NSMutableArray alloc] init]; + + // + // Simulate a server: create a [[communicator alloc] init] and object + // adapter. The object adapter is started on a system allocated + // port. The configuration used here contains the Ice.Locator + // configuration variable. The [[object alloc] init] adapter will register + // its endpoints with the locator and create references containing + // the adapter id instead of the endpoints. + // + + id<ICECommunicator> serverCommunicator = [ICEUtil createCommunicator:initData_]; + [communicators_ addObject:serverCommunicator]; + + id<ICEObjectAdapter> adapter = [serverCommunicator createObjectAdapter:@"TestAdapter"]; + id<ICEObjectAdapter> adapter2 = [serverCommunicator createObjectAdapter:@"TestAdapter2"]; + + id<ICEObjectPrx> locator = [serverCommunicator stringToProxy:@"locator:default -p 12010"]; + [adapter setLocator:[ICELocatorPrx uncheckedCast:locator]]; + [adapter2 setLocator:[ICELocatorPrx uncheckedCast:locator]]; + + ICEObject* object = ICE_AUTORELEASE([[TestLocationI alloc] init:adapter adapter2:adapter2 registry:registry_]); + [registry_ addObject:[adapter add:object identity:[serverCommunicator stringToIdentity:@"test"]]]; + [registry_ addObject:[adapter add:object identity:[serverCommunicator stringToIdentity:@"test2"]]]; + [adapter add:object identity:[serverCommunicator stringToIdentity:@"test3"]]; + + [adapter activate]; + [adapter2 activate]; +} + +-(void) shutdown:(ICECurrent*)current +{ + for(id<ICECommunicator> c in communicators_) + { + [c destroy]; + } + [communicators_ removeAllObjects]; + [[current.adapter getCommunicator] shutdown]; +} + +-(void) terminate +{ + for(id<ICECommunicator> c in communicators_) + { + [c destroy]; + } + [communicators_ removeAllObjects]; +} +@end + +@implementation TestLocationI +-(id) init:(id<ICEObjectAdapter>)adapter + adapter2:(id<ICEObjectAdapter>)adapter2 + registry:(ServerLocatorRegistry*)registry +{ + self = [super init]; + if(!self) + { + return nil; + } + adapter1_ = ICE_RETAIN(adapter); + adapter2_ = ICE_RETAIN(adapter2); + registry_ = registry; + [registry_ addObject:[adapter1_ add:[HelloI hello] identity:[[adapter1_ getCommunicator] stringToIdentity:@"hello"]]]; + return self; +} + +#if defined(__clang__) && !__has_feature(objc_arc) +-(void) dealloc +{ + [adapter1_ release]; + [adapter2_ release]; + [super dealloc]; +} +#endif + +-(void) shutdown:(ICECurrent*)current +{ + [[adapter1_ getCommunicator] shutdown]; +} + +-(id<TestLocationHelloPrx>) getHello:(ICECurrent*)current +{ + return [TestLocationHelloPrx uncheckedCast:[adapter1_ createIndirectProxy:[[adapter1_ getCommunicator] + stringToIdentity:@"hello"]]]; +} + +-(id<TestLocationHelloPrx>) getReplicatedHello:(ICECurrent*)current +{ + return [TestLocationHelloPrx uncheckedCast:[adapter1_ createProxy:[[adapter1_ getCommunicator] stringToIdentity:@"hello"]]]; +} + +-(void) migrateHello:(ICECurrent*)current +{ + ICEIdentity* ident = [[adapter1_ getCommunicator] stringToIdentity:@"hello"]; + @try + { + [registry_ addObject:[adapter2_ add:[adapter1_ remove:ident] identity:ident]]; + } + @catch(ICENotRegisteredException*) + { + [registry_ addObject:[adapter1_ add:[adapter2_ remove:ident] identity:ident]]; + } +} +@end + +@implementation HelloI +-(void) sayHello:(ICECurrent*)current +{ +} +@end diff --git a/objective-c/test/Ice/location/run.py b/objective-c/test/Ice/location/run.py new file mode 100755 index 00000000000..ce8c5dd4b18 --- /dev/null +++ b/objective-c/test/Ice/location/run.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python +# ********************************************************************** +# +# Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +# +# This copy of Ice is licensed to you under the terms described in the +# ICE_LICENSE file included in this distribution. +# +# ********************************************************************** + +import os, sys + +path = [ ".", "..", "../..", "../../..", "../../../..", "../../../../.." ] +head = os.path.dirname(sys.argv[0]) +if len(head) > 0: + path = [os.path.join(head, p) for p in path] +path = [os.path.abspath(p) for p in path if os.path.exists(os.path.join(p, "scripts", "TestUtil.py")) ] +if len(path) == 0: + raise RuntimeError("can't find toplevel directory!") +sys.path.append(os.path.join(path[0], "scripts")) +import TestUtil + +TestUtil.clientServerTest() diff --git a/objective-c/test/Ice/metrics/.gitignore b/objective-c/test/Ice/metrics/.gitignore new file mode 100644 index 00000000000..919d41acc0f --- /dev/null +++ b/objective-c/test/Ice/metrics/.gitignore @@ -0,0 +1,8 @@ +// Generated by makegitignore.py + +// IMPORTANT: Do not edit this file -- any edits made here will be lost! +client +server +.depend +MetricsTest.m +MetricsTest.h diff --git a/objective-c/test/Ice/metrics/AllTests.m b/objective-c/test/Ice/metrics/AllTests.m new file mode 100644 index 00000000000..2feab5f5aae --- /dev/null +++ b/objective-c/test/Ice/metrics/AllTests.m @@ -0,0 +1,1154 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice Touch is licensed to you under the terms described in the +// ICE_TOUCH_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <TestCommon.h> +#import <MetricsTest.h> + +#import <Foundation/Foundation.h> + +@interface UpdateCallbackI : NSObject<ICEPropertiesAdminUpdateCallback> +{ +@private +BOOL updated; +id<ICEPropertiesAdminPrx> serverProps; +NSCondition* cond; +} +-(id) initWithServerProps:(id<ICEPropertiesAdminPrx>)serverProps; +-(void) waitForUpdate; +-(void) updated:(ICEMutablePropertyDict*)properties; +@end + +@implementation UpdateCallbackI +-(id) initWithServerProps:(id<ICEPropertiesAdminPrx>)serverProps_ +{ + self = [super init]; + if(self) + { + self->serverProps = ICE_RETAIN(serverProps_); + self->cond = [[NSCondition alloc] init]; + } + return self; +} + +-(void) waitForUpdate +{ + [cond lock]; + while(!updated) + { + [cond wait]; + } + // Ensure that the previous updates were committed, the setProperties call returns before + // notifying the callbacks so to ensure all the update callbacks have be notified we call + // a second time, this will block until all the notifications from the first update have + // completed. + [serverProps setProperties:[ICEPropertyDict dictionary]]; + updated = NO; + [cond unlock]; +} + +-(void) updated:(ICEMutablePropertyDict*)properties +{ + [cond lock]; + updated = YES; + [cond signal]; + [cond unlock]; +} + +#if defined(__clang__) && !__has_feature(objc_arc) +-(void) dealloc +{ + [serverProps release]; + [cond release]; + [super dealloc]; +} +#endif +@end + +@interface Callback : NSObject +{ +BOOL wait; +NSCondition* cond; +} + +-(id) init; ++(id) callback; + +-(void) response; +-(void) exception:(ICEException*)exception; +-(void) waitForResponse; +@end + +@implementation Callback +-(id) init +{ + self = [super init]; + if(self) + { + wait = true; + cond = [[NSCondition alloc] init]; + } + return self; +} + ++(id) callback +{ + return ICE_AUTORELEASE([[Callback alloc] init]); +} + +#if defined(__clang__) && !__has_feature(objc_arc) +-(void) dealloc +{ + [cond release]; + [super dealloc]; +} +#endif + +-(void) response +{ + [cond lock]; + wait = false; + [cond signal]; + [cond unlock]; +} + +-(void) exception:(ICEException*)exception +{ + [self response]; +} + +-(void) waitForResponse +{ + [cond lock]; + while(wait) + { + [cond wait]; + } + wait = true; + [cond unlock]; +} +@end + +@interface Operation : NSObject +{ +@protected + ICEObjectPrx* proxy; +} +-(id) init:(ICEObjectPrx*)proxy_; +@end + +@implementation Operation +-(id) init:(ICEObjectPrx*)proxy_ +{ + self = [super init]; + if(self) + { + self->proxy = ICE_RETAIN(proxy_); + } + return self; +} + +#if defined(__clang__) && !__has_feature(objc_arc) +-(void) dealloc +{ + [self->proxy release]; + [super dealloc]; +} +#endif +@end + +@interface Connect : Operation +-(id) init:(ICEObjectPrx*)proxy_; ++(id) connect:(ICEObjectPrx*)proxy_; +-(void) run; +@end + +@implementation Connect +-(id) init:(ICEObjectPrx*)proxy_ +{ + self = [super init:proxy_]; + return self; +} + ++(id) connect:(ICEObjectPrx*)proxy_ +{ + return ICE_AUTORELEASE([[Connect alloc] init:proxy_]); +} + +-(void) run +{ + if([proxy ice_getCachedConnection]) + { + [[proxy ice_getCachedConnection] close:NO]; + } + @try + { + [proxy ice_ping]; + } + @catch(ICELocalException*) + { + } + if([proxy ice_getCachedConnection]) + { + [[proxy ice_getCachedConnection] close:NO]; + } +} +@end + + +@interface InvokeOp : Operation +-(id) init:(ICEObjectPrx*)proxy_; ++(id) invokeOp:(ICEObjectPrx*)proxy_; +-(void) run; +@end + +@implementation InvokeOp +-(id) init:(ICEObjectPrx*)proxy_ +{ + self = [super init:proxy_]; + return self; +} + ++(id) invokeOp:(ICEObjectPrx*)proxy_ +{ + return ICE_AUTORELEASE([[InvokeOp alloc] init:proxy_]); +} + +-(void) run +{ + ICEMutableContext* ctx = [ICEMutableContext dictionary]; + [ctx setObject:@"test" forKey:@"entry1"]; + [ctx setObject:@"" forKey:@"entry2"]; + TestMetricsMetricsPrx* metrics = [TestMetricsMetricsPrx uncheckedCast:proxy]; + [metrics op:ctx]; +} +@end + +void +waitForCurrent(ICEMXMetricsAdminPrx* metrics, NSString* viewName, NSString* map, int value) +{ + while(true) + { + ICELong timestamp; + ICEMXMetricsView* view = [metrics getMetricsView:viewName timestamp:×tamp]; + test([view objectForKey:map] != nil); + + bool ok = true; + ICEMXMetricsMap* mmap = [view objectForKey:map]; + for(ICEMXMetrics* m in mmap) + { + if(m.current != value) + { + ok = false; + break; + } + } + + if(ok) + { + break; + } + [NSThread sleepForTimeInterval:50 / 1000.0]; + } +} + +ICEMutablePropertyDict* +getClientProps(id<ICEPropertiesAdminPrx> p, ICEMutablePropertyDict* orig, NSString* m) +{ + ICEMutablePropertyDict* props = [p getPropertiesForPrefix:@"IceMX.Metrics"]; + ICEPropertyDict* cprops = ICE_AUTORELEASE([props copy]); + [cprops enumerateKeysAndObjectsUsingBlock: ^(id key, id obj, BOOL *stop) + { + [props setObject:@"" forKey:key]; + }]; + + [orig enumerateKeysAndObjectsUsingBlock: ^(id key, id obj, BOOL *stop) + { + [props setObject:obj forKey:key]; + }]; + + NSString* map = @""; + if(![m isEqualToString:@""]) + { + map = [map stringByAppendingFormat:@"Map.%@.", m]; + } + [props setObject:@"Ice\\.Admin" + forKey:[NSString stringWithFormat:@"IceMX.Metrics.View.%@Reject.parent", map]]; + + [props setObject:@"12010" + forKey:[NSString stringWithFormat:@"IceMX.Metrics.View.%@Accept.endpointPort", map] ]; + + [props setObject:@".*/admin|controller" + forKey:[NSString stringWithFormat:@"IceMX.Metrics.View.%@Reject.identity", map]]; + return props; +} + +ICEMutablePropertyDict* +getServerProps(id<ICEPropertiesAdminPrx> p, ICEMutablePropertyDict* orig, NSString* m) +{ + ICEMutablePropertyDict* props = [p getPropertiesForPrefix:@"IceMX.Metrics"]; + ICEPropertyDict* sprops = ICE_AUTORELEASE([props copy]); + [sprops enumerateKeysAndObjectsUsingBlock: ^(id key, id obj, BOOL *stop) + { + [props setObject:@"" forKey:key]; + }]; + + [orig enumerateKeysAndObjectsUsingBlock: ^(id key, id obj, BOOL *stop) + { + [props setObject:obj forKey:key]; + }]; + + NSString* map = @""; + if(![m isEqualToString:@""]) + { + map = [map stringByAppendingFormat:@"Map.%@.", m]; + } + [props setObject:@"Ice\\.Admin|Controller" + forKey:[NSString stringWithFormat:@"IceMX.Metrics.View.%@Reject.parent", map]]; + + [props setObject:@"12010" + forKey:[NSString stringWithFormat:@"IceMX.Metrics.View.%@Accept.endpointPort", map]]; + + [props setObject:@".*/admin|controller" + forKey:[NSString stringWithFormat:@"IceMX.Metrics.View.%@Reject.identity", map]]; + return props; +} + +ICEMXConnectionMetrics* +getServerConnectionMetrics(ICEMXMetricsAdminPrx* metrics, ICELong expected) +{ + ICEMXConnectionMetrics* s; + int nRetry = 30; + ICELong timestamp; + s = (ICEMXConnectionMetrics*) + [[[metrics getMetricsView:@"View" timestamp:×tamp] objectForKey:@"Connection"] objectAtIndex:0]; + while(s.sentBytes != expected && nRetry-- > 0) + { + // On some platforms, it's necessary to wait a little before obtaining the server metrics + // to get an accurate sentBytes metric. The sentBytes metric is updated before the response + // to the operation is sent and getMetricsView can be dispatched before the metric is really + // updated. + [NSThread sleepForTimeInterval:100 / 1000.0]; + s = (ICEMXConnectionMetrics*) + [[[metrics getMetricsView:@"View" timestamp:×tamp] objectForKey:@"Connection"] objectAtIndex:0]; + } + return s; +} + +void +updateProps(id<ICEPropertiesAdminPrx> cprops, + id<ICEPropertiesAdminPrx> sprops, + UpdateCallbackI* callback, + ICEMutablePropertyDict* props, + NSString* map) +{ + [cprops setProperties:getClientProps(cprops, props, map)]; + [sprops setProperties:getServerProps(sprops, props, map)]; + [callback waitForUpdate]; +} + +void +testAttribute(ICEMXMetricsAdminPrx* metrics, + ICEPropertiesAdminPrx* props, + UpdateCallbackI* update, + NSString* map, + NSString* attr, + NSString* value, + id func) +{ + ICEMutablePropertyDict* dict = [ICEMutablePropertyDict dictionary]; + [dict setObject:attr forKey:[NSString stringWithFormat:@"IceMX.Metrics.View.Map.%@.GroupBy", map]]; + if([[props ice_getIdentity].category isEqualToString:@"client"]) + { + [props setProperties:getClientProps(props, dict, map)]; + [update waitForUpdate]; + } + else + { + [props setProperties:getServerProps(props, dict, map)]; + [props setProperties:[ICEPropertyDict dictionary]]; + } + [func run]; + ICELong timestamp; + ICEMXMetricsView* view = [metrics getMetricsView:@"View" timestamp:×tamp]; + if([view objectForKey:map] == nil || [[view objectForKey:map] count] == 0) + { + if(![value isEqualToString:@""]) + { + test(NO); + } + } + else if([[view objectForKey:map] count] != 1 || + ![((ICEMXMetrics*)[[view objectForKey:map] objectAtIndex:0]).id_ isEqualToString:value]) + { + test(NO); + } + + [dict removeAllObjects]; + if([[props ice_getIdentity].category isEqualToString:@"client"]) + { + [props setProperties:getClientProps(props, dict, map)]; + [update waitForUpdate]; + } + else + { + [props setProperties:getServerProps(props, dict, map)]; + [props setProperties:[ICEPropertyDict dictionary]]; + } +} + +void +clearView(ICEPropertiesAdminPrx* cprops, ICEPropertiesAdminPrx* sprops, UpdateCallbackI* callback) +{ + ICEMutablePropertyDict* dict = [cprops getPropertiesForPrefix:@"IceMX.Metrics"]; + [dict setObject:@"1" forKey:@"IceMX.Metrics.View.Disabled"]; + [cprops setProperties:dict]; + + dict = [sprops getPropertiesForPrefix:@"IceMX.Metrics"]; + [dict setObject:@"1" forKey:@"IceMX.Metrics.View.Disabled"]; + [sprops setProperties:dict]; + + [callback waitForUpdate]; + + dict = [cprops getPropertiesForPrefix:@"IceMX.Metrics"]; + [dict setObject:@"" forKey:@"IceMX.Metrics.View.Disabled"]; + [cprops setProperties:dict]; + + dict = [sprops getPropertiesForPrefix:@"IceMX.Metrics"]; + [dict setObject:@"" forKey:@"IceMX.Metrics.View.Disabled"]; + [sprops setProperties:dict]; + + [callback waitForUpdate]; +} + +void +checkFailure(ICEMXMetricsAdminPrx* m, NSString* map, NSString* id_, NSString* failure, int count) +{ + ICEMXMetricsFailures* f = [m getMetricsFailures:@"View" map:map id:id_]; + if([f.failures objectForKey:failure] == nil) + { + NSLog(@"couldn't find failure `%@' for `%@'", failure, id_); + test(NO); + } + if(count > 0 && [[f.failures objectForKey:failure] intValue] != count) + { + NSLog(@"count for failure `%@' of `%@' is different from expected: ", failure, id_); + NSLog(@"%i != %@", count, [f.failures objectForKey:failure]); + test(NO); + } +} + +NSMutableDictionary* +toMap(ICEMXMetricsMap* mmap) +{ + NSMutableDictionary* m = [NSMutableDictionary dictionary]; + for(ICEMXMetrics* metrics in mmap) + { + [m setObject:metrics forKey:metrics.id_]; + } + return m; +} + +id<TestMetricsMetricsPrx> +metricsAllTests(id<ICECommunicator> communicator) +{ + id<TestMetricsMetricsPrx> metrics = [TestMetricsMetricsPrx checkedCast: + [communicator stringToProxy:@"metrics:default -p 12010"]]; + + tprintf("testing metrics admin facet checkedCast... "); + id<ICEObjectPrx> admin = [communicator getAdmin]; + id<ICEPropertiesAdminPrx> clientProps = [ICEPropertiesAdminPrx checkedCast:admin facet:@"Properties"]; + + id<ICEMXMetricsAdminPrx> clientMetrics = [ICEMXMetricsAdminPrx checkedCast:admin facet:@"Metrics"]; + test(clientProps && clientMetrics); + + admin = [metrics getAdmin]; + id<ICEPropertiesAdminPrx> serverProps = [ICEPropertiesAdminPrx checkedCast:admin facet:@"Properties"]; + id<ICEMXMetricsAdminPrx> serverMetrics = [ICEMXMetricsAdminPrx checkedCast:admin facet:@"Metrics"]; + test(serverProps && serverMetrics); + + UpdateCallbackI* update = ICE_AUTORELEASE([[UpdateCallbackI alloc] initWithServerProps:serverProps]); + id<ICENativePropertiesAdmin> nativePropertiesAdmin = + (id<ICENativePropertiesAdmin>)[communicator findAdminFacet:@"Properties"]; + [nativePropertiesAdmin addUpdateCallback:update]; + tprintf("ok\n"); + + ICEMutablePropertyDict* props = [ICEMutablePropertyDict dictionary]; + tprintf("testing group by none..."); + + [props setObject:@"none" forKey:@"IceMX.Metrics.View.GroupBy"]; + + updateProps(clientProps, serverProps, update, props, @""); + + int threadCount = 4; + + ICELong timestamp = 0; + ICEMXMetricsView* view = [clientMetrics getMetricsView:@"View" timestamp:×tamp]; + + test([[view objectForKey:@"Connection"] count] == 1 && + [[[view objectForKey:@"Connection"] objectAtIndex:0] current] == 1 && + [[[view objectForKey:@"Connection"] objectAtIndex:0] total] == 1); + + test([[view objectForKey:@"Thread"] count] == 1); + test([[[view objectForKey:@"Thread"] objectAtIndex:0] current] == threadCount); + test([[[view objectForKey:@"Thread"] objectAtIndex:0] total] == threadCount); + + tprintf("ok\n"); + + tprintf("testing connection metrics... "); + + [props setObject:@"none" forKey:@"IceMX.Metrics.View.Map.Connection.GroupBy"]; + updateProps(clientProps, serverProps, update, props, @"Connection"); + + test([[[clientMetrics getMetricsView:@"View" timestamp:×tamp] objectForKey:@"Connection"] count] == 1); + test([[[serverMetrics getMetricsView:@"View" timestamp:×tamp] objectForKey:@"Connection"] count] == 1); + + [metrics ice_ping]; + + ICEMXConnectionMetrics *cm1, *sm1, *cm2, *sm2; + cm1 = (ICEMXConnectionMetrics*) + [[[clientMetrics getMetricsView:@"View" timestamp:×tamp] objectForKey:@"Connection"] objectAtIndex:0]; + + sm1 = (ICEMXConnectionMetrics*) + [[[serverMetrics getMetricsView:@"View" timestamp:×tamp] objectForKey:@"Connection"] objectAtIndex:0]; + + sm1 = getServerConnectionMetrics(serverMetrics, 25); + + test(cm1.total == 1 && sm1.total == 1); + + [metrics ice_ping]; + + cm2 = (ICEMXConnectionMetrics*) + [[[clientMetrics getMetricsView:@"View" timestamp:×tamp] objectForKey:@"Connection"] objectAtIndex:0]; + sm2 = getServerConnectionMetrics(serverMetrics, 50); + + test(cm2.sentBytes - cm1.sentBytes == 45); // 45 for ice_ping request + test(cm2.receivedBytes - cm1.receivedBytes == 25); // 25 bytes for ice_ping response + test(sm2.receivedBytes - sm1.receivedBytes == 45); + test(sm2.sentBytes - sm1.sentBytes == 25); + + cm1 = cm2; + sm1 = sm2; + + TestMetricsMutableByteSeq* bs = [TestMetricsMutableByteSeq dataWithLength:0]; + [metrics opByteS:bs]; + + cm2 = (ICEMXConnectionMetrics*) + [[[clientMetrics getMetricsView:@"View" timestamp:×tamp] objectForKey:@"Connection"] objectAtIndex:0]; + + sm2 = getServerConnectionMetrics(serverMetrics, sm1.sentBytes + cm2.receivedBytes - cm1.receivedBytes); + ICELong requestSz = cm2.sentBytes - cm1.sentBytes; + ICELong replySz = cm2.receivedBytes - cm1.receivedBytes; + + cm1 = cm2; + sm1 = sm2; + + [bs setLength:456]; + [metrics opByteS:bs]; + + cm2 = (ICEMXConnectionMetrics*) + [[[clientMetrics getMetricsView:@"View" timestamp:×tamp] objectForKey:@"Connection"] objectAtIndex:0]; + sm2 = getServerConnectionMetrics(serverMetrics, sm1.sentBytes + replySz); + + // 4 is for the seq variable size + test(cm2.sentBytes - cm1.sentBytes == requestSz + [bs length] + 4); + test(cm2.receivedBytes - cm1.receivedBytes == replySz); + test(sm2.receivedBytes - sm1.receivedBytes == requestSz + [bs length] + 4); + test(sm2.sentBytes - sm1.sentBytes == replySz); + + cm1 = cm2; + sm1 = sm2; + + [bs setLength:(1024 * 1024 * 10)]; // Try with large amount of data which should be sent in several chunks + [metrics opByteS:bs]; + + cm2 = (ICEMXConnectionMetrics*) + [[[clientMetrics getMetricsView:@"View" timestamp:×tamp] objectForKey:@"Connection"] objectAtIndex:0]; + sm2 = getServerConnectionMetrics(serverMetrics, sm1.sentBytes + replySz); + + // 4 is for the seq variable size + test(cm2.sentBytes - cm1.sentBytes == requestSz + [bs length] + 4); + test(cm2.receivedBytes - cm1.receivedBytes == replySz); + test(sm2.receivedBytes - sm1.receivedBytes == requestSz + [bs length] + 4); + test(sm2.sentBytes - sm1.sentBytes == replySz); + + [props setObject:@"state" forKey:@"IceMX.Metrics.View.Map.Connection.GroupBy"]; + updateProps(clientProps, serverProps, update, props, @"Connection"); + + NSMutableDictionary* map = + toMap([[serverMetrics getMetricsView:@"View" timestamp:×tamp] objectForKey:@"Connection"]); + + test([[map objectForKey:@"active"] current] == 1); + + TestMetricsControllerPrx* controller = + [TestMetricsControllerPrx checkedCast:[communicator stringToProxy:@"controller:default -p 12011"]]; + + [controller hold]; + + map = toMap([[clientMetrics getMetricsView:@"View" timestamp:×tamp] objectForKey:@"Connection"]); + test([[map objectForKey:@"active"] current] == 1); + map = toMap([[serverMetrics getMetricsView:@"View" timestamp:×tamp] objectForKey:@"Connection"]); + test([[map objectForKey:@"holding"] current] == 1); + + [[metrics ice_getConnection] close:false]; + + map = toMap([[clientMetrics getMetricsView:@"View" timestamp:×tamp] objectForKey:@"Connection"]); + test([[map objectForKey:@"closing"] current] == 1); + map = toMap([[serverMetrics getMetricsView:@"View" timestamp:×tamp] objectForKey:@"Connection"]); + test([[map objectForKey:@"holding"] current] == 1); + + [controller resume]; + + map = toMap([[serverMetrics getMetricsView:@"View" timestamp:×tamp] objectForKey:@"Connection"]); + test([[map objectForKey:@"holding"] current] == 0); + + [props setObject:@"none" forKey:@"IceMX.Metrics.View.Map.Connection.GroupBy"]; + updateProps(clientProps, serverProps, update, props, @"Connection"); + + [[metrics ice_getConnection] close:false]; + + [[metrics ice_timeout:500] ice_ping]; + [controller hold]; + @try + { + [[metrics ice_timeout:500] opByteS:[NSMutableData dataWithLength:10000000]]; + test(NO); + } + @catch(const ICETimeoutException*) + { + } + [controller resume]; + + cm1 = (ICEMXConnectionMetrics*) + [[[clientMetrics getMetricsView:@"View" timestamp:×tamp] objectForKey:@"Connection"] objectAtIndex:0]; + while(true) + { + sm1 = (ICEMXConnectionMetrics*) + [[[serverMetrics getMetricsView:@"View" timestamp:×tamp] objectForKey:@"Connection"] objectAtIndex:0]; + if(sm1.failures >= 2) + { + break; + } + [NSThread sleepForTimeInterval:10 / 1000.0]; + } + + test(cm1.failures == 2 && sm1.failures >= 1); + + checkFailure(clientMetrics, @"Connection", cm1.id_, @"Ice::TimeoutException", 1); + checkFailure(clientMetrics, @"Connection", cm1.id_, @"Ice::ConnectTimeoutException", 1); + checkFailure(serverMetrics, @"Connection", sm1.id_, @"Ice::ConnectionLostException", 0); + + ICEMXMetricsPrx* m = [[metrics ice_timeout:500] ice_connectionId:@"Con1"]; + [m ice_ping]; + + testAttribute(clientMetrics, clientProps, update, @"Connection", @"parent", @"Communicator", nil); + //testAttribute(clientMetrics, clientProps, update, "Connection", "id", ""); + testAttribute(clientMetrics, clientProps, update, @"Connection", @"endpoint", @"tcp -h 127.0.0.1 -p 12010 -t 500", + nil); + + testAttribute(clientMetrics, clientProps, update, @"Connection", @"endpointType", @"1", nil); + testAttribute(clientMetrics, clientProps, update, @"Connection", @"endpointIsDatagram", @"false", nil); + testAttribute(clientMetrics, clientProps, update, @"Connection", @"endpointIsSecure", @"false", nil); + testAttribute(clientMetrics, clientProps, update, @"Connection", @"endpointTimeout", @"500", nil); + testAttribute(clientMetrics, clientProps, update, @"Connection", @"endpointCompress", @"false", nil); + testAttribute(clientMetrics, clientProps, update, @"Connection", @"endpointHost", @"127.0.0.1", nil); + testAttribute(clientMetrics, clientProps, update, @"Connection", @"endpointPort", @"12010", nil); + + testAttribute(clientMetrics, clientProps, update, @"Connection", @"incoming", @"false", nil); + testAttribute(clientMetrics, clientProps, update, @"Connection", @"adapterName", @"", nil); + testAttribute(clientMetrics, clientProps, update, @"Connection", @"connectionId", @"Con1", nil); + testAttribute(clientMetrics, clientProps, update, @"Connection", @"localHost", @"127.0.0.1", nil); + //testAttribute(clientMetrics, clientProps, update, "Connection", "localPort", ""); + testAttribute(clientMetrics, clientProps, update, @"Connection", @"remoteHost", @"127.0.0.1", nil); + testAttribute(clientMetrics, clientProps, update, @"Connection", @"remotePort", @"12010", nil); + testAttribute(clientMetrics, clientProps, update, @"Connection", @"mcastHost", @"", nil); + testAttribute(clientMetrics, clientProps, update, @"Connection", @"mcastPort", @"", nil); + + [[m ice_getConnection] close:false]; + + waitForCurrent(clientMetrics, @"View", @"Connection", 0); + waitForCurrent(serverMetrics, @"View", @"Connection", 0); + + tprintf("ok\n"); + + tprintf("testing connection establishment metrics... "); + + [props setObject:@"id" forKey:@"IceMX.Metrics.View.Map.ConnectionEstablishment.GroupBy"]; + updateProps(clientProps, serverProps, update, props, @"ConnectionEstablishment"); + test([[[clientMetrics getMetricsView:@"View" timestamp:×tamp] + objectForKey:@"ConnectionEstablishment"] count] == 0); + + [metrics ice_ping]; + + test([[[clientMetrics getMetricsView:@"View" timestamp:×tamp] + objectForKey:@"ConnectionEstablishment"] count] == 1); + ICEMXMetrics* m1 = [[[clientMetrics getMetricsView:@"View" timestamp:×tamp] + objectForKey:@"ConnectionEstablishment"] objectAtIndex:0]; + + test(m1.current == 0 && m1.total == 1 && [m1.id_ isEqualToString:@"127.0.0.1:12010"]); + + [[metrics ice_getConnection] close:NO]; + [controller hold]; + @try + { + [[[communicator stringToProxy:@"test:tcp -p 12010 -h 127.0.0.1"] ice_timeout:10] ice_ping]; + test(NO); + } + @catch(ICEConnectTimeoutException*) + { + } + @catch(const ICELocalException*) + { + test(NO); + } + [controller resume]; + test([[[clientMetrics getMetricsView:@"View" timestamp:×tamp] + objectForKey:@"ConnectionEstablishment"] count] == 1); + m1 = [[[clientMetrics getMetricsView:@"View" timestamp:×tamp] + objectForKey:@"ConnectionEstablishment"] objectAtIndex:0]; + test([m1.id_ isEqualToString:@"127.0.0.1:12010"] && m1.total == 3 && m1.failures == 2); + + checkFailure(clientMetrics, @"ConnectionEstablishment", m1.id_, @"Ice::ConnectTimeoutException", 2); + + Connect* c = [Connect connect:metrics]; + + testAttribute(clientMetrics, clientProps, update, @"ConnectionEstablishment", @"parent", @"Communicator", c); + testAttribute(clientMetrics, clientProps, update, @"ConnectionEstablishment", @"id", @"127.0.0.1:12010", c); + testAttribute(clientMetrics, clientProps, update, @"ConnectionEstablishment", @"endpoint", + @"tcp -h 127.0.0.1 -p 12010 -t 60000", c); + + testAttribute(clientMetrics, clientProps, update, @"ConnectionEstablishment", @"endpointType", @"1", c); + testAttribute(clientMetrics, clientProps, update, @"ConnectionEstablishment", @"endpointIsDatagram", @"false", c); + testAttribute(clientMetrics, clientProps, update, @"ConnectionEstablishment", @"endpointIsSecure", @"false", c); + testAttribute(clientMetrics, clientProps, update, @"ConnectionEstablishment", @"endpointTimeout", @"60000", c); + testAttribute(clientMetrics, clientProps, update, @"ConnectionEstablishment", @"endpointCompress", @"false", c); + testAttribute(clientMetrics, clientProps, update, @"ConnectionEstablishment", @"endpointHost", @"127.0.0.1", c); + testAttribute(clientMetrics, clientProps, update, @"ConnectionEstablishment", @"endpointPort", @"12010", c); + + tprintf("ok\n"); + + // + // Ice doesn't do any endpoint lookup with WinRT, the WinRT + // runtime takes care of if. + // + // In iOS we use CFStream transports that doesn't do any enpoint + // lookup. + // +#if !defined(ICE_OS_WINRT) && (!defined(__APPLE__) || (defined(__APPLE__) && !TARGET_OS_IPHONE)) + tprintf("testing endpoint lookup metrics... "); + + [props setObject:@"id" forKey:@"IceMX.Metrics.View.Map.EndpointLookup.GroupBy"]; + updateProps(clientProps, serverProps, update, props, @"EndpointLookup"); + test([[[clientMetrics getMetricsView:@"View" timestamp:×tamp] objectForKey:@"EndpointLookup"] count] == 0); + + ICEObjectPrx* prx = [communicator stringToProxy:@"metrics:default -p 12010 -h localhost -t infinite"]; + [prx ice_ping]; + test([[[clientMetrics getMetricsView:@"View" timestamp:×tamp] objectForKey:@"EndpointLookup"] count] == 1); + m1 = [[[clientMetrics getMetricsView:@"View" timestamp:×tamp] objectForKey:@"EndpointLookup"] objectAtIndex:0]; + + test(m1.current <= 1 && m1.total == 1 && [m1.id_ isEqualToString:@"tcp -h localhost -p 12010 -t infinite"]); + + [[prx ice_getConnection] close:NO]; + + BOOL dnsException = NO; + @try + { + [[communicator stringToProxy:@"test:tcp -t 500 -p 12010 -h unknownfoo.zeroc.com"] ice_ping]; + test(NO); + } + @catch(const ICEDNSException*) + { + dnsException = YES; + } + @catch(ICELocalException*) + { + // Some DNS servers don't fail on unknown DNS names. + } + test([[[clientMetrics getMetricsView:@"View" timestamp:×tamp] objectForKey:@"EndpointLookup"] count] == 2); + m1 = [[[clientMetrics getMetricsView:@"View" timestamp:×tamp] objectForKey:@"EndpointLookup"] objectAtIndex:1]; + test([m1.id_ isEqualToString:@"tcp -h unknownfoo.zeroc.com -p 12010 -t 500"] && m1.total == 2 && + (!dnsException || m1.failures == 2)); + if(dnsException) + { + checkFailure(clientMetrics, @"EndpointLookup", m1.id_, @"Ice::DNSException", 2); + } + + c = [Connect connect:prx]; + testAttribute(clientMetrics, clientProps, update, @"EndpointLookup", @"parent", @"Communicator", c); + testAttribute(clientMetrics, clientProps, update, @"EndpointLookup", @"id", + @"tcp -h localhost -p 12010 -t infinite", c); + testAttribute(clientMetrics, clientProps, update, @"EndpointLookup", @"endpoint", + @"tcp -h localhost -p 12010 -t infinite", c); + + testAttribute(clientMetrics, clientProps, update, @"EndpointLookup", @"endpointType", @"1", c); + testAttribute(clientMetrics, clientProps, update, @"EndpointLookup", @"endpointIsDatagram", @"false", c); + testAttribute(clientMetrics, clientProps, update, @"EndpointLookup", @"endpointIsSecure", @"false", c); + testAttribute(clientMetrics, clientProps, update, @"EndpointLookup", @"endpointTimeout", @"-1", c); + testAttribute(clientMetrics, clientProps, update, @"EndpointLookup", @"endpointCompress", @"false", c); + testAttribute(clientMetrics, clientProps, update, @"EndpointLookup", @"endpointHost", @"localhost", c); + testAttribute(clientMetrics, clientProps, update, @"EndpointLookup", @"endpointPort", @"12010", c); + + tprintf("ok\n"); +#endif + + tprintf("testing dispatch metrics... "); + + [props setObject:@"operation" forKey:@"IceMX.Metrics.View.Map.Dispatch.GroupBy"]; + updateProps(clientProps, serverProps, update, props, @"Dispatch"); + test([[[serverMetrics getMetricsView:@"View" timestamp:×tamp] objectForKey:@"Dispatch"] count] == 0); + + [metrics op]; + @try + { + [metrics opWithUserException]; + test(NO); + } + @catch(TestMetricsUserEx*) + { + } + @try + { + [metrics opWithRequestFailedException]; + test(NO); + } + @catch(ICERequestFailedException*) + { + } + @try + { + [metrics opWithLocalException]; + test(NO); + } + @catch(ICELocalException*) + { + } + @try + { + [metrics opWithUnknownException]; + test(NO); + } + @catch(ICEUnknownException*) + { + } + @try + { + [metrics fail]; + test(NO); + } + @catch(ICEConnectionLostException*) + { + } + + map = toMap([[serverMetrics getMetricsView:@"View" timestamp:×tamp] objectForKey:@"Dispatch"]); + test([map count] == 6); + + ICEMXDispatchMetrics* dm1 = (ICEMXDispatchMetrics*)[map objectForKey:@"op"]; + test(dm1.current <= 1 && dm1.total == 1 && dm1.failures == 0 && dm1.userException == 0); + test(dm1.size == 21 && dm1.replySize == 7); + + dm1 = (ICEMXDispatchMetrics*)[map objectForKey:@"opWithUserException"]; + test(dm1.current <= 1 && dm1.total == 1 && dm1.failures == 0 && dm1.userException == 1); + test(dm1.size == 38 && dm1.replySize == 23); + + dm1 = (ICEMXDispatchMetrics*)[map objectForKey:@"opWithLocalException"]; + test(dm1.current <= 1 && dm1.total == 1 && dm1.failures == 1 && dm1.userException == 0); + checkFailure(serverMetrics, @"Dispatch", dm1.id_, @"Ice::SyscallException", 1); + test(dm1.size == 39 && dm1.replySize > 7); // Reply contains the exception stack depending on the OS. + + dm1 = (ICEMXDispatchMetrics*)[map objectForKey:@"opWithRequestFailedException"]; + test(dm1.current <= 1 && dm1.total == 1 && dm1.failures == 1 && dm1.userException == 0); + checkFailure(serverMetrics, @"Dispatch", dm1.id_, @"Ice::ObjectNotExistException", 1); + test(dm1.size == 47 && dm1.replySize == 40); + + dm1 = (ICEMXDispatchMetrics*)[map objectForKey:@"opWithUnknownException"]; + test(dm1.current <= 1 && dm1.total == 1 && dm1.failures == 1 && dm1.userException == 0); + checkFailure(serverMetrics, @"Dispatch", dm1.id_, @"IceObjC::Exception", 1); + test(dm1.size == 41 && dm1.replySize > 7); // Reply contains the exception stack depending on the OS. + + InvokeOp* op = [InvokeOp invokeOp:metrics]; + testAttribute(serverMetrics, serverProps, update, @"Dispatch", @"parent", @"TestAdapter", op); + testAttribute(serverMetrics, serverProps, update, @"Dispatch", @"id", @"metrics [op]", op); + testAttribute(serverMetrics, serverProps, update, @"Dispatch", @"endpoint", + @"tcp -h 127.0.0.1 -p 12010 -t 60000", op); + //testAttribute(serverMetrics, serverProps, update, "Dispatch", "connection", "", op); + + testAttribute(serverMetrics, serverProps, update, @"Dispatch", @"endpointType", @"1", op); + testAttribute(serverMetrics, serverProps, update, @"Dispatch", @"endpointIsDatagram", @"false", op); + testAttribute(serverMetrics, serverProps, update, @"Dispatch", @"endpointIsSecure", @"false", op); + testAttribute(serverMetrics, serverProps, update, @"Dispatch", @"endpointTimeout", @"60000", op); + testAttribute(serverMetrics, serverProps, update, @"Dispatch", @"endpointCompress", @"false", op); + testAttribute(serverMetrics, serverProps, update, @"Dispatch", @"endpointHost", @"127.0.0.1", op); + testAttribute(serverMetrics, serverProps, update, @"Dispatch", @"endpointPort", @"12010", op); + + testAttribute(serverMetrics, serverProps, update, @"Dispatch", @"incoming", @"true", op); + testAttribute(serverMetrics, serverProps, update, @"Dispatch", @"adapterName", @"TestAdapter", op); + testAttribute(serverMetrics, serverProps, update, @"Dispatch", @"connectionId", @"", op); + testAttribute(serverMetrics, serverProps, update, @"Dispatch", @"localHost", @"127.0.0.1", op); + testAttribute(serverMetrics, serverProps, update, @"Dispatch", @"localPort", @"12010", op); + testAttribute(serverMetrics, serverProps, update, @"Dispatch", @"remoteHost", @"127.0.0.1", op); + //testAttribute(serverMetrics, serverProps, update, "Dispatch", "remotePort", "12010", op); + testAttribute(serverMetrics, serverProps, update, @"Dispatch", @"mcastHost", @"", op); + testAttribute(serverMetrics, serverProps, update, @"Dispatch", @"mcastPort", @"", op); + + testAttribute(serverMetrics, serverProps, update, @"Dispatch", @"operation", @"op", op); + testAttribute(serverMetrics, serverProps, update, @"Dispatch", @"identity", @"metrics", op); + testAttribute(serverMetrics, serverProps, update, @"Dispatch", @"facet", @"", op); + testAttribute(serverMetrics, serverProps, update, @"Dispatch", @"mode", @"twoway", op); + + testAttribute(serverMetrics, serverProps, update, @"Dispatch", @"context.entry1", @"test", op); + testAttribute(serverMetrics, serverProps, update, @"Dispatch", @"context.entry2", @"", op); + testAttribute(serverMetrics, serverProps, update, @"Dispatch", @"context.entry3", @"", op); + + tprintf("ok\n"); + + tprintf("testing invocation metrics... "); + + [props setObject:@"operation" forKey:@"IceMX.Metrics.View.Map.Invocation.GroupBy"]; + [props setObject:@"localPort" forKey:@"IceMX.Metrics.View.Map.Invocation.Map.Remote.GroupBy"]; + updateProps(clientProps, serverProps, update, props, @"Invocation"); + test([[[serverMetrics getMetricsView:@"View" timestamp:×tamp] objectForKey:@"Invocation"] count] == 0); + + Callback* cb = [Callback callback]; + + void(^responseCB)() = ^() + { + [cb response]; + }; + + void(^exceptionCB)(ICEException*) = ^(ICEException* ex) + { + [cb exception:ex]; + }; + + [metrics op]; + [metrics end_op:[metrics begin_op]]; + [metrics begin_op:responseCB exception:exceptionCB]; + [cb waitForResponse]; + + // User exception + @try + { + [metrics opWithUserException]; + test(NO); + } + @catch(TestMetricsUserEx*) + { + } + @try + { + [metrics end_opWithUserException:[metrics begin_opWithUserException]]; + test(NO); + } + @catch(const TestMetricsUserEx*) + { + } + [metrics begin_opWithUserException:responseCB exception:exceptionCB]; + [cb waitForResponse]; + + // Request failed exception + @try + { + [metrics opWithRequestFailedException]; + test(NO); + } + @catch(ICERequestFailedException*) + { + } + @try + { + [metrics end_opWithRequestFailedException:[metrics begin_opWithRequestFailedException]]; + test(NO); + } + @catch(const ICERequestFailedException*) + { + } + [metrics begin_opWithRequestFailedException:responseCB exception:exceptionCB]; + [cb waitForResponse]; + + // Local exception + @try + { + [metrics opWithLocalException]; + test(NO); + } + @catch(ICELocalException*) + { + } + @try + { + [metrics end_opWithLocalException:[metrics begin_opWithLocalException]]; + test(NO); + } + @catch(ICELocalException*) + { + } + [metrics begin_opWithLocalException:responseCB exception:exceptionCB]; + [cb waitForResponse]; + + // Unknown exception + @try + { + [metrics opWithUnknownException]; + test(NO); + } + @catch(ICEUnknownException*) + { + } + @try + { + [metrics end_opWithUnknownException:[metrics begin_opWithUnknownException]]; + test(NO); + } + @catch(ICEUnknownException*) + { + } + [metrics begin_opWithUnknownException:responseCB exception:exceptionCB]; + [cb waitForResponse]; + + // Fail + @try + { + [metrics fail]; + test(NO); + } + @catch(ICEConnectionLostException*) + { + } + @try + { + [metrics end_fail:[metrics begin_fail]]; + test(NO); + } + @catch(ICEConnectionLostException*) + { + } + [metrics begin_fail:responseCB exception:exceptionCB]; + [cb waitForResponse]; + + map = toMap([[clientMetrics getMetricsView:@"View" timestamp:×tamp] objectForKey:@"Invocation"]); + test([map count] == 6); + + ICEMXInvocationMetrics* im1; + ICEMXRemoteMetrics* rim1; + im1 = (ICEMXInvocationMetrics*)[map objectForKey:@"op"]; + test(im1.current <= 1 && im1.total == 3 && im1.failures == 0 && im1.retry == 0 && [im1.remotes count] == 1); + rim1 = (ICEMXRemoteMetrics*)[im1.remotes objectAtIndex:0]; + test(rim1.current == 0 && rim1.total == 3 && rim1.failures == 0); + test(rim1.size == 63 && rim1.replySize == 21); + + im1 = (ICEMXInvocationMetrics*)[map objectForKey:@"opWithUserException"]; + test(im1.current <= 1 && im1.total == 3 && im1.failures == 0 && im1.retry == 0 && [im1.remotes count] == 1); + rim1 = (ICEMXRemoteMetrics*)[im1.remotes objectAtIndex:0]; + test(rim1.current == 0 && rim1.total == 3 && rim1.failures == 0); + test(rim1.size == 114 && rim1.replySize == 69); + test(im1.userException == 3); + + im1 = (ICEMXInvocationMetrics*)[map objectForKey:@"opWithLocalException"]; + test(im1.current <= 1 && im1.total == 3 && im1.failures == 3 && im1.retry == 0 && [im1.remotes count] == 1); + rim1 = (ICEMXRemoteMetrics*)[im1.remotes objectAtIndex:0]; + test(rim1.current == 0 && rim1.total == 3 && rim1.failures == 0); + test(rim1.size == 117 && rim1.replySize > 7); + checkFailure(clientMetrics, @"Invocation", im1.id_, @"Ice::UnknownLocalException", 3); + + im1 = (ICEMXInvocationMetrics*)[map objectForKey:@"opWithRequestFailedException"]; + test(im1.current <= 1 && im1.total == 3 && im1.failures == 3 && im1.retry == 0 && [im1.remotes count] == 1); + rim1 = (ICEMXRemoteMetrics*)[im1.remotes objectAtIndex:0]; + test(rim1.current == 0 && rim1.total == 3 && rim1.failures == 0); + test(rim1.size == 141 && rim1.replySize == 120); + checkFailure(clientMetrics, @"Invocation", im1.id_, @"Ice::ObjectNotExistException", 3); + + im1 = (ICEMXInvocationMetrics*)[map objectForKey:@"opWithUnknownException"]; + test(im1.current <= 1 && im1.total == 3 && im1.failures == 3 && im1.retry == 0 && [im1.remotes count] == 1); + rim1 = (ICEMXRemoteMetrics*)[im1.remotes objectAtIndex:0]; + test(rim1.current == 0 && rim1.total == 3 && rim1.failures == 0); + checkFailure(clientMetrics, @"Invocation", im1.id_, @"Ice::UnknownException", 3); + + im1 = (ICEMXInvocationMetrics*)[map objectForKey:@"fail"]; + test(im1.current <= 1 && im1.total == 3 && im1.failures == 3 && im1.retry == 3 && [im1.remotes count] == 6); + + test(((ICEMXMetrics*)[im1.remotes objectAtIndex:0]).current == 0 && + ((ICEMXMetrics*)[im1.remotes objectAtIndex:0]).total == 1 && + ((ICEMXMetrics*)[im1.remotes objectAtIndex:0]).failures == 1); + + test(((ICEMXMetrics*)[im1.remotes objectAtIndex:1]).current == 0 && + ((ICEMXMetrics*)[im1.remotes objectAtIndex:1]).total == 1 && + ((ICEMXMetrics*)[im1.remotes objectAtIndex:1]).failures == 1); + + test(((ICEMXMetrics*)[im1.remotes objectAtIndex:2]).current == 0 && + ((ICEMXMetrics*)[im1.remotes objectAtIndex:2]).total == 1 && + ((ICEMXMetrics*)[im1.remotes objectAtIndex:2]).failures == 1); + + test(((ICEMXMetrics*)[im1.remotes objectAtIndex:3]).current == 0 && + ((ICEMXMetrics*)[im1.remotes objectAtIndex:3]).total == 1 && + ((ICEMXMetrics*)[im1.remotes objectAtIndex:3]).failures == 1); + + test(((ICEMXMetrics*)[im1.remotes objectAtIndex:4]).current == 0 && + ((ICEMXMetrics*)[im1.remotes objectAtIndex:4]).total == 1 && + ((ICEMXMetrics*)[im1.remotes objectAtIndex:4]).failures == 1); + + test(((ICEMXMetrics*)[im1.remotes objectAtIndex:5]).current == 0 && + ((ICEMXMetrics*)[im1.remotes objectAtIndex:5]).total == 1 && + ((ICEMXMetrics*)[im1.remotes objectAtIndex:5]).failures == 1); + + checkFailure(clientMetrics, @"Invocation", im1.id_, @"Ice::ConnectionLostException", 3); + + testAttribute(clientMetrics, clientProps, update, @"Invocation", @"parent", @"Communicator", op); + testAttribute(clientMetrics, clientProps, update, @"Invocation", @"id", @"metrics -t -e 1.1 [op]", op); + + testAttribute(clientMetrics, clientProps, update, @"Invocation", @"operation", @"op", op); + testAttribute(clientMetrics, clientProps, update, @"Invocation", @"identity", @"metrics", op); + testAttribute(clientMetrics, clientProps, update, @"Invocation", @"facet", @"", op); + testAttribute(clientMetrics, clientProps, update, @"Invocation", @"encoding", @"1.1", op); + testAttribute(clientMetrics, clientProps, update, @"Invocation", @"mode", @"twoway", op); + testAttribute(clientMetrics, clientProps, update, @"Invocation", @"proxy", + @"metrics -t -e 1.1:tcp -h 127.0.0.1 -p 12010 -t 60000", op); + + testAttribute(clientMetrics, clientProps, update, @"Invocation", @"context.entry1", @"test", op); + testAttribute(clientMetrics, clientProps, update, @"Invocation", @"context.entry2", @"", op); + testAttribute(clientMetrics, clientProps, update, @"Invocation", @"context.entry3", @"", op); + + tprintf("ok\n"); + + tprintf("testing metrics view enable/disable..."); + + + [props setObject:@"none" forKey:@"IceMX.Metrics.View.GroupBy"]; + [props setObject:@"0" forKey:@"IceMX.Metrics.View.Disabled"]; + updateProps(clientProps, serverProps, update, props, @"Thread"); + test([[[clientMetrics getMetricsView:@"View" timestamp:×tamp] objectForKey:@"Thread"] count] > 0); + + ICEMutableStringSeq* disabledViews; + ICEMutableStringSeq* names = [clientMetrics getMetricsViewNames:&disabledViews]; + test([names count] == 1 && [disabledViews count] == 0); + + [props setObject:@"1" forKey:@"IceMX.Metrics.View.Disabled"]; + updateProps(clientProps, serverProps, update, props, @"Thread"); + test([[[clientMetrics getMetricsView:@"View" timestamp:×tamp] objectForKey:@"Thread"] count] == 0); + test([[clientMetrics getMetricsViewNames:&disabledViews] count] == 0 && [disabledViews count] == 1); + + [clientMetrics enableMetricsView:@"View"]; + test([[[clientMetrics getMetricsView:@"View" timestamp:×tamp] objectForKey:@"Thread"] count] > 0); + test([[clientMetrics getMetricsViewNames:&disabledViews] count] == 1 && [disabledViews count] == 0); + + [clientMetrics disableMetricsView:@"View"]; + test([[[clientMetrics getMetricsView:@"View" timestamp:×tamp] objectForKey:@"Thread"] count] == 0); + test([[clientMetrics getMetricsViewNames:&disabledViews] count] == 0 && [disabledViews count] == 1); + + @try + { + [clientMetrics enableMetricsView:@"UnknownView"]; + } + @catch(ICEMXUnknownMetricsView*) + { + } + + tprintf("ok\n"); + + return metrics; +} diff --git a/objective-c/test/Ice/metrics/Client.m b/objective-c/test/Ice/metrics/Client.m new file mode 100644 index 00000000000..f7b5bfdbb65 --- /dev/null +++ b/objective-c/test/Ice/metrics/Client.m @@ -0,0 +1,82 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <TestCommon.h> +#import <MetricsTest.h> + +static int +run(id<ICECommunicator> communicator) +{ + id<TestMetricsMetricsPrx> metricsAllTests(id<ICECommunicator>); + id<TestMetricsMetricsPrx> metrics = metricsAllTests(communicator); + [metrics shutdown]; + return EXIT_SUCCESS; +} + +#if TARGET_OS_IPHONE +# define main metricsClient +#endif + +int +main(int argc, char* argv[]) +{ + int status; + @autoreleasepool + { + id<ICECommunicator> communicator = nil; + + @try + { + ICEInitializationData* initData = [ICEInitializationData initializationData]; + initData.properties = defaultClientProperties(&argc, argv); + [initData.properties setProperty:@"Ice.Admin.Endpoints" value:@"tcp"]; + [initData.properties setProperty:@"Ice.Admin.InstanceName" value:@"client"]; + [initData.properties setProperty:@"Ice.Admin.DelayCreation" value:@"1"]; + [initData.properties setProperty:@"Ice.Warn.Connections" value:@"0"]; + [initData.properties setProperty:@"Ice.MessageSizeMax" value:@"50000"]; + + [initData.properties setProperty:@"IceMX.Metrics.Debug.GroupBy" value:@"id"]; + [initData.properties setProperty:@"IceMX.Metrics.Parent.GroupBy" value:@"parent"]; + [initData.properties setProperty:@"IceMX.Metrics.All.GroupBy" value:@"none"]; + [initData.properties setProperty:@"Ice.Default.Host" value:@"127.0.0.1"]; +#if TARGET_OS_IPHONE + initData.prefixTable__ = [NSDictionary dictionaryWithObjectsAndKeys: + @"TestMetrics", @"::Test", + @"ICEMX", @"::IceMX", + nil]; +#endif + communicator = [ICEUtil createCommunicator:&argc argv:argv initData:initData]; + status = run(communicator); + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + @catch(TestFailedException* ex) + { + status = EXIT_FAILURE; + } + + if(communicator) + { + @try + { + [communicator destroy]; + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + } + } + return status; +} diff --git a/objective-c/test/Ice/metrics/Makefile b/objective-c/test/Ice/metrics/Makefile new file mode 100644 index 00000000000..4903fcb6485 --- /dev/null +++ b/objective-c/test/Ice/metrics/Makefile @@ -0,0 +1,37 @@ +# ********************************************************************** +# +# Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +# +# This copy of Ice is licensed to you under the terms described in the +# ICE_LICENSE file included in this distribution. +# +# ********************************************************************** + +top_srcdir = ../../.. + +CLIENT = client +SERVER = server + +TARGETS = $(CLIENT) $(SERVER) + +SLICE_OBJS = MetricsTest.o + +COBJS = Client.o \ + AllTests.o + +SOBJS = TestI.o \ + Server.o + +OBJS = $(COBJS) $(SOBJS) $(SLICE_OBJS) + +include $(top_srcdir)/config/Make.rules + +CPPFLAGS := -I. -I.. -I../../include $(CPPFLAGS) + +$(CLIENT): $(COBJS) $(SLICE_OBJS) + rm -f $@ + $(CXX) $(LDFLAGS) $(LDEXEFLAGS) -o $@ $(COBJS) $(SLICE_OBJS) $(TEST_LIBS) + +$(SERVER): $(SOBJS) $(SLICE_OBJS) + rm -f $@ + $(CXX) $(LDFLAGS) $(LDEXEFLAGS) -o $@ $(SOBJS) $(SLICE_OBJS) $(TEST_LIBS) diff --git a/objective-c/test/Ice/metrics/MetricsTest.ice b/objective-c/test/Ice/metrics/MetricsTest.ice new file mode 100644 index 00000000000..405a570c0c9 --- /dev/null +++ b/objective-c/test/Ice/metrics/MetricsTest.ice @@ -0,0 +1,51 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#pragma once + +["objc:prefix:TestMetrics"] +module Test +{ + +exception UserEx +{ +}; + +sequence<byte> ByteSeq; + +interface Metrics +{ + void op(); + + idempotent void fail(); + + void opWithUserException() + throws UserEx; + + void opWithRequestFailedException(); + + void opWithLocalException(); + + void opWithUnknownException(); + + void opByteS(ByteSeq bs); + + Object* getAdmin(); + + void shutdown(); +}; + +interface Controller +{ + void hold(); + + void resume(); +}; + +}; diff --git a/objective-c/test/Ice/metrics/Server.m b/objective-c/test/Ice/metrics/Server.m new file mode 100644 index 00000000000..89b72ab1d97 --- /dev/null +++ b/objective-c/test/Ice/metrics/Server.m @@ -0,0 +1,92 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <metrics/TestI.h> +#import <TestCommon.h> + +static int +run(id<ICECommunicator> communicator) +{ + [[communicator getProperties] setProperty:@"TestAdapter.Endpoints" value:@"default -p 12010"]; + id<ICEObjectAdapter> adapter = [communicator createObjectAdapter:@"TestAdapter"]; + + ICEObject* object = [MetricsI metrics]; + [adapter add:object identity:[communicator stringToIdentity:@"metrics"]]; + [adapter activate]; + + [[communicator getProperties] setProperty:@"ControllerAdapter.Endpoints" value:@"default -p 12011"]; + id<ICEObjectAdapter> controllerAdapter = [communicator createObjectAdapter:@"ControllerAdapter"]; + + ICEObject* controller = ICE_AUTORELEASE([[ControllerI alloc] init:adapter]); + [controllerAdapter add:controller identity:[communicator stringToIdentity:@"controller"]]; + [controllerAdapter activate]; + + serverReady(communicator); + + [communicator waitForShutdown]; + + return EXIT_SUCCESS; +} + +#if TARGET_OS_IPHONE +# define main metricsServer +#endif + +int +main(int argc, char* argv[]) +{ + int status; + @autoreleasepool + { + id<ICECommunicator> communicator = nil; + @try + { + ICEInitializationData* initData = [ICEInitializationData initializationData]; + initData.properties = defaultServerProperties(&argc, argv); + [initData.properties setProperty:@"Ice.Admin.Endpoints" value:@"tcp"]; + [initData.properties setProperty:@"Ice.Admin.InstanceName" value:@"server"]; + [initData.properties setProperty:@"Ice.Warn.Connections" value:@"0"]; + [initData.properties setProperty:@"Ice.Warn.Dispatch" value:@"0"]; + [initData.properties setProperty:@"Ice.MessageSizeMax" value:@"50000"]; + + [initData.properties setProperty:@"IceMX.Metrics.Debug.GroupBy" value:@"id"]; + [initData.properties setProperty:@"IceMX.Metrics.Parent.GroupBy" value:@"parent"]; + [initData.properties setProperty:@"IceMX.Metrics.All.GroupBy" value:@"none"]; + [initData.properties setProperty:@"Ice.Default.Host" value:@"127.0.0.1"]; +#if TARGET_OS_IPHONE + initData.prefixTable__ = [NSDictionary dictionaryWithObjectsAndKeys: + @"TestMetrics", @"::Test", + @"ICEMX", @"::IceMX", + nil]; +#endif + communicator = [ICEUtil createCommunicator:&argc argv:argv initData:initData]; + status = run(communicator); + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + + if(communicator) + { + @try + { + [communicator destroy]; + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + } + } + return status; +} diff --git a/objective-c/test/Ice/metrics/TestI.h b/objective-c/test/Ice/metrics/TestI.h new file mode 100644 index 00000000000..a6e09119ce3 --- /dev/null +++ b/objective-c/test/Ice/metrics/TestI.h @@ -0,0 +1,33 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <MetricsTest.h> + +@interface MetricsI : TestMetricsMetrics<TestMetricsMetrics> +-(id) init; +-(void) op:(ICECurrent*)current; +-(void) fail:(ICECurrent*)current; +-(void) opWithUserException:(ICECurrent*)current; +-(void) opWithRequestFailedException:(ICECurrent*)current; +-(void) opWithLocalException:(ICECurrent*)current; +-(void) opWithUnknownException:(ICECurrent*)current; +-(void) opByteS:(ICEByteSeq*)bs current:(ICECurrent*)current; +-(ICEObjectPrx*) getAdmin:(ICECurrent*)current; +-(void) shutdown:(ICECurrent*)current; +@end + +@interface ControllerI : TestMetricsController<TestMetricsController> +{ +@private + id<ICEObjectAdapter> adapter; +} +-(id) init:(id<ICEObjectAdapter>)adapter_p; +-(void) hold:(ICECurrent*)current; +-(void) resume:(ICECurrent*)current; +@end diff --git a/objective-c/test/Ice/metrics/TestI.m b/objective-c/test/Ice/metrics/TestI.m new file mode 100644 index 00000000000..88c5c25c6f3 --- /dev/null +++ b/objective-c/test/Ice/metrics/TestI.m @@ -0,0 +1,94 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <metrics/TestI.h> + +@implementation MetricsI + +-(id) init +{ + self = [super init]; + return self; +} + +-(void) op:(ICECurrent*)current +{ +} + +-(void) fail:(ICECurrent*)current +{ + [current.con close:YES]; +} + +-(void) opWithUserException:(ICECurrent*)current +{ + @throw [TestMetricsUserEx userEx]; +} + +-(void) opWithRequestFailedException:(ICECurrent*)current +{ + @throw [ICEObjectNotExistException objectNotExistException:__FILE__ line:__LINE__]; +} + +-(void) opWithLocalException:(ICECurrent*)current +{ + @throw [ICESyscallException syscallException:__FILE__ line:__LINE__]; +} + +-(void) opWithUnknownException:(ICECurrent*)current +{ + @throw @"TEST"; +} + +-(void) opByteS:(ICEByteSeq*)bs current:(ICECurrent*)current +{ +} + +-(ICEObjectPrx*) getAdmin:(ICECurrent*)current +{ + return [[current.adapter getCommunicator] getAdmin]; +} + +-(void) shutdown:(ICECurrent*)current +{ + [[current.adapter getCommunicator] shutdown]; +} +@end + +@implementation ControllerI +-(id) init:(id<ICEObjectAdapter>)adapter_p +{ + self = [super init]; + if(self) + { + self->adapter = ICE_RETAIN(adapter_p); + } + return self; +} + +#if defined(__clang__) && !__has_feature(objc_arc) +-(void) dealloc +{ + [self->adapter release]; + [super dealloc]; +} +#endif + +-(void) hold:(ICECurrent*)current +{ + [adapter hold]; + [adapter waitForHold]; +} + +-(void) resume:(ICECurrent*)current +{ + [adapter activate]; +} +@end diff --git a/objective-c/test/Ice/metrics/run.py b/objective-c/test/Ice/metrics/run.py new file mode 100755 index 00000000000..ce8c5dd4b18 --- /dev/null +++ b/objective-c/test/Ice/metrics/run.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python +# ********************************************************************** +# +# Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +# +# This copy of Ice is licensed to you under the terms described in the +# ICE_LICENSE file included in this distribution. +# +# ********************************************************************** + +import os, sys + +path = [ ".", "..", "../..", "../../..", "../../../..", "../../../../.." ] +head = os.path.dirname(sys.argv[0]) +if len(head) > 0: + path = [os.path.join(head, p) for p in path] +path = [os.path.abspath(p) for p in path if os.path.exists(os.path.join(p, "scripts", "TestUtil.py")) ] +if len(path) == 0: + raise RuntimeError("can't find toplevel directory!") +sys.path.append(os.path.join(path[0], "scripts")) +import TestUtil + +TestUtil.clientServerTest() diff --git a/objective-c/test/Ice/objects/.gitignore b/objective-c/test/Ice/objects/.gitignore new file mode 100644 index 00000000000..77d9ac7c381 --- /dev/null +++ b/objective-c/test/Ice/objects/.gitignore @@ -0,0 +1,9 @@ +// Generated by makegitignore.py + +// IMPORTANT: Do not edit this file -- any edits made here will be lost! +client +server +collocated +.depend +ObjectsTest.m +ObjectsTest.h diff --git a/objective-c/test/Ice/objects/AllTests.m b/objective-c/test/Ice/objects/AllTests.m new file mode 100644 index 00000000000..47c9e574d91 --- /dev/null +++ b/objective-c/test/Ice/objects/AllTests.m @@ -0,0 +1,514 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <TestCommon.h> +#import <ObjectsTest.h> + +void breakRetainCycleB(); +void breakRetainCycleC(); +void breakRetainCycleD(); + +void breakRetainCycleB(TestObjectsB* b1) +{ + if([b1.theA isKindOfClass:[TestObjectsB class]]) + { + TestObjectsB* b2 = (TestObjectsB*)b1.theA; + b2.theA = nil; + b2.theB.theA = nil; + b2.theB.theB = nil; + b2.theB.theC = nil; + b2.theB = nil; + b2.theC = nil; + b2 = nil; + } + b1.theA = nil; + b1.theB = nil; + b1.theC = nil; +} + +void breakRetainCycleC(TestObjectsC* c1) +{ + breakRetainCycleB(c1.theB); + c1.theB = nil; + +} + +void breakRetainCycleD(TestObjectsD* d1) +{ + breakRetainCycleB((TestObjectsB*)d1.theA); + breakRetainCycleB(d1.theB); +} + +id<TestObjectsInitialPrx> +objectsAllTests(id<ICECommunicator> communicator, BOOL collocated) +{ + tprintf("testing stringToProxy... "); + NSString* ref = @"initial:default -p 12010"; + id<ICEObjectPrx> base = [communicator stringToProxy:ref]; + test(base); + tprintf("ok\n"); + + tprintf("testing checked cast... "); + id<TestObjectsInitialPrx> initial = [TestObjectsInitialPrx checkedCast:base]; + test(initial); + test([initial isEqual:base]); + tprintf("ok\n"); + + tprintf("testing constructor, convenience constructor, and copy... "); + + TestObjectsBase* ba1 = [TestObjectsBase base]; + + test([ba1.theS.str isEqual:@""]); + test([ba1.str isEqual:@""]); + ba1.theS = nil; + + TestObjectsS* s = [TestObjectsS s]; + s.str = @"hello"; + TestObjectsBase* ba2 = [TestObjectsBase base:s str:@"hi"]; + test(ba2.theS == s); + test([ba2.str isEqualToString:@"hi"]); + ba2.theS = nil; + + TestObjectsBase* ba3 = ICE_AUTORELEASE([ba2 copy]); + test(ba3 != ba2); + test(ba3.theS == ba2.theS); + test(ba3.str == ba2.str); + ba3.theS = nil; + +#if 0 + // Can't override assignment operator in Objective-C. + *ba1 = *ba2; + test([ba1.theS.str isEqualToString:@"hello"]); + test([ba1.str isEqualToString:@"hi"]); + + TestObjectsBase* bp1 = [TestObjectsBase base]; + *bp1 = *ba2; + test([bp1.theS.str isEqualToString:@"hello"]); + test([bp1.str isEqualToString:@"hi"]); +#endif + + tprintf("ok\n"); + + tprintf("getting B1... "); + TestObjectsB* b1 = [initial getB1]; + test(b1); + tprintf("ok\n"); + + tprintf("getting B2... "); + TestObjectsB* b2 = [initial getB2]; + test(b2); + tprintf("ok\n"); + + tprintf("getting C... "); + TestObjectsC* c = [initial getC]; + test(c); + tprintf("ok\n"); + + tprintf("getting D... "); + TestObjectsD* d = [initial getD]; + test(d); + tprintf("ok\n"); + + tprintf("checking consistency... "); + test(b1 != b2); + test(b1 != (TestObjectsB*)c); + test(b1 != (TestObjectsB*)d); + test(b2 != (TestObjectsB*)c); + test(b2 != (TestObjectsB*)d); + test(c != (TestObjectsC*)d); + test(b1.theB == b1); + test(b1.theC == 0); + test([b1.theA isKindOfClass:[TestObjectsB class]]); + test(((TestObjectsB*)b1.theA).theA == b1.theA); + test(((TestObjectsB*)b1.theA).theB == b1); + test([((TestObjectsB*)b1.theA).theC isKindOfClass:[TestObjectsC class]]); + test(((TestObjectsC*)((TestObjectsB*)b1.theA).theC).theB == b1.theA); + test(b1.preMarshalInvoked); + test([(id<TestObjectsB>)b1 postUnmarshalInvoked:nil]); + test(b1.theA.preMarshalInvoked); + test([(id<TestObjectsA>)b1.theA postUnmarshalInvoked:nil]); + test(((TestObjectsB*)b1.theA).theC.preMarshalInvoked); + test([(id<TestObjectsC>)((TestObjectsB*)b1.theA).theC postUnmarshalInvoked:nil]); + + // More tests possible for b2 and d, but I think this is already sufficient. + test(b2.theA == b2); + test(d.theC == 0); + + breakRetainCycleB(b1); + breakRetainCycleB(b2); + breakRetainCycleC(c); + breakRetainCycleD(d); + + tprintf("ok\n"); + + tprintf("getting B1, B2, C, and D all at once... "); + [initial getAll:&b1 b2:&b2 theC:&c theD:&d]; + test(b1); + test(b2); + test(c); + test(d); + tprintf("ok\n"); + + tprintf("checking consistency... "); + test(b1 != b2); + test(b1 != (TestObjectsB*)c); + test(b1 != (TestObjectsB*)d); + test(b2 != (TestObjectsB*)c); + test(b2 != (TestObjectsB*)d); + test(c != (TestObjectsC*)d); + test(b1.theA == b2); + test(b1.theB == b1); + //test(b1.theC == 0); + test(b2.theA == b2); + test(b2.theB == b1); + test(b2.theC == c); + test(c.theB == b2); + test(d.theA == b1); + test(d.theB == b2); + //test(d.theC == 0); +// if(!collocated) +// { + test(d.preMarshalInvoked); + test([(id<TestObjectsD>)d postUnmarshalInvoked:nil]); + test(d.theA.preMarshalInvoked); + test([(id<TestObjectsA>)d.theA postUnmarshalInvoked:nil]); + test(d.theB.preMarshalInvoked); + test([(id<TestObjectsA>)d.theB postUnmarshalInvoked:nil]); + test(d.theB.theC.preMarshalInvoked); + test([(id<TestObjectsC>)d.theB.theC postUnmarshalInvoked:nil]); +// } + + breakRetainCycleB(b1); + breakRetainCycleB(b2); + breakRetainCycleC(c); + breakRetainCycleD(d); + + tprintf("ok\n"); + + tprintf("testing protected members... "); + TestObjectsE* e = [initial getE]; + test([(id<TestObjectsE>)e checkValues:nil]); + TestObjectsF* f = [initial getF]; + test([(id<TestObjectsF>)f checkValues:nil]); + test([(id<TestObjectsE>)f.e2 checkValues:nil]); + tprintf("ok\n"); + + tprintf("getting I, J and H... "); + TestObjectsI* i = (TestObjectsI*)[initial getI]; + test(i); + TestObjectsI* j = (TestObjectsI*)[initial getJ]; + test(j && [j isKindOfClass:[TestObjectsJ class]]); + TestObjectsI* h = (TestObjectsI*)[initial getH]; + test(h && [h isKindOfClass:[TestObjectsH class]]); + tprintf("ok\n"); + + tprintf("setting I... "); + [initial setI:i]; + [initial setI:j]; + [initial setI:h]; + tprintf("ok\n"); + + tprintf("testing sequences... "); + TestObjectsMutableBaseSeq* inS = [TestObjectsMutableBaseSeq array]; + TestObjectsMutableBaseSeq* outS; + TestObjectsMutableBaseSeq* retS = [initial opBaseSeq:inS outSeq:&outS]; + + [inS addObject:[TestObjectsBase base]]; + retS = [initial opBaseSeq:inS outSeq:&outS]; + test([retS count] == 1 && [outS count] == 1); + tprintf("ok\n"); + + tprintf("testing compact ID..."); + @try + { + test([initial getCompact]); + } + @catch(ICEOperationNotExistException*) + { + } + tprintf("ok\n"); + +// if(!collocated) +// { + tprintf("testing UnexpectedObjectException... "); + ref = @"uoet:default -p 12010"; + base = [communicator stringToProxy:ref]; + test(base); + id<TestObjectsUnexpectedObjectExceptionTestPrx> uoet = [TestObjectsUnexpectedObjectExceptionTestPrx uncheckedCast:base]; + test(uoet); + @try + { + [uoet op]; + test(NO); + } + @catch(ICEUnexpectedObjectException* ex) + { + test([ex.type isEqualToString:@"::Test::AlsoEmpty"]); + test([ex.expectedType isEqualToString:@"::Test::Empty"]); + } + @catch(ICEException* ex) + { + test(NO); + } + tprintf("ok\n"); +// } + + // + // TestObjectss specific to Objective-C. + // + { + tprintf("setting Object sequence... "); + TestObjectsMutableObjectSeq* seq = [TestObjectsMutableObjectSeq array]; + + [seq addObject:[NSNull null]]; + + TestObjectsBase* b = [TestObjectsBase base]; + b.theS = [TestObjectsS s]; + b.theS.str = @"Hello"; + b.str = @"World"; + [seq addObject:b]; + + @try + { + TestObjectsObjectSeq* r = [initial getObjectSeq:seq]; + test([r objectAtIndex:0 == [NSNull null]]); + TestObjectsBase* br = [r objectAtIndex:1]; + test([br.theS.str isEqualToString:@"Hello"]); + test([br.str isEqualToString:@"World"]); + } + @catch(ICEOperationNotExistException*) + { + // Expected if we are testing against a non-Objective-C server. + } + @catch(...) + { + test(NO); + } + tprintf("ok\n"); + } + + { + tprintf("setting Object proxy sequence... "); + TestObjectsMutableObjectPrxSeq* seq = [TestObjectsMutableObjectPrxSeq array]; + + [seq addObject:[NSNull null]]; + [seq addObject:initial]; + + @try + { + TestObjectsObjectPrxSeq* r = [initial getObjectPrxSeq:seq]; + test([r objectAtIndex:0 == [NSNull null]]); + test([[r objectAtIndex:1] isEqual:initial]); + } + @catch(ICEOperationNotExistException*) + { + // Expected if we are testing against a non-Objective-C server. + } + @catch(...) + { + test(NO); + } + tprintf("ok\n"); + } + + { + tprintf("setting Base sequence... "); + TestObjectsMutableBaseSeq* seq = [TestObjectsMutableBaseSeq array]; + + [seq addObject:[NSNull null]]; + + TestObjectsBase* b = [TestObjectsBase base]; + b.theS = [TestObjectsS s]; + b.theS.str = @"Hello"; + b.str = @"World"; + [seq addObject:b]; + + @try + { + TestObjectsBaseSeq* r = [initial getBaseSeq:seq]; + test([r objectAtIndex:0 == [NSNull null]]); + TestObjectsBase* br = [r objectAtIndex:1]; + test([br.theS.str isEqualToString:@"Hello"]); + test([br.str isEqualToString:@"World"]); + br.theS = nil; + } + @catch(ICEOperationNotExistException*) + { + // Expected if we are testing against a non-Objective-C server. + } + @catch(...) + { + test(NO); + } + + { + TestObjectsBase* br = [seq objectAtIndex:1]; + br.theS = nil; + b.theS = nil; + } + tprintf("ok\n"); + } + + { + tprintf("setting Base proxy sequence... "); + TestObjectsMutableBasePrxSeq* seq = [TestObjectsMutableBasePrxSeq array]; + + [seq addObject:[NSNull null]]; + NSString* ref = @"base:default -p 12010"; + id<ICEObjectPrx> base = [communicator stringToProxy:ref]; + id<TestObjectsBasePrx> b = [TestObjectsBasePrx uncheckedCast:base]; + [seq addObject:b]; + + @try + { + TestObjectsBasePrxSeq* r = [initial getBasePrxSeq:seq]; + test([r objectAtIndex:0 == [NSNull null]]); + test([[r objectAtIndex:1] isEqual:b]); + } + @catch(ICEOperationNotExistException*) + { + // Expected if we are testing against a non-Objective-C server. + } + @catch(...) + { + test(NO); + } + tprintf("ok\n"); + } + + { + tprintf("setting Object dictionary... "); + TestObjectsMutableObjectDict* dict = [TestObjectsMutableObjectDict dictionary]; + + [dict setObject:[NSNull null] forKey:@"zero"]; + + TestObjectsBase* b = [TestObjectsBase base]; + b.theS = [TestObjectsS s]; + b.theS.str = @"Hello"; + b.str = @"World"; + [dict setObject:b forKey:@"one"]; + + @try + { + TestObjectsObjectDict* r = [initial getObjectDict:dict]; + test([r objectForKey:@"zero"] == [NSNull null]); + TestObjectsBase* br = [r objectForKey:@"one"]; + test([br.theS.str isEqualToString:@"Hello"]); + test([br.str isEqualToString:@"World"]); + br.theS = nil; + } + @catch(ICEOperationNotExistException*) + { + // Expected if we are testing against a non-Objective-C server. + } + @catch(...) + { + test(NO); + } + { + TestObjectsBase* br = [dict objectForKey:@"one"]; + br.theS = nil; + b.theS = nil; + } + tprintf("ok\n"); + } + + { + tprintf("setting Object proxy dictionary... "); + TestObjectsMutableObjectPrxDict* dict = [TestObjectsMutableObjectPrxDict dictionary]; + + [dict setObject:[NSNull null] forKey:@"zero"]; + NSString* ref = @"object:default -p 12010"; + id<ICEObjectPrx> o = [communicator stringToProxy:ref]; + [dict setObject:o forKey:@"one"]; + + @try + { + TestObjectsObjectPrxDict* r = [initial getObjectPrxDict:dict]; + test([r objectForKey:@"zero"] == [NSNull null]); + test([[r objectForKey:@"one"] isEqual:o]); + } + @catch(ICEOperationNotExistException*) + { + // Expected if we are testing against a non-Objective-C server. + } + @catch(...) + { + test(NO); + } + tprintf("ok\n"); + } + + { + tprintf("setting Base dictionary... "); + TestObjectsMutableBaseDict* dict = [TestObjectsMutableBaseDict dictionary]; + + [dict setObject:[NSNull null] forKey:@"zero"]; + + TestObjectsBase* b = [TestObjectsBase base]; + b.theS = [TestObjectsS s]; + b.theS.str = @"Hello"; + b.str = @"World"; + [dict setObject:b forKey:@"one"]; + + @try + { + TestObjectsBaseDict* r = [initial getBaseDict:dict]; + test([r objectForKey:@"zero"] == [NSNull null]); + TestObjectsBase* br = [r objectForKey:@"one"]; + test([br.theS.str isEqualToString:@"Hello"]); + test([br.str isEqualToString:@"World"]); + br.theS = nil; + } + @catch(ICEOperationNotExistException*) + { + // Expected if we are testing against a non-Objective-C server. + } + @catch(...) + { + test(NO); + } + { + TestObjectsBase* br = [dict objectForKey:@"one"]; + br.theS = nil; + b.theS = nil; + } + tprintf("ok\n"); + } + + { + tprintf("setting Base proxy dictionary... "); + TestObjectsMutableBasePrxDict* dict = [TestObjectsMutableBasePrxDict dictionary]; + + [dict setObject:[NSNull null] forKey:@"zero"]; + NSString* ref = @"base:default -p 12010"; + id<ICEObjectPrx> base = [communicator stringToProxy:ref]; + id<TestObjectsBasePrx> b = [TestObjectsBasePrx uncheckedCast:base]; + [dict setObject:b forKey:@"one"]; + + @try + { + TestObjectsObjectPrxDict* r = [initial getObjectPrxDict:dict]; + test([r objectForKey:@"zero"] == [NSNull null]); + test([[r objectForKey:@"one"] isEqual:b]); + } + @catch(ICEOperationNotExistException*) + { + // Expected if we are testing against a non-Objective-C server. + } + @catch(...) + { + test(NO); + } + tprintf("ok\n"); + } + + return initial; +} diff --git a/objective-c/test/Ice/objects/Client.m b/objective-c/test/Ice/objects/Client.m new file mode 100644 index 00000000000..aeabb134b02 --- /dev/null +++ b/objective-c/test/Ice/objects/Client.m @@ -0,0 +1,139 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <TestCommon.h> +#import <objects/TestI.h> + +#if !TARGET_OS_IPHONE +# import <Foundation/NSGarbageCollector.h> +#endif + +@interface ClientMyObjectFactory : NSObject<ICEObjectFactory> +@end + +@implementation ClientMyObjectFactory + +// Note that the object factory must not autorelease the +// returned objects. +-(ICEObject*) create:(NSString*)type +{ + if([type isEqualToString:@"::Test::B"]) + { + return [[TestObjectsBI alloc] init]; + } + else if([type isEqualToString:@"::Test::C"]) + { + return [[TestObjectsCI alloc] init]; + } + else if([type isEqualToString:@"::Test::D"]) + { + return [[TestObjectsDI alloc] init]; + } + else if([type isEqualToString:@"::Test::E"]) + { + return [[TestObjectsEI alloc] init]; + } + else if([type isEqualToString:@"::Test::F"]) + { + return [[TestObjectsFI alloc] init]; + } + else if([type isEqualToString:@"::Test::I"]) + { + return [[TestObjectsI alloc] init]; + } + else if([type isEqualToString:@"::Test::J"]) + { + return [[TestObjectsJI alloc] init]; + } + else if([type isEqualToString:@"::Test::H"]) + { + return [[TestObjectsHI alloc] init]; + } + else + { + test(NO); + } + return nil; +} + +-(void) destroy +{ + // Nothing to do +} +@end + +static int +run(id<ICECommunicator> communicator) +{ + id<ICEObjectFactory> factory = ICE_AUTORELEASE([[ClientMyObjectFactory alloc] init]); + + [communicator addObjectFactory:factory sliceId:@"::Test::B"]; + [communicator addObjectFactory:factory sliceId:@"::Test::C"]; + [communicator addObjectFactory:factory sliceId:@"::Test::D"]; + [communicator addObjectFactory:factory sliceId:@"::Test::E"]; + [communicator addObjectFactory:factory sliceId:@"::Test::F"]; + [communicator addObjectFactory:factory sliceId:@"::Test::I"]; + [communicator addObjectFactory:factory sliceId:@"::Test::J"]; + [communicator addObjectFactory:factory sliceId:@"::Test::H"]; + + id<TestObjectsInitialPrx> objectsAllTests(id<ICECommunicator>, bool); + id<TestObjectsInitialPrx> initial = objectsAllTests(communicator, NO); + [initial shutdown]; + return EXIT_SUCCESS; +} + +#if TARGET_OS_IPHONE +# define main objectsClient +#endif + +int +main(int argc, char* argv[]) +{ + int status; + @autoreleasepool + { + id<ICECommunicator> communicator = nil; + @try + { + ICEInitializationData* initData = [ICEInitializationData initializationData]; + initData.properties = defaultClientProperties(&argc, argv); +#if TARGET_OS_IPHONE + initData.prefixTable__ = [NSDictionary dictionaryWithObjectsAndKeys: + @"TestObjects", @"::Test", + nil]; +#endif + communicator = [ICEUtil createCommunicator:&argc argv:argv initData:initData]; + status = run(communicator); + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + @catch(TestFailedException* ex) + { + status = EXIT_FAILURE; + } + + if(communicator) + { + @try + { + [communicator destroy]; + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + } + } + return status; +} diff --git a/objective-c/test/Ice/objects/Collocated.m b/objective-c/test/Ice/objects/Collocated.m new file mode 100644 index 00000000000..1506c1c3293 --- /dev/null +++ b/objective-c/test/Ice/objects/Collocated.m @@ -0,0 +1,142 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <TestCommon.h> +#import <objects/TestI.h> + +@interface CollocatedMyObjectFactory : NSObject<ICEObjectFactory> +@end + +@implementation CollocatedMyObjectFactory + +// Note that the object factory must not autorelease the +// returned objects. +-(ICEObject*) create:(NSString*)type +{ + if([type isEqualToString:@"::Test::B"]) + { + return [[TestObjectsBI alloc] init]; + } + else if([type isEqualToString:@"::Test::C"]) + { + return [[TestObjectsCI alloc] init]; + } + else if([type isEqualToString:@"::Test::D"]) + { + return [[TestObjectsDI alloc] init]; + } + else if([type isEqualToString:@"::Test::E"]) + { + return [[TestObjectsEI alloc] init]; + } + else if([type isEqualToString:@"::Test::F"]) + { + return [[TestObjectsFI alloc] init]; + } + else if([type isEqualToString:@"::Test::I"]) + { + return [[TestObjectsI alloc] init]; + } + else if([type isEqualToString:@"::Test::J"]) + { + return [[TestObjectsJI alloc] init]; + } + else if([type isEqualToString:@"::Test::H"]) + { + return [[TestObjectsHI alloc] init]; + } + else + { + test(NO); + } + return nil; +} + +-(void) destroy +{ + // Nothing to do +} +@end + +static int +run(id<ICECommunicator> communicator) +{ + id<ICEObjectFactory> factory = ICE_AUTORELEASE([[CollocatedMyObjectFactory alloc] init]); + + [communicator addObjectFactory:factory sliceId:@"::Test::B"]; + [communicator addObjectFactory:factory sliceId:@"::Test::C"]; + [communicator addObjectFactory:factory sliceId:@"::Test::D"]; + [communicator addObjectFactory:factory sliceId:@"::Test::E"]; + [communicator addObjectFactory:factory sliceId:@"::Test::F"]; + [communicator addObjectFactory:factory sliceId:@"::Test::I"]; + [communicator addObjectFactory:factory sliceId:@"::Test::J"]; + [communicator addObjectFactory:factory sliceId:@"::Test::H"]; + + [[communicator getProperties] setProperty:@"TestAdapter.Endpoints" value:@"default -p 12010"]; + id<ICEObjectAdapter> adapter = [communicator createObjectAdapter:@"TestAdapter"]; + TestObjectsInitialI* initial = [TestObjectsInitialI initial]; + [adapter add:initial identity:[communicator stringToIdentity:@"initial"]]; + + ICEObject* uoet = ICE_AUTORELEASE([[UnexpectedObjectExceptionTestI alloc] init]); + [adapter add:uoet identity:[communicator stringToIdentity:@"uoet"]]; + + id<TestObjectsInitialPrx> objectsAllTests(id<ICECommunicator>, bool); + objectsAllTests(communicator, NO); + + // We must call shutdown even in the collocated case for cyclic dependency cleanup + [initial shutdown:nil]; + + return EXIT_SUCCESS; +} + +#if TARGET_OS_IPHONE +# define main objectsCollocated +#endif + +int +main(int argc, char* argv[]) +{ + int status; + @autoreleasepool + { + id<ICECommunicator> communicator = nil; + @try + { + ICEInitializationData* initData = [ICEInitializationData initializationData]; + initData.properties = defaultServerProperties(&argc, argv); +#if TARGET_OS_IPHONE + initData.prefixTable__ = [NSDictionary dictionaryWithObjectsAndKeys: + @"TestObjects", @"::Test", + nil]; +#endif + communicator = [ICEUtil createCommunicator:&argc argv:argv initData:initData]; + status = run(communicator); + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + + if(communicator) + { + @try + { + [communicator destroy]; + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + } + } + return status; +} diff --git a/objective-c/test/Ice/objects/Makefile b/objective-c/test/Ice/objects/Makefile new file mode 100644 index 00000000000..6dbc4fdb29d --- /dev/null +++ b/objective-c/test/Ice/objects/Makefile @@ -0,0 +1,47 @@ +# ********************************************************************** +# +# Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +# +# This copy of Ice is licensed to you under the terms described in the +# ICE_LICENSE file included in this distribution. +# +# ********************************************************************** + +top_srcdir = ../../.. + +CLIENT = client +SERVER = server +COLLOCATED = collocated + +TARGETS = $(CLIENT) $(SERVER) $(COLLOCATED) + +SLICE_OBJS = ObjectsTest.o + +COBJS = Client.o \ + TestI.o \ + AllTests.o + +SOBJS = TestI.o \ + Server.o + +COLOBJS = Collocated.o \ + TestI.o \ + AllTests.o + +OBJS = $(COBJS) $(SOBJS) $(COLOBJS) $(SLICE_OBJS) + +include $(top_srcdir)/config/Make.rules + +CPPFLAGS := -I. -I.. -I../../include $(CPPFLAGS) + +$(CLIENT): $(COBJS) $(SLICE_OBJS) + rm -f $@ + $(CXX) $(LDFLAGS) $(LDEXEFLAGS) -o $@ $(COBJS) $(SLICE_OBJS) $(TEST_LIBS) + +$(SERVER): $(SOBJS) $(SLICE_OBJS) + rm -f $@ + $(CXX) $(LDFLAGS) $(LDEXEFLAGS) -o $@ $(SOBJS) $(SLICE_OBJS) $(TEST_LIBS) + +$(COLLOCATED): $(COLOBJS) $(SLICE_OBJS) + rm -f $@ + $(CXX) $(LDFLAGS) $(LDEXEFLAGS) -o $@ $(COLOBJS) $(SLICE_OBJS) $(TEST_LIBS) diff --git a/objective-c/test/Ice/objects/ObjectsTest.ice b/objective-c/test/Ice/objects/ObjectsTest.ice new file mode 100644 index 00000000000..afe41d9d904 --- /dev/null +++ b/objective-c/test/Ice/objects/ObjectsTest.ice @@ -0,0 +1,201 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#pragma once + +["objc:prefix:TestObjects"] +module Test +{ + +struct S +{ + string str; +}; + +class Base +{ + S theS; + string str; +}; + +class B; +class C; + +class A +{ + B theB; + C theC; + + bool preMarshalInvoked; + bool postUnmarshalInvoked(); +}; + +class B extends A +{ + A theA; +}; + +class C +{ + B theB; + + bool preMarshalInvoked; + bool postUnmarshalInvoked(); +}; + +class D +{ + A theA; + B theB; + C theC; + + bool preMarshalInvoked; + bool postUnmarshalInvoked(); +}; + +["protected"] class E +{ + int i; + string s; + + bool checkValues(); +}; + +class F +{ + ["protected"] E e1; + E e2; + + bool checkValues(); +}; + +interface I +{ +}; + +interface J extends I +{ +}; + +class H implements I +{ +}; + +class CompactExt; + +class Compact(1) +{ +}; + +const int CompactExtId = 789; + +class CompactExt(CompactExtId) extends Compact +{ +}; + +sequence<Object> ObjectSeq; // For Objective-C only +sequence<Object*> ObjectPrxSeq; // For Objective-C only +sequence<Base> BaseSeq; // For Objective-C only +sequence<Base*> BasePrxSeq; // For Objective-C only + +dictionary<string, Object> ObjectDict; // For Objective-C only +dictionary<string, Object*> ObjectPrxDict; // For Objective-C only +dictionary<string, Base> BaseDict; // For Objective-C only +dictionary<string, Base*> BasePrxDict; // For Objective-C only + +class Initial +{ + void shutdown(); + B getB1(); + B getB2(); + C getC(); + D getD(); + E getE(); + F getF(); + + void getAll(out B b1, out B b2, out C theC, out D theD); + + I getI(); + I getJ(); + I getH(); + + void setI(I theI); + + BaseSeq opBaseSeq(BaseSeq inSeq, out BaseSeq outSeq); + + Compact getCompact(); + + // + // Remaining operations are here only for Objective-C and are not implemented by other language mappings. + // + ObjectSeq getObjectSeq(ObjectSeq s); + ObjectPrxSeq getObjectPrxSeq(ObjectPrxSeq s); + BaseSeq getBaseSeq(BaseSeq s); + BasePrxSeq getBasePrxSeq(BasePrxSeq s); + + ObjectDict getObjectDict(ObjectDict d); + ObjectPrxDict getObjectPrxDict(ObjectPrxDict d); + BaseDict getBaseDict(BaseDict d); + BasePrxDict getBasePrxDict(BasePrxDict d); +}; + +class Empty +{ +}; + +class AlsoEmpty +{ +}; + +interface UnexpectedObjectExceptionTest +{ + Empty op(); +}; + +// +// Remaining definitions are here to ensure that the generated code compiles. +// + +class COneMember +{ + Empty e; +}; + +class CTwoMembers +{ + Empty e1; + Empty e2; +}; + +exception EOneMember +{ + Empty e; +}; + +exception ETwoMembers +{ + Empty e1; + Empty e2; +}; + +struct SOneMember +{ + Empty e; +}; + +struct STwoMembers +{ + Empty e1; + Empty e2; +}; + +dictionary<int, COneMember> DOneMember; +dictionary<int, CTwoMembers> DTwoMembers; + +}; diff --git a/objective-c/test/Ice/objects/Server.m b/objective-c/test/Ice/objects/Server.m new file mode 100644 index 00000000000..a8431a61509 --- /dev/null +++ b/objective-c/test/Ice/objects/Server.m @@ -0,0 +1,114 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <TestCommon.h> +#import <objects/TestI.h> + +@interface ServerMyObjectFactory : NSObject<ICEObjectFactory> +@end + +@implementation ServerMyObjectFactory +// Note that the object factory must not autorelease the +// returned objects. +-(ICEObject*) create:(NSString*)type +{ + if([type isEqualToString:@"::Test::I"]) + { + return [[TestObjectsI alloc] init]; + } + else if([type isEqualToString:@"::Test::J"]) + { + return [[TestObjectsJI alloc] init]; + } + else if([type isEqualToString:@"::Test::H"]) + { + return [[TestObjectsHI alloc] init]; + } + else + { + test(NO); // Should never be reached + } + return nil; +} + +-(void) destroy +{ + // Nothing to do +} +@end + +static int +run(id<ICECommunicator> communicator) +{ + id<ICEObjectFactory> factory = ICE_AUTORELEASE([[ServerMyObjectFactory alloc] init]); + + [communicator addObjectFactory:factory sliceId:@"::Test::I"]; + [communicator addObjectFactory:factory sliceId:@"::Test::J"]; + [communicator addObjectFactory:factory sliceId:@"::Test::H"]; + + [[communicator getProperties] setProperty:@"TestAdapter.Endpoints" value:@"default -p 12010"]; + id<ICEObjectAdapter> adapter = [communicator createObjectAdapter:@"TestAdapter"]; + ICEObject* initial = [TestObjectsInitialI initial]; + [adapter add:initial identity:[communicator stringToIdentity:@"initial"]]; + + ICEObject* uoet = ICE_AUTORELEASE([[UnexpectedObjectExceptionTestI alloc] init]); + [adapter add:uoet identity:[communicator stringToIdentity:@"uoet"]]; + [adapter activate]; + + serverReady(communicator); + + [communicator waitForShutdown]; + return EXIT_SUCCESS; +} + +#if TARGET_OS_IPHONE +# define main objectsServer +#endif + +int +main(int argc, char* argv[]) +{ + int status; + @autoreleasepool + { + id<ICECommunicator> communicator = nil; + @try + { + ICEInitializationData* initData = [ICEInitializationData initializationData]; + initData.properties = defaultServerProperties(&argc, argv); +#if TARGET_OS_IPHONE + initData.prefixTable__ = [NSDictionary dictionaryWithObjectsAndKeys: + @"TestObjects", @"::Test", + nil]; +#endif + communicator = [ICEUtil createCommunicator:&argc argv:argv initData:initData]; + status = run(communicator); + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + + if(communicator) + { + @try + { + [communicator destroy]; + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + } + } + return status; +} diff --git a/objective-c/test/Ice/objects/TestI.h b/objective-c/test/Ice/objects/TestI.h new file mode 100644 index 00000000000..b0ddf730f3b --- /dev/null +++ b/objective-c/test/Ice/objects/TestI.h @@ -0,0 +1,79 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <ObjectsTest.h> + +@interface TestObjectsBI : TestObjectsB<TestObjectsB> +{ + BOOL _postUnmarshalInvoked; +} +@end + +@interface TestObjectsCI : TestObjectsC<TestObjectsC> +{ + BOOL _postUnmarshalInvoked; +} +@end + +@interface TestObjectsDI : TestObjectsD<TestObjectsD> +{ + BOOL _postUnmarshalInvoked; +} +@end + +@interface TestObjectsEI : TestObjectsE<TestObjectsE> +@end + +@interface TestObjectsFI : TestObjectsF<TestObjectsF> +@end + +//@interface TestObjectsII : TestObjectsI<TestObjectsI> +//@end + +@interface TestObjectsJI : TestObjectsJ<TestObjectsJ> +@end + +@interface TestObjectsHI : TestObjectsH<TestObjectsH> +@end + +@interface TestObjectsInitialI : TestObjectsInitial<TestObjectsInitial> +{ + TestObjectsB* _b1; + TestObjectsB* _b2; + TestObjectsC* _c; + TestObjectsD* _d; + TestObjectsE* _e; + TestObjectsF* _f; +} +-(id) init; +-(void) shutdown:(ICECurrent*)current; +-(TestObjectsB *) getB1:(ICECurrent *)current; +-(TestObjectsB *) getB2:(ICECurrent *)current; +-(TestObjectsC *) getC:(ICECurrent *)current; +-(TestObjectsD *) getD:(ICECurrent *)current; +-(TestObjectsE *) getE:(ICECurrent *)current; +-(TestObjectsF *) getF:(ICECurrent *)current; +-(void) getAll:(TestObjectsB **)b1 b2:(TestObjectsB **)b2 theC:(TestObjectsC **)theC theD:(TestObjectsD **)theD current:(ICECurrent *)current; +-(TestObjectsI *) getI:(ICECurrent *)current; +-(TestObjectsI *) getJ:(ICECurrent *)current; +-(TestObjectsI *) getH:(ICECurrent *)current; +-(TestObjectsCompact*) getCompact:(ICECurrent*)current; +-(void) setI:(TestObjectsI *)theI current:(ICECurrent *)current; +-(TestObjectsObjectSeq *) getObjectSeq:(TestObjectsMutableObjectSeq *)s current:(ICECurrent *)current; +-(TestObjectsObjectPrxSeq *) getObjectPrxSeq:(TestObjectsMutableObjectPrxSeq *)s current:(ICECurrent *)current; +-(TestObjectsBaseSeq *) getBaseSeq:(TestObjectsMutableBaseSeq *)s current:(ICECurrent *)current; +-(TestObjectsBasePrxSeq *) getBasePrxSeq:(TestObjectsMutableBasePrxSeq *)s current:(ICECurrent *)current; +-(TestObjectsObjectDict *) getObjectDict:(TestObjectsMutableObjectDict *)d current:(ICECurrent *)current; +-(TestObjectsObjectPrxDict *) getObjectPrxDict:(TestObjectsMutableObjectPrxDict *)d current:(ICECurrent *)current; +-(TestObjectsBaseDict *) getBaseDict:(TestObjectsMutableBaseDict *)d current:(ICECurrent *)current; +-(TestObjectsBasePrxDict *) getBasePrxDict:(TestObjectsMutableBasePrxDict *)d current:(ICECurrent *)current; +@end + +@interface UnexpectedObjectExceptionTestI : ICEBlobject<ICEBlobject> +@end diff --git a/objective-c/test/Ice/objects/TestI.m b/objective-c/test/Ice/objects/TestI.m new file mode 100644 index 00000000000..3b3b10a69d9 --- /dev/null +++ b/objective-c/test/Ice/objects/TestI.m @@ -0,0 +1,308 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <objects/TestI.h> + +@implementation TestObjectsBI +-(BOOL) postUnmarshalInvoked:(ICECurrent*)current +{ + return _postUnmarshalInvoked; +} +-(void) ice_preMarshal +{ + preMarshalInvoked = YES; +} +-(void) ice_postUnmarshal +{ + _postUnmarshalInvoked = YES; +} + +@end + +@implementation TestObjectsCI +-(BOOL) postUnmarshalInvoked:(ICECurrent*)current +{ + return _postUnmarshalInvoked; +} +-(void) ice_preMarshal +{ + preMarshalInvoked = YES; +} +-(void) ice_postUnmarshal +{ + _postUnmarshalInvoked = YES; +} + +@end + +@implementation TestObjectsDI +-(BOOL) postUnmarshalInvoked:(ICECurrent*)current +{ + return _postUnmarshalInvoked; +} +-(void) ice_preMarshal +{ + preMarshalInvoked = YES; +} +-(void) ice_postUnmarshal +{ + _postUnmarshalInvoked = YES; +} +@end + +@implementation TestObjectsEI +-(id) init +{ + return [super init:1 s:@"hello"]; +} +-(BOOL) checkValues:(ICECurrent*)current +{ + return i == 1 && [s isEqualToString:@"hello"]; +} +@end + +@implementation TestObjectsFI +-(id) init:(TestObjectsE*)e1_ e2:(TestObjectsE*)e2_ +{ + self = [super init:e1_ e2:e2_]; + if(!self) + { + return nil; + } + return self; +} +-(BOOL) checkValues:(ICECurrent*)current +{ + return e1 && e1 == e2; +} +@end + +@implementation TestObjectsHI +@end + +/*@implementation TestObjectsII +-(void) dealloc +{ + printf("Deallocating Object"); +} +@end*/ + +@implementation TestObjectsJI +@end + +@implementation TestObjectsInitialI + +-(id) init +{ + self = [super init]; + if(!self) + { + return nil; + } + + _b1 = [[TestObjectsBI alloc] init]; + _b2 = [[TestObjectsBI alloc] init]; + _c = [[TestObjectsCI alloc] init]; + _d = [[TestObjectsDI alloc] init]; + _e = [[TestObjectsEI alloc] init]; + _f = [[TestObjectsFI alloc] init:_e e2:_e]; + + _b1.theA = _b2; // Cyclic reference to another B + _b1.theB = _b1; // Self reference. + _b1.theC = nil; // Null reference. + + _b2.theA = _b2; // Self reference, using base. + _b2.theB = _b1; // Cyclic reference to another B + _b2.theC = _c; // Cyclic reference to a C. + + _c.theB = _b2; // Cyclic reference to a B. + + _d.theA = _b1; // Reference to a B. + _d.theB = _b2; // Reference to a B. + _d.theC = nil; // Reference to a C. + return self; +} + +#if defined(__clang__) && !__has_feature(objc_arc) +-(void) dealloc +{ + [_b1 release]; + [_b2 release]; + [_c release]; + [_d release]; + [_e release]; + [_f release]; + [super dealloc]; +} +#endif + +-(void) shutdown:(ICECurrent*)current +{ + _b1.theA = nil; // Break cyclic reference. + _b1.theB = nil; // Break cyclic reference. + + _b2.theA = nil; // Break cyclic reference. + _b2.theB = nil; // Break cyclic reference. + _b2.theC = nil; // Break cyclic reference. + + _c.theB = nil; // Break cyclic reference. + + _d.theA = nil; // Break cyclic reference. + _d.theB = nil; // Break cyclic reference. + _d.theC = nil; // Break cyclic reference. + [[current.adapter getCommunicator] shutdown]; +} + +-(TestObjectsB*) getB1:(ICECurrent*)current +{ + _b1.preMarshalInvoked = NO; + _b2.preMarshalInvoked = NO; + _c.preMarshalInvoked = NO; + return _b1; +} + +-(TestObjectsB*) getB2:(ICECurrent*)current +{ + _b1.preMarshalInvoked = NO; + _b2.preMarshalInvoked = NO; + _c.preMarshalInvoked = NO; + return _b2; +} + + +-(TestObjectsC*) getC:(ICECurrent*)current +{ + _b1.preMarshalInvoked = NO; + _b2.preMarshalInvoked = NO; + _c.preMarshalInvoked = NO; + return _c; +} + + +-(TestObjectsD*) getD:(ICECurrent*)current +{ + _b1.preMarshalInvoked = NO; + _b2.preMarshalInvoked = NO; + _c.preMarshalInvoked = NO; + _d.preMarshalInvoked = NO; + return _d; +} + + +-(TestObjectsE*) getE:(ICECurrent*)current +{ + return _e; +} + + +-(TestObjectsF*) getF:(ICECurrent*)current +{ + return _f; +} + + +-(void) getAll:(TestObjectsB **)b1 b2:(TestObjectsB **)b2 theC:(TestObjectsC **)theC theD:(TestObjectsD **)theD current:(ICECurrent *)current; +{ + _b1.preMarshalInvoked = NO; + _b2.preMarshalInvoked = NO; + _c.preMarshalInvoked = NO; + _d.preMarshalInvoked = NO; + *b1 = _b1; + *b2 = _b2; + *theC = _c; + *theD = _d; +} + +-(TestObjectsI*) getI:(ICECurrent*)current +{ + return [TestObjectsI i]; +} + +-(TestObjectsI*) getJ:(ICECurrent*)current +{ + return (TestObjectsI*)[TestObjectsJ j]; +} + +-(TestObjectsI*) getH:(ICECurrent*)current +{ + return (TestObjectsI*)[TestObjectsH h]; +} + +-(TestObjectsBaseSeq*) opBaseSeq:(TestObjectsMutableBaseSeq*)inSeq outSeq:(TestObjectsBaseSeq**)outSeq + current:(ICECurrent*)current +{ + *outSeq = inSeq; + return inSeq; +} + +-(TestObjectsCompact*) getCompact:(ICECurrent*)current +{ + return (TestObjectsCompact*)[TestObjectsCompactExt compactExt]; +} + +-(void) setI:(TestObjectsI*)i current:(ICECurrent*)current +{ +} + +-(TestObjectsObjectSeq *) getObjectSeq:(TestObjectsMutableObjectSeq *)s current:(ICECurrent*)current +{ + return s; +} + +-(TestObjectsObjectPrxSeq *) getObjectPrxSeq:(TestObjectsMutableObjectPrxSeq *)s current:(ICECurrent*)current +{ + return s; +} + +-(TestObjectsBaseSeq *) getBaseSeq:(TestObjectsMutableBaseSeq *)s current:(ICECurrent*)current +{ + return s; +} + +-(TestObjectsBasePrxSeq *) getBasePrxSeq:(TestObjectsMutableBasePrxSeq *)s current:(ICECurrent*)current +{ + return s; +} + +-(TestObjectsObjectDict *) getObjectDict:(TestObjectsMutableObjectDict *)d current:(ICECurrent*)current +{ + return d; +} + +-(TestObjectsObjectPrxDict *) getObjectPrxDict:(TestObjectsMutableObjectPrxDict *)d current:(ICECurrent*)current +{ + return d; +} + +-(TestObjectsBaseDict *) getBaseDict:(TestObjectsMutableBaseDict *)d current:(ICECurrent*)current +{ + return d; +} + +-(TestObjectsBasePrxDict *) getBasePrxDict:(TestObjectsMutableBasePrxDict *)d current:(ICECurrent*)current +{ + return d; +} +@end + +@implementation UnexpectedObjectExceptionTestI +-(BOOL)ice_invoke:(NSData*)inEncaps outEncaps:(NSMutableData**)outEncaps current:(ICECurrent*)current +{ + id<ICECommunicator> communicator = [current.adapter getCommunicator]; + id<ICEOutputStream> o = [ICEUtil createOutputStream:communicator]; + [o startEncapsulation]; + TestObjectsAlsoEmpty* ae = [TestObjectsAlsoEmpty alsoEmpty]; + [o writeObject:ae]; + [o writePendingObjects]; + [o endEncapsulation]; + *outEncaps = [o finished]; + return YES; +} +@end diff --git a/objective-c/test/Ice/objects/run.py b/objective-c/test/Ice/objects/run.py new file mode 100755 index 00000000000..74e15b483a3 --- /dev/null +++ b/objective-c/test/Ice/objects/run.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python +# ********************************************************************** +# +# Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +# +# This copy of Ice is licensed to you under the terms described in the +# ICE_LICENSE file included in this distribution. +# +# ********************************************************************** + +import os, sys + +path = [ ".", "..", "../..", "../../..", "../../../..", "../../../../.." ] +head = os.path.dirname(sys.argv[0]) +if len(head) > 0: + path = [os.path.join(head, p) for p in path] +path = [os.path.abspath(p) for p in path if os.path.exists(os.path.join(p, "scripts", "TestUtil.py")) ] +if len(path) == 0: + raise RuntimeError("can't find toplevel directory!") +sys.path.append(os.path.join(path[0], "scripts")) +import TestUtil + +print("Running test with compact (default) format.") +TestUtil.clientServerTest() + +print("Running test with sliced format.") +TestUtil.clientServerTest(additionalClientOptions="--Ice.Default.SlicedFormat", + additionalServerOptions="--Ice.Default.SlicedFormat") + +print("Running test with 1.0 encoding.") +TestUtil.clientServerTest(additionalClientOptions="--Ice.Default.EncodingVersion=1.0", + additionalServerOptions="--Ice.Default.EncodingVersion=1.0") + +print("tests with collocated server.") +TestUtil.collocatedTest() diff --git a/objective-c/test/Ice/objects/test.log b/objective-c/test/Ice/objects/test.log new file mode 100644 index 00000000000..3150beca6c7 --- /dev/null +++ b/objective-c/test/Ice/objects/test.log @@ -0,0 +1,1399 @@ +testing stringToProxy... ok +testing checked cast... ok +testing constructor, copy constructor, and assignment operator... ok +getting B1... starting server... ok +starting client... ok +2008-09-05 18:27:29.095 server[74756:2403] write Test::B +2008-09-05 18:27:29.098 client[74758:10b] read Test::B +2008-09-05 18:27:29.100 client[74758:10b] read Test::A +2008-09-05 18:27:29.101 client[74758:10b] readPendingObject +ok +getting B2... 2008-09-05 18:27:29.096 server[74756:2403] write Test::A +2008-09-05 18:27:29.102 server[74756:2203] write Test::B +2008-09-05 18:27:29.102 server[74756:2203] write Test::A +2008-09-05 18:27:29.103 server[74756:2203] write Test::B +2008-09-05 18:27:29.103 server[74756:2203] write Test::A +2008-09-05 18:27:29.104 server[74756:2203] write Test::B +2008-09-05 18:27:29.104 server[74756:2203] write Test::A +2008-09-05 18:27:29.105 server[74756:2203] write Test::B +2008-09-05 18:27:29.105 server[74756:2203] write Test::A +2008-09-05 18:27:29.105 server[74756:2203] write Test::B +2008-09-05 18:27:29.106 server[74756:2203] write Test::A +2008-09-05 18:27:29.106 server[74756:2203] write Test::B +2008-09-05 18:27:29.106 server[74756:2203] write Test::A +2008-09-05 18:27:29.107 server[74756:2203] write Test::B +2008-09-05 18:27:29.107 server[74756:2203] write Test::A +2008-09-05 18:27:29.108 server[74756:2203] write Test::B +2008-09-05 18:27:29.108 server[74756:2203] write Test::A +2008-09-05 18:27:29.108 server[74756:2203] write Test::B +2008-09-05 18:27:29.109 server[74756:2203] write Test::A +2008-09-05 18:27:29.109 server[74756:2203] write Test::B +2008-09-05 18:27:29.109 server[74756:2203] write Test::A +2008-09-05 18:27:29.110 server[74756:2203] write Test::B +2008-09-05 18:27:29.110 server[74756:2203] write Test::A +2008-09-05 18:27:29.110 server[74756:2203] write Test::B +2008-09-05 18:27:29.111 server[74756:2203] write Test::A +2008-09-05 18:27:29.111 server[74756:2203] write Test::B +2008-09-05 18:27:29.111 server[74756:2203] write Test::A +2008-09-05 18:27:29.112 server[74756:2203] write Test::B +2008-09-05 18:27:29.112 server[74756:2203] write Test::A +2008-09-05 18:27:29.113 server[74756:2203] write Test::B +2008-09-05 18:27:29.113 server[74756:2203] write Test::A +2008-09-05 18:27:29.113 server[74756:2203] write Test::B +2008-09-05 18:27:29.114 server[74756:2203] write Test::A +2008-09-05 18:27:29.114 server[74756:2203] write Test::B +2008-09-05 18:27:29.114 server[74756:2203] write Test::A +2008-09-05 18:27:29.115 server[74756:2203] write Test::B +2008-09-05 18:27:29.115 server[74756:2203] write Test::A +2008-09-05 18:27:29.115 server[74756:2203] write Test::B +2008-09-05 18:27:29.116 server[74756:2203] write Test::A +2008-09-05 18:27:29.116 server[74756:2203] write Test::B +2008-09-05 18:27:29.117 server[74756:2203] write Test::A +2008-09-05 18:27:29.117 server[74756:2203] write Test::B +2008-09-05 18:27:29.117 server[74756:2203] write Test::A +2008-09-05 18:27:29.118 server[74756:2203] write Test::B +2008-09-05 18:27:29.118 server[74756:2203] write Test::A +2008-09-05 18:27:29.118 server[74756:2203] write Test::B +2008-09-05 18:27:29.119 server[74756:2203] write Test::A +2008-09-05 18:27:29.119 server[74756:2203] write Test::B +2008-09-05 18:27:29.119 server[74756:2203] write Test::A +2008-09-05 18:27:29.120 server[74756:2203] write Test::B +2008-09-05 18:27:29.120 server[74756:2203] write Test::A +2008-09-05 18:27:29.120 server[74756:2203] write Test::B +2008-09-05 18:27:29.121 server[74756:2203] write Test::A +2008-09-05 18:27:29.121 server[74756:2203] write Test::B +2008-09-05 18:27:29.122 server[74756:2203] write Test::A +2008-09-05 18:27:29.122 server[74756:2203] write Test::B +2008-09-05 18:27:29.122 server[74756:2203] write Test::A +2008-09-05 18:27:29.123 server[74756:2203] write Test::B +2008-09-05 18:27:29.123 server[74756:2203] write Test::A +2008-09-05 18:27:29.123 server[74756:2203] write Test::B +2008-09-05 18:27:29.124 server[74756:2203] write Test::A +2008-09-05 18:27:29.124 server[74756:2203] write Test::B +2008-09-05 18:27:29.124 server[74756:2203] write Test::A +2008-09-05 18:27:29.125 server[74756:2203] write Test::B +2008-09-05 18:27:29.125 server[74756:2203] write Test::A +2008-09-05 18:27:29.126 server[74756:2203] write Test::B +2008-09-05 18:27:29.126 server[74756:2203] write Test::A +2008-09-05 18:27:29.126 server[74756:2203] write Test::B +2008-09-05 18:27:29.127 server[74756:2203] write Test::A +2008-09-05 18:27:29.127 server[74756:2203] write Test::B +2008-09-05 18:27:29.127 server[74756:2203] write Test::A +2008-09-05 18:27:29.128 server[74756:2203] write Test::B +2008-09-05 18:27:29.128 server[74756:2203] write Test::A +2008-09-05 18:27:29.128 server[74756:2203] write Test::B +2008-09-05 18:27:29.129 server[74756:2203] write Test::A +2008-09-05 18:27:29.129 server[74756:2203] write Test::B +2008-09-05 18:27:29.130 server[74756:2203] write Test::A +2008-09-05 18:27:29.130 server[74756:2203] write Test::B +2008-09-05 18:27:29.130 server[74756:2203] write Test::A +2008-09-05 18:27:29.131 server[74756:2203] write Test::B +2008-09-05 18:27:29.131 server[74756:2203] write Test::A +2008-09-05 18:27:29.131 server[74756:2203] write Test::B +2008-09-05 18:27:29.132 server[74756:2203] write Test::A +2008-09-05 18:27:29.132 server[74756:2203] write Test::B +2008-09-05 18:27:29.133 server[74756:2203] write Test::A +2008-09-05 18:27:29.133 server[74756:2203] write Test::B +2008-09-05 18:27:29.133 server[74756:2203] write Test::A +2008-09-05 18:27:29.134 server[74756:2203] write Test::B +2008-09-05 18:27:29.134 server[74756:2203] write Test::A +2008-09-05 18:27:29.134 server[74756:2203] write Test::B +2008-09-05 18:27:29.135 server[74756:2203] write Test::A +2008-09-05 18:27:29.135 server[74756:2203] write Test::B +2008-09-05 18:27:29.135 server[74756:2203] write Test::A +2008-09-05 18:27:29.136 server[74756:2203] write Test::B +2008-09-05 18:27:29.136 server[74756:2203] write Test::A +2008-09-05 18:27:29.137 server[74756:2203] write Test::B +2008-09-05 18:27:29.137 server[74756:2203] write Test::A +2008-09-05 18:27:29.137 server[74756:2203] write Test::B +2008-09-05 18:27:29.138 server[74756:2203] write Test::A +2008-09-05 18:27:29.138 server[74756:2203] write Test::B +2008-09-05 18:27:29.138 server[74756:2203] write Test::A +2008-09-05 18:27:29.139 server[74756:2203] write Test::B +2008-09-05 18:27:29.139 server[74756:2203] write Test::A +2008-09-05 18:27:29.140 server[74756:2203] write Test::B +2008-09-05 18:27:29.140 server[74756:2203] write Test::A +2008-09-05 18:27:29.140 server[74756:2203] write Test::B +2008-09-05 18:27:29.141 server[74756:2203] write Test::A +2008-09-05 18:27:29.141 server[74756:2203] write Test::B +2008-09-05 18:27:29.142 server[74756:2203] write Test::A +2008-09-05 18:27:29.142 server[74756:2203] write Test::B +2008-09-05 18:27:29.142 server[74756:2203] write Test::A +2008-09-05 18:27:29.143 server[74756:2203] write Test::B +2008-09-05 18:27:29.143 server[74756:2203] write Test::A +2008-09-05 18:27:29.144 server[74756:2203] write Test::B +2008-09-05 18:27:29.144 server[74756:2203] write Test::A +2008-09-05 18:27:29.144 server[74756:2203] write Test::B +2008-09-05 18:27:29.145 server[74756:2203] write Test::A +2008-09-05 18:27:29.145 server[74756:2203] write Test::B +2008-09-05 18:27:29.145 server[74756:2203] write Test::A +2008-09-05 18:27:29.146 server[74756:2203] write Test::B +2008-09-05 18:27:29.146 server[74756:2203] write Test::A +2008-09-05 18:27:29.147 server[74756:2203] write Test::B +2008-09-05 18:27:29.147 server[74756:2203] write Test::A +2008-09-05 18:27:29.147 server[74756:2203] write Test::B +2008-09-05 18:27:29.148 server[74756:2203] write Test::A +2008-09-05 18:27:29.148 server[74756:2203] write Test::B +2008-09-05 18:27:29.148 server[74756:2203] write Test::A +2008-09-05 18:27:29.149 server[74756:2203] write Test::B +2008-09-05 18:27:29.149 server[74756:2203] write Test::A +2008-09-05 18:27:29.150 server[74756:2203] write Test::B +2008-09-05 18:27:29.150 server[74756:2203] write Test::A +2008-09-05 18:27:29.150 server[74756:2203] write Test::B +2008-09-05 18:27:29.151 server[74756:2203] write Test::A +2008-09-05 18:27:29.151 server[74756:2203] write Test::B +2008-09-05 18:27:29.151 server[74756:2203] write Test::A +2008-09-05 18:27:29.152 server[74756:2203] write Test::B +2008-09-05 18:27:29.152 server[74756:2203] write Test::A +2008-09-05 18:27:29.152 server[74756:2203] write Test::B +2008-09-05 18:27:29.153 server[74756:2203] write Test::A +2008-09-05 18:27:29.153 server[74756:2203] write Test::B +2008-09-05 18:27:29.153 server[74756:2203] write Test::A +2008-09-05 18:27:29.154 server[74756:2203] write Test::B +2008-09-05 18:27:29.154 server[74756:2203] write Test::A +2008-09-05 18:27:29.155 server[74756:2203] write Test::B +2008-09-05 18:27:29.155 server[74756:2203] write Test::A +2008-09-05 18:27:29.155 server[74756:2203] write Test::B +2008-09-05 18:27:29.156 server[74756:2203] write Test::A +2008-09-05 18:27:29.156 server[74756:2203] write Test::B +2008-09-05 18:27:29.156 server[74756:2203] write Test::A +2008-09-05 18:27:29.157 server[74756:2203] write Test::B +2008-09-05 18:27:29.157 server[74756:2203] write Test::A +2008-09-05 18:27:29.157 server[74756:2203] write Test::B +2008-09-05 18:27:29.158 server[74756:2203] write Test::A +2008-09-05 18:27:29.158 server[74756:2203] write Test::B +2008-09-05 18:27:29.159 server[74756:2203] write Test::A +2008-09-05 18:27:29.159 server[74756:2203] write Test::B +2008-09-05 18:27:29.159 server[74756:2203] write Test::A +2008-09-05 18:27:29.160 server[74756:2203] write Test::B +2008-09-05 18:27:29.160 server[74756:2203] write Test::A +2008-09-05 18:27:29.160 server[74756:2203] write Test::B +2008-09-05 18:27:29.161 server[74756:2203] write Test::A +2008-09-05 18:27:29.161 server[74756:2203] write Test::B +2008-09-05 18:27:29.162 server[74756:2203] write Test::A +2008-09-05 18:27:29.162 server[74756:2203] write Test::B +2008-09-05 18:27:29.162 server[74756:2203] write Test::A +2008-09-05 18:27:29.163 server[74756:2203] write Test::B +2008-09-05 18:27:29.163 server[74756:2203] write Test::A +2008-09-05 18:27:29.164 server[74756:2203] write Test::B +2008-09-05 18:27:29.165 server[74756:2203] write Test::A +2008-09-05 18:27:29.165 server[74756:2203] write Test::B +2008-09-05 18:27:29.166 server[74756:2203] write Test::A +2008-09-05 18:27:29.166 server[74756:2203] write Test::B +2008-09-05 18:27:29.166 server[74756:2203] write Test::A +2008-09-05 18:27:29.167 server[74756:2203] write Test::B +2008-09-05 18:27:29.167 server[74756:2203] write Test::A +2008-09-05 18:27:29.168 server[74756:2203] write Test::B +2008-09-05 18:27:29.170 server[74756:2203] write Test::A +2008-09-05 18:27:29.170 server[74756:2203] write Test::B +2008-09-05 18:27:29.170 server[74756:2203] write Test::A +2008-09-05 18:27:29.171 server[74756:2203] write Test::B +2008-09-05 18:27:29.171 server[74756:2203] write Test::A +2008-09-05 18:27:29.171 server[74756:2203] write Test::B +2008-09-05 18:27:29.172 server[74756:2203] write Test::A +2008-09-05 18:27:29.172 server[74756:2203] write Test::B +2008-09-05 18:27:29.173 server[74756:2203] write Test::A +2008-09-05 18:27:29.173 server[74756:2203] write Test::B +2008-09-05 18:27:29.173 server[74756:2203] write Test::A +2008-09-05 18:27:29.174 server[74756:2203] write Test::B +2008-09-05 18:27:29.174 server[74756:2203] write Test::A +2008-09-05 18:27:29.174 server[74756:2203] write Test::B +2008-09-05 18:27:29.175 server[74756:2203] write Test::A +2008-09-05 18:27:29.175 server[74756:2203] write Test::B +2008-09-05 18:27:29.176 server[74756:2203] write Test::A +2008-09-05 18:27:29.176 server[74756:2203] write Test::B +2008-09-05 18:27:29.176 server[74756:2203] write Test::A +2008-09-05 18:27:29.177 server[74756:2203] write Test::B +2008-09-05 18:27:29.177 server[74756:2203] write Test::A +2008-09-05 18:27:29.178 server[74756:2203] write Test::B +2008-09-05 18:27:29.178 server[74756:2203] write Test::A +2008-09-05 18:27:29.178 server[74756:2203] write Test::B +2008-09-05 18:27:29.179 server[74756:2203] write Test::A +2008-09-05 18:27:29.179 server[74756:2203] write Test::B +2008-09-05 18:27:29.179 server[74756:2203] write Test::A +2008-09-05 18:27:29.180 server[74756:2203] write Test::B +2008-09-05 18:27:29.180 server[74756:2203] write Test::A +2008-09-05 18:27:29.181 server[74756:2203] write Test::B +2008-09-05 18:27:29.181 server[74756:2203] write Test::A +2008-09-05 18:27:29.181 server[74756:2203] write Test::B +2008-09-05 18:27:29.182 server[74756:2203] write Test::A +2008-09-05 18:27:29.182 server[74756:2203] write Test::B +2008-09-05 18:27:29.182 server[74756:2203] write Test::A +2008-09-05 18:27:29.183 server[74756:2203] write Test::B +2008-09-05 18:27:29.183 server[74756:2203] write Test::A +2008-09-05 18:27:29.184 server[74756:2203] write Test::B +2008-09-05 18:27:29.184 server[74756:2203] write Test::A +2008-09-05 18:27:29.184 server[74756:2203] write Test::B +2008-09-05 18:27:29.185 server[74756:2203] write Test::A +2008-09-05 18:27:29.185 server[74756:2203] write Test::B +2008-09-05 18:27:29.186 server[74756:2203] write Test::A +2008-09-05 18:27:29.186 server[74756:2203] write Test::B +2008-09-05 18:27:29.186 server[74756:2203] write Test::A +2008-09-05 18:27:29.187 server[74756:2203] write Test::B +2008-09-05 18:27:29.187 server[74756:2203] write Test::A +2008-09-05 18:27:29.187 server[74756:2203] write Test::B +2008-09-05 18:27:29.188 server[74756:2203] write Test::A +2008-09-05 18:27:29.188 server[74756:2203] write Test::B +2008-09-05 18:27:29.189 server[74756:2203] write Test::A +2008-09-05 18:27:29.189 server[74756:2203] write Test::B +2008-09-05 18:27:29.189 server[74756:2203] write Test::A +2008-09-05 18:27:29.190 server[74756:2203] write Test::B +2008-09-05 18:27:29.190 server[74756:2203] write Test::A +2008-09-05 18:27:29.191 server[74756:2203] write Test::B +2008-09-05 18:27:29.191 server[74756:2203] write Test::A +2008-09-05 18:27:29.191 server[74756:2203] write Test::B +2008-09-05 18:27:29.192 server[74756:2203] write Test::A +2008-09-05 18:27:29.192 server[74756:2203] write Test::B +2008-09-05 18:27:29.192 server[74756:2203] write Test::A +2008-09-05 18:27:29.193 server[74756:2203] write Test::B +2008-09-05 18:27:29.193 server[74756:2203] write Test::A +2008-09-05 18:27:29.194 server[74756:2203] write Test::B +2008-09-05 18:27:29.194 server[74756:2203] write Test::A +2008-09-05 18:27:29.194 server[74756:2203] write Test::B +2008-09-05 18:27:29.195 server[74756:2203] write Test::A +2008-09-05 18:27:29.196 server[74756:2203] write Test::B +2008-09-05 18:27:29.197 server[74756:2203] write Test::A +2008-09-05 18:27:29.198 server[74756:2203] write Test::B +2008-09-05 18:27:29.198 server[74756:2203] write Test::A +2008-09-05 18:27:29.199 server[74756:2203] write Test::B +2008-09-05 18:27:29.199 server[74756:2203] write Test::A +2008-09-05 18:27:29.199 server[74756:2203] write Test::B +2008-09-05 18:27:29.200 server[74756:2203] write Test::A +2008-09-05 18:27:29.200 server[74756:2203] write Test::B +2008-09-05 18:27:29.200 server[74756:2203] write Test::A +2008-09-05 18:27:29.201 server[74756:2203] write Test::B +2008-09-05 18:27:29.201 server[74756:2203] write Test::A +2008-09-05 18:27:29.202 server[74756:2203] write Test::B +2008-09-05 18:27:29.202 server[74756:2203] write Test::A +2008-09-05 18:27:29.202 server[74756:2203] write Test::B +2008-09-05 18:27:29.203 server[74756:2203] write Test::A +2008-09-05 18:27:29.203 server[74756:2203] write Test::B +2008-09-05 18:27:29.204 server[74756:2203] write Test::A +2008-09-05 18:27:29.204 server[74756:2203] write Test::B +2008-09-05 18:27:29.204 server[74756:2203] write Test::A +2008-09-05 18:27:29.205 server[74756:2203] write Test::B +2008-09-05 18:27:29.205 server[74756:2203] write Test::A +2008-09-05 18:27:29.205 server[74756:2203] write Test::B +2008-09-05 18:27:29.206 server[74756:2203] write Test::A +2008-09-05 18:27:29.206 server[74756:2203] write Test::B +2008-09-05 18:27:29.207 server[74756:2203] write Test::A +2008-09-05 18:27:29.207 server[74756:2203] write Test::B +2008-09-05 18:27:29.207 server[74756:2203] write Test::A +2008-09-05 18:27:29.208 server[74756:2203] write Test::B +2008-09-05 18:27:29.208 server[74756:2203] write Test::A +2008-09-05 18:27:29.209 server[74756:2203] write Test::B +2008-09-05 18:27:29.209 server[74756:2203] write Test::A +2008-09-05 18:27:29.209 server[74756:2203] write Test::B +2008-09-05 18:27:29.210 server[74756:2203] write Test::A +2008-09-05 18:27:29.210 server[74756:2203] write Test::B +2008-09-05 18:27:29.211 server[74756:2203] write Test::A +2008-09-05 18:27:29.211 server[74756:2203] write Test::B +2008-09-05 18:27:29.212 server[74756:2203] write Test::A +2008-09-05 18:27:29.213 server[74756:2203] write Test::B +2008-09-05 18:27:29.213 server[74756:2203] write Test::A +2008-09-05 18:27:29.214 server[74756:2203] write Test::B +2008-09-05 18:27:29.214 server[74756:2203] write Test::A +2008-09-05 18:27:29.215 server[74756:2203] write Test::B +2008-09-05 18:27:29.215 server[74756:2203] write Test::A +2008-09-05 18:27:29.216 server[74756:2203] write Test::B +2008-09-05 18:27:29.216 server[74756:2203] write Test::A +2008-09-05 18:27:29.216 server[74756:2203] write Test::B +2008-09-05 18:27:29.217 server[74756:2203] write Test::A +2008-09-05 18:27:29.217 server[74756:2203] write Test::B +2008-09-05 18:27:29.217 server[74756:2203] write Test::A +2008-09-05 18:27:29.218 server[74756:2203] write Test::B +2008-09-05 18:27:29.218 server[74756:2203] write Test::A +2008-09-05 18:27:29.219 server[74756:2203] write Test::B +2008-09-05 18:27:29.219 server[74756:2203] write Test::A +2008-09-05 18:27:29.219 server[74756:2203] write Test::B +2008-09-05 18:27:29.220 server[74756:2203] write Test::A +2008-09-05 18:27:29.220 server[74756:2203] write Test::B +2008-09-05 18:27:29.221 server[74756:2203] write Test::A +2008-09-05 18:27:29.221 server[74756:2203] write Test::B +2008-09-05 18:27:29.221 server[74756:2203] write Test::A +2008-09-05 18:27:29.222 server[74756:2203] write Test::B +2008-09-05 18:27:29.222 server[74756:2203] write Test::A +2008-09-05 18:27:29.222 server[74756:2203] write Test::B +2008-09-05 18:27:29.223 server[74756:2203] write Test::A +2008-09-05 18:27:29.223 server[74756:2203] write Test::B +2008-09-05 18:27:29.224 server[74756:2203] write Test::A +2008-09-05 18:27:29.224 server[74756:2203] write Test::B +2008-09-05 18:27:29.224 server[74756:2203] write Test::A +2008-09-05 18:27:29.225 server[74756:2203] write Test::B +2008-09-05 18:27:29.225 server[74756:2203] write Test::A +2008-09-05 18:27:29.226 server[74756:2203] write Test::B +2008-09-05 18:27:29.226 server[74756:2203] write Test::A +2008-09-05 18:27:29.226 server[74756:2203] write Test::B +2008-09-05 18:27:29.227 server[74756:2203] write Test::A +2008-09-05 18:27:29.227 server[74756:2203] write Test::B +2008-09-05 18:27:29.228 server[74756:2203] write Test::A +2008-09-05 18:27:29.228 server[74756:2203] write Test::B +2008-09-05 18:27:29.228 server[74756:2203] write Test::A +2008-09-05 18:27:29.229 server[74756:2203] write Test::B +2008-09-05 18:27:29.229 server[74756:2203] write Test::A +2008-09-05 18:27:29.230 server[74756:2203] write Test::B +2008-09-05 18:27:29.230 server[74756:2203] write Test::A +2008-09-05 18:27:29.230 server[74756:2203] write Test::B +2008-09-05 18:27:29.231 server[74756:2203] write Test::A +2008-09-05 18:27:29.233 server[74756:2203] write Test::B +2008-09-05 18:27:29.233 server[74756:2203] write Test::A +2008-09-05 18:27:29.233 server[74756:2203] write Test::B +2008-09-05 18:27:29.234 server[74756:2203] write Test::A +2008-09-05 18:27:29.234 server[74756:2203] write Test::B +2008-09-05 18:27:29.235 server[74756:2203] write Test::A +2008-09-05 18:27:29.235 server[74756:2203] write Test::B +2008-09-05 18:27:29.235 server[74756:2203] write Test::A +2008-09-05 18:27:29.236 server[74756:2203] write Test::B +2008-09-05 18:27:29.236 server[74756:2203] write Test::A +2008-09-05 18:27:29.236 server[74756:2203] write Test::B +2008-09-05 18:27:29.237 server[74756:2203] write Test::A +2008-09-05 18:27:29.237 server[74756:2203] write Test::B +2008-09-05 18:27:29.238 server[74756:2203] write Test::A +2008-09-05 18:27:29.238 server[74756:2203] write Test::B +2008-09-05 18:27:29.238 server[74756:2203] write Test::A +2008-09-05 18:27:29.239 server[74756:2203] write Test::B +2008-09-05 18:27:29.239 server[74756:2203] write Test::A +2008-09-05 18:27:29.239 server[74756:2203] write Test::B +2008-09-05 18:27:29.240 server[74756:2203] write Test::A +2008-09-05 18:27:29.240 server[74756:2203] write Test::B +2008-09-05 18:27:29.240 server[74756:2203] write Test::A +2008-09-05 18:27:29.241 server[74756:2203] write Test::B +2008-09-05 18:27:29.241 server[74756:2203] write Test::A +2008-09-05 18:27:29.241 server[74756:2203] write Test::B +2008-09-05 18:27:29.242 server[74756:2203] write Test::A +2008-09-05 18:27:29.242 server[74756:2203] write Test::B +2008-09-05 18:27:29.242 server[74756:2203] write Test::A +2008-09-05 18:27:29.243 server[74756:2203] write Test::B +2008-09-05 18:27:29.243 server[74756:2203] write Test::A +2008-09-05 18:27:29.244 server[74756:2203] write Test::B +2008-09-05 18:27:29.244 server[74756:2203] write Test::A +2008-09-05 18:27:29.244 server[74756:2203] write Test::B +2008-09-05 18:27:29.245 server[74756:2203] write Test::A +2008-09-05 18:27:29.245 server[74756:2203] write Test::B +2008-09-05 18:27:29.246 server[74756:2203] write Test::A +2008-09-05 18:27:29.246 server[74756:2203] write Test::B +2008-09-05 18:27:29.246 server[74756:2203] write Test::A +2008-09-05 18:27:29.247 server[74756:2203] write Test::B +2008-09-05 18:27:29.247 server[74756:2203] write Test::A +2008-09-05 18:27:29.247 server[74756:2203] write Test::B +2008-09-05 18:27:29.248 server[74756:2203] write Test::A +2008-09-05 18:27:29.248 server[74756:2203] write Test::B +2008-09-05 18:27:29.249 server[74756:2203] write Test::A +2008-09-05 18:27:29.249 server[74756:2203] write Test::B +2008-09-05 18:27:29.249 server[74756:2203] write Test::A +2008-09-05 18:27:29.250 server[74756:2203] write Test::B +2008-09-05 18:27:29.250 server[74756:2203] write Test::A +2008-09-05 18:27:29.250 server[74756:2203] write Test::B +2008-09-05 18:27:29.251 server[74756:2203] write Test::A +2008-09-05 18:27:29.251 server[74756:2203] write Test::B +2008-09-05 18:27:29.252 server[74756:2203] write Test::A +2008-09-05 18:27:29.252 server[74756:2203] write Test::B +2008-09-05 18:27:29.252 server[74756:2203] write Test::A +2008-09-05 18:27:29.253 server[74756:2203] write Test::B +2008-09-05 18:27:29.253 server[74756:2203] write Test::A +2008-09-05 18:27:29.254 server[74756:2203] write Test::B +2008-09-05 18:27:29.255 server[74756:2203] write Test::A +2008-09-05 18:27:29.255 server[74756:2203] write Test::B +2008-09-05 18:27:29.255 server[74756:2203] write Test::A +2008-09-05 18:27:29.256 server[74756:2203] write Test::B +2008-09-05 18:27:29.256 server[74756:2203] write Test::A +2008-09-05 18:27:29.257 server[74756:2203] write Test::B +2008-09-05 18:27:29.257 server[74756:2203] write Test::A +2008-09-05 18:27:29.257 server[74756:2203] write Test::B +2008-09-05 18:27:29.258 server[74756:2203] write Test::A +2008-09-05 18:27:29.258 server[74756:2203] write Test::B +2008-09-05 18:27:29.259 server[74756:2203] write Test::A +2008-09-05 18:27:29.259 server[74756:2203] write Test::B +2008-09-05 18:27:29.259 server[74756:2203] write Test::A +2008-09-05 18:27:29.260 server[74756:2203] write Test::B +2008-09-05 18:27:29.260 server[74756:2203] write Test::A +2008-09-05 18:27:29.261 server[74756:2203] write Test::B +2008-09-05 18:27:29.261 server[74756:2203] write Test::A +2008-09-05 18:27:29.261 server[74756:2203] write Test::B +2008-09-05 18:27:29.262 server[74756:2203] write Test::A +2008-09-05 18:27:29.262 server[74756:2203] write Test::B +2008-09-05 18:27:29.263 server[74756:2203] write Test::A +2008-09-05 18:27:29.263 server[74756:2203] write Test::B +2008-09-05 18:27:29.264 server[74756:2203] write Test::A +2008-09-05 18:27:29.264 server[74756:2203] write Test::B +2008-09-05 18:27:29.265 server[74756:2203] write Test::A +2008-09-05 18:27:29.265 server[74756:2203] write Test::B +2008-09-05 18:27:29.265 server[74756:2203] write Test::A +2008-09-05 18:27:29.266 server[74756:2203] write Test::B +2008-09-05 18:27:29.266 server[74756:2203] write Test::A +2008-09-05 18:27:29.267 server[74756:2203] write Test::B +2008-09-05 18:27:29.267 server[74756:2203] write Test::A +2008-09-05 18:27:29.268 server[74756:2203] write Test::B +2008-09-05 18:27:29.268 server[74756:2203] write Test::A +2008-09-05 18:27:29.268 server[74756:2203] write Test::B +2008-09-05 18:27:29.269 server[74756:2203] write Test::A +2008-09-05 18:27:29.270 server[74756:2203] write Test::B +2008-09-05 18:27:29.270 server[74756:2203] write Test::A +2008-09-05 18:27:29.271 server[74756:2203] write Test::B +2008-09-05 18:27:29.271 server[74756:2203] write Test::A +2008-09-05 18:27:29.271 server[74756:2203] write Test::B +2008-09-05 18:27:29.272 server[74756:2203] write Test::A +2008-09-05 18:27:29.272 server[74756:2203] write Test::B +2008-09-05 18:27:29.273 server[74756:2203] write Test::A +2008-09-05 18:27:29.273 server[74756:2203] write Test::B +2008-09-05 18:27:29.273 server[74756:2203] write Test::A +2008-09-05 18:27:29.274 server[74756:2203] write Test::B +2008-09-05 18:27:29.274 server[74756:2203] write Test::A +2008-09-05 18:27:29.275 server[74756:2203] write Test::B +2008-09-05 18:27:29.275 server[74756:2203] write Test::A +2008-09-05 18:27:29.275 server[74756:2203] write Test::B +2008-09-05 18:27:29.276 server[74756:2203] write Test::A +2008-09-05 18:27:29.276 server[74756:2203] write Test::B +2008-09-05 18:27:29.277 server[74756:2203] write Test::A +2008-09-05 18:27:29.277 server[74756:2203] write Test::B +2008-09-05 18:27:29.278 server[74756:2203] write Test::A +2008-09-05 18:27:29.278 server[74756:2203] write Test::B +2008-09-05 18:27:29.278 server[74756:2203] write Test::A +2008-09-05 18:27:29.279 server[74756:2203] write Test::B +2008-09-05 18:27:29.279 server[74756:2203] write Test::A +2008-09-05 18:27:29.281 server[74756:2203] write Test::B +2008-09-05 18:27:29.282 server[74756:2203] write Test::A +2008-09-05 18:27:29.283 server[74756:2203] write Test::B +2008-09-05 18:27:29.283 server[74756:2203] write Test::A +2008-09-05 18:27:29.283 server[74756:2203] write Test::B +2008-09-05 18:27:29.284 server[74756:2203] write Test::A +2008-09-05 18:27:29.284 server[74756:2203] write Test::B +2008-09-05 18:27:29.285 server[74756:2203] write Test::A +2008-09-05 18:27:29.285 server[74756:2203] write Test::B +2008-09-05 18:27:29.286 server[74756:2203] write Test::A +2008-09-05 18:27:29.286 server[74756:2203] write Test::B +2008-09-05 18:27:29.286 server[74756:2203] write Test::A +2008-09-05 18:27:29.287 server[74756:2203] write Test::B +2008-09-05 18:27:29.287 server[74756:2203] write Test::A +2008-09-05 18:27:29.288 server[74756:2203] write Test::B +2008-09-05 18:27:29.288 server[74756:2203] write Test::A +2008-09-05 18:27:29.288 server[74756:2203] write Test::B +2008-09-05 18:27:29.289 server[74756:2203] write Test::A +2008-09-05 18:27:29.289 server[74756:2203] write Test::B +2008-09-05 18:27:29.290 server[74756:2203] write Test::A +2008-09-05 18:27:29.291 server[74756:2203] write Test::B +2008-09-05 18:27:29.291 server[74756:2203] write Test::A +2008-09-05 18:27:29.291 server[74756:2203] write Test::B +2008-09-05 18:27:29.292 server[74756:2203] write Test::A +2008-09-05 18:27:29.292 server[74756:2203] write Test::B +2008-09-05 18:27:29.293 server[74756:2203] write Test::A +2008-09-05 18:27:29.293 server[74756:2203] write Test::B +2008-09-05 18:27:29.293 server[74756:2203] write Test::A +2008-09-05 18:27:29.295 server[74756:2203] write Test::B +2008-09-05 18:27:29.295 server[74756:2203] write Test::A +2008-09-05 18:27:29.295 server[74756:2203] write Test::B +2008-09-05 18:27:29.296 server[74756:2203] write Test::A +2008-09-05 18:27:29.299 server[74756:2203] write Test::B +2008-09-05 18:27:29.299 server[74756:2203] write Test::A +2008-09-05 18:27:29.300 server[74756:2203] write Test::B +2008-09-05 18:27:29.300 server[74756:2203] write Test::A +2008-09-05 18:27:29.300 server[74756:2203] write Test::B +2008-09-05 18:27:29.301 server[74756:2203] write Test::A +2008-09-05 18:27:29.301 server[74756:2203] write Test::B +2008-09-05 18:27:29.301 server[74756:2203] write Test::A +2008-09-05 18:27:29.302 server[74756:2203] write Test::B +2008-09-05 18:27:29.302 server[74756:2203] write Test::A +2008-09-05 18:27:29.302 server[74756:2203] write Test::B +2008-09-05 18:27:29.303 server[74756:2203] write Test::A +2008-09-05 18:27:29.303 server[74756:2203] write Test::B +2008-09-05 18:27:29.303 server[74756:2203] write Test::A +2008-09-05 18:27:29.304 server[74756:2203] write Test::B +2008-09-05 18:27:29.304 server[74756:2203] write Test::A +2008-09-05 18:27:29.305 server[74756:2203] write Test::B +2008-09-05 18:27:29.305 server[74756:2203] write Test::A +2008-09-05 18:27:29.305 server[74756:2203] write Test::B +2008-09-05 18:27:29.306 server[74756:2203] write Test::A +2008-09-05 18:27:29.306 server[74756:2203] write Test::B +2008-09-05 18:27:29.306 server[74756:2203] write Test::A +2008-09-05 18:27:29.307 server[74756:2203] write Test::B +2008-09-05 18:27:29.307 server[74756:2203] write Test::A +2008-09-05 18:27:29.307 server[74756:2203] write Test::B +2008-09-05 18:27:29.308 server[74756:2203] write Test::A +2008-09-05 18:27:29.308 server[74756:2203] write Test::B +2008-09-05 18:27:29.308 server[74756:2203] write Test::A +2008-09-05 18:27:29.309 server[74756:2203] write Test::B +2008-09-05 18:27:29.309 server[74756:2203] write Test::A +2008-09-05 18:27:29.309 server[74756:2203] write Test::B +2008-09-05 18:27:29.310 server[74756:2203] write Test::A +2008-09-05 18:27:29.311 server[74756:2203] write Test::B +2008-09-05 18:27:29.311 server[74756:2203] write Test::A +2008-09-05 18:27:29.311 server[74756:2203] write Test::B +2008-09-05 18:27:29.312 server[74756:2203] write Test::A +2008-09-05 18:27:29.312 server[74756:2203] write Test::B +2008-09-05 18:27:29.312 server[74756:2203] write Test::A +2008-09-05 18:27:29.313 server[74756:2203] write Test::B +2008-09-05 18:27:29.313 server[74756:2203] write Test::A +2008-09-05 18:27:29.314 server[74756:2203] write Test::B +2008-09-05 18:27:29.314 server[74756:2203] write Test::A +2008-09-05 18:27:29.314 server[74756:2203] write Test::B +2008-09-05 18:27:29.315 server[74756:2203] write Test::A +2008-09-05 18:27:29.315 server[74756:2203] write Test::B +2008-09-05 18:27:29.315 server[74756:2203] write Test::A +2008-09-05 18:27:29.316 server[74756:2203] write Test::B +2008-09-05 18:27:29.316 server[74756:2203] write Test::A +2008-09-05 18:27:29.316 server[74756:2203] write Test::B +2008-09-05 18:27:29.317 server[74756:2203] write Test::A +2008-09-05 18:27:29.317 server[74756:2203] write Test::B +2008-09-05 18:27:29.317 server[74756:2203] write Test::A +2008-09-05 18:27:29.318 server[74756:2203] write Test::B +2008-09-05 18:27:29.318 server[74756:2203] write Test::A +2008-09-05 18:27:29.318 server[74756:2203] write Test::B +2008-09-05 18:27:29.319 server[74756:2203] write Test::A +2008-09-05 18:27:29.319 server[74756:2203] write Test::B +2008-09-05 18:27:29.320 server[74756:2203] write Test::A +2008-09-05 18:27:29.320 server[74756:2203] write Test::B +2008-09-05 18:27:29.320 server[74756:2203] write Test::A +2008-09-05 18:27:29.321 server[74756:2203] write Test::B +2008-09-05 18:27:29.321 server[74756:2203] write Test::A +2008-09-05 18:27:29.321 server[74756:2203] write Test::B +2008-09-05 18:27:29.322 server[74756:2203] write Test::A +2008-09-05 18:27:29.322 server[74756:2203] write Test::B +2008-09-05 18:27:29.322 server[74756:2203] write Test::A +2008-09-05 18:27:29.323 server[74756:2203] write Test::B +2008-09-05 18:27:29.323 server[74756:2203] write Test::A +2008-09-05 18:27:29.323 server[74756:2203] write Test::B +2008-09-05 18:27:29.324 server[74756:2203] write Test::A +2008-09-05 18:27:29.324 server[74756:2203] write Test::B +2008-09-05 18:27:29.324 server[74756:2203] write Test::A +2008-09-05 18:27:29.325 server[74756:2203] write Test::B +2008-09-05 18:27:29.325 server[74756:2203] write Test::A +2008-09-05 18:27:29.326 server[74756:2203] write Test::B +2008-09-05 18:27:29.326 server[74756:2203] write Test::A +2008-09-05 18:27:29.326 server[74756:2203] write Test::B +2008-09-05 18:27:29.327 server[74756:2203] write Test::A +2008-09-05 18:27:29.327 server[74756:2203] write Test::B +2008-09-05 18:27:29.327 server[74756:2203] write Test::A +2008-09-05 18:27:29.328 server[74756:2203] write Test::B +2008-09-05 18:27:29.328 server[74756:2203] write Test::A +2008-09-05 18:27:29.328 server[74756:2203] write Test::B +2008-09-05 18:27:29.329 server[74756:2203] write Test::A +2008-09-05 18:27:29.329 server[74756:2203] write Test::B +2008-09-05 18:27:29.329 server[74756:2203] write Test::A +2008-09-05 18:27:29.330 server[74756:2203] write Test::B +2008-09-05 18:27:29.330 server[74756:2203] write Test::A +2008-09-05 18:27:29.331 server[74756:2203] write Test::B +2008-09-05 18:27:29.331 server[74756:2203] write Test::A +2008-09-05 18:27:29.331 server[74756:2203] write Test::B +2008-09-05 18:27:29.332 server[74756:2203] write Test::A +2008-09-05 18:27:29.332 server[74756:2203] write Test::B +2008-09-05 18:27:29.332 server[74756:2203] write Test::A +2008-09-05 18:27:29.333 server[74756:2203] write Test::B +2008-09-05 18:27:29.333 server[74756:2203] write Test::A +2008-09-05 18:27:29.333 server[74756:2203] write Test::B +2008-09-05 18:27:29.334 server[74756:2203] write Test::A +2008-09-05 18:27:29.334 server[74756:2203] write Test::B +2008-09-05 18:27:29.334 server[74756:2203] write Test::A +2008-09-05 18:27:29.335 server[74756:2203] write Test::B +2008-09-05 18:27:29.335 server[74756:2203] write Test::A +2008-09-05 18:27:29.336 server[74756:2203] write Test::B +2008-09-05 18:27:29.336 server[74756:2203] write Test::A +2008-09-05 18:27:29.336 server[74756:2203] write Test::B +2008-09-05 18:27:29.338 server[74756:2203] write Test::A +2008-09-05 18:27:29.339 server[74756:2203] write Test::B +2008-09-05 18:27:29.339 server[74756:2203] write Test::A +2008-09-05 18:27:29.339 server[74756:2203] write Test::B +2008-09-05 18:27:29.340 server[74756:2203] write Test::A +2008-09-05 18:27:29.340 server[74756:2203] write Test::B +2008-09-05 18:27:29.341 server[74756:2203] write Test::A +2008-09-05 18:27:29.341 server[74756:2203] write Test::B +2008-09-05 18:27:29.341 server[74756:2203] write Test::A +2008-09-05 18:27:29.342 server[74756:2203] write Test::B +2008-09-05 18:27:29.342 server[74756:2203] write Test::A +2008-09-05 18:27:29.343 server[74756:2203] write Test::B +2008-09-05 18:27:29.343 server[74756:2203] write Test::A +2008-09-05 18:27:29.343 server[74756:2203] write Test::B +2008-09-05 18:27:29.344 server[74756:2203] write Test::A +2008-09-05 18:27:29.344 server[74756:2203] write Test::B +2008-09-05 18:27:29.344 server[74756:2203] write Test::A +2008-09-05 18:27:29.345 server[74756:2203] write Test::B +2008-09-05 18:27:29.345 server[74756:2203] write Test::A +2008-09-05 18:27:29.346 server[74756:2203] write Test::B +2008-09-05 18:27:29.346 server[74756:2203] write Test::A +2008-09-05 18:27:29.346 server[74756:2203] write Test::B +2008-09-05 18:27:29.347 server[74756:2203] write Test::A +2008-09-05 18:27:29.347 server[74756:2203] write Test::B +2008-09-05 18:27:29.348 server[74756:2203] write Test::A +2008-09-05 18:27:29.348 server[74756:2203] write Test::B +2008-09-05 18:27:29.348 server[74756:2203] write Test::A +2008-09-05 18:27:29.349 server[74756:2203] write Test::B +2008-09-05 18:27:29.349 server[74756:2203] write Test::A +2008-09-05 18:27:29.350 server[74756:2203] write Test::B +2008-09-05 18:27:29.350 server[74756:2203] write Test::A +2008-09-05 18:27:29.350 server[74756:2203] write Test::B +2008-09-05 18:27:29.351 server[74756:2203] write Test::A +2008-09-05 18:27:29.351 server[74756:2203] write Test::B +2008-09-05 18:27:29.352 server[74756:2203] write Test::A +2008-09-05 18:27:29.352 server[74756:2203] write Test::B +2008-09-05 18:27:29.352 server[74756:2203] write Test::A +2008-09-05 18:27:29.353 server[74756:2203] write Test::B +2008-09-05 18:27:29.353 server[74756:2203] write Test::A +2008-09-05 18:27:29.354 server[74756:2203] write Test::B +2008-09-05 18:27:29.354 server[74756:2203] write Test::A +2008-09-05 18:27:29.354 server[74756:2203] write Test::B +2008-09-05 18:27:29.355 server[74756:2203] write Test::A +2008-09-05 18:27:29.355 server[74756:2203] write Test::B +2008-09-05 18:27:29.355 server[74756:2203] write Test::A +2008-09-05 18:27:29.356 server[74756:2203] write Test::B +2008-09-05 18:27:29.356 server[74756:2203] write Test::A +2008-09-05 18:27:29.357 server[74756:2203] write Test::B +2008-09-05 18:27:29.357 server[74756:2203] write Test::A +2008-09-05 18:27:29.357 server[74756:2203] write Test::B +2008-09-05 18:27:29.358 server[74756:2203] write Test::A +2008-09-05 18:27:29.359 server[74756:2203] write Test::B +2008-09-05 18:27:29.359 server[74756:2203] write Test::A +2008-09-05 18:27:29.359 server[74756:2203] write Test::B +2008-09-05 18:27:29.360 server[74756:2203] write Test::A +2008-09-05 18:27:29.360 server[74756:2203] write Test::B +2008-09-05 18:27:29.361 server[74756:2203] write Test::A +2008-09-05 18:27:29.362 server[74756:2203] write Test::B +2008-09-05 18:27:29.362 server[74756:2203] write Test::A +2008-09-05 18:27:29.362 server[74756:2203] write Test::B +2008-09-05 18:27:29.363 server[74756:2203] write Test::A +2008-09-05 18:27:29.363 server[74756:2203] write Test::B +2008-09-05 18:27:29.364 server[74756:2203] write Test::A +2008-09-05 18:27:29.364 server[74756:2203] write Test::B +2008-09-05 18:27:29.364 server[74756:2203] write Test::A +2008-09-05 18:27:29.366 server[74756:2203] write Test::B +2008-09-05 18:27:29.366 server[74756:2203] write Test::A +2008-09-05 18:27:29.367 server[74756:2203] write Test::B +2008-09-05 18:27:29.367 server[74756:2203] write Test::A +2008-09-05 18:27:29.368 server[74756:2203] write Test::B +2008-09-05 18:27:29.368 server[74756:2203] write Test::A +2008-09-05 18:27:29.368 server[74756:2203] write Test::B +2008-09-05 18:27:29.369 server[74756:2203] write Test::A +2008-09-05 18:27:29.369 server[74756:2203] write Test::B +2008-09-05 18:27:29.370 server[74756:2203] write Test::A +2008-09-05 18:27:29.370 server[74756:2203] write Test::B +2008-09-05 18:27:29.370 server[74756:2203] write Test::A +2008-09-05 18:27:29.371 server[74756:2203] write Test::B +2008-09-05 18:27:29.371 server[74756:2203] write Test::A +2008-09-05 18:27:29.371 server[74756:2203] write Test::B +2008-09-05 18:27:29.372 server[74756:2203] write Test::A +2008-09-05 18:27:29.372 server[74756:2203] write Test::B +2008-09-05 18:27:29.373 server[74756:2203] write Test::A +2008-09-05 18:27:29.373 server[74756:2203] write Test::B +2008-09-05 18:27:29.373 server[74756:2203] write Test::A +2008-09-05 18:27:29.374 server[74756:2203] write Test::B +2008-09-05 18:27:29.374 server[74756:2203] write Test::A +2008-09-05 18:27:29.375 server[74756:2203] write Test::B +2008-09-05 18:27:29.375 server[74756:2203] write Test::A +2008-09-05 18:27:29.375 server[74756:2203] write Test::B +2008-09-05 18:27:29.376 server[74756:2203] write Test::A +2008-09-05 18:27:29.376 server[74756:2203] write Test::B +2008-09-05 18:27:29.377 server[74756:2203] write Test::A +2008-09-05 18:27:29.377 server[74756:2203] write Test::B +2008-09-05 18:27:29.377 server[74756:2203] write Test::A +2008-09-05 18:27:29.378 server[74756:2203] write Test::B +2008-09-05 18:27:29.378 server[74756:2203] write Test::A +2008-09-05 18:27:29.379 server[74756:2203] write Test::B +2008-09-05 18:27:29.379 server[74756:2203] write Test::A +2008-09-05 18:27:29.379 server[74756:2203] write Test::B +2008-09-05 18:27:29.380 server[74756:2203] write Test::A +2008-09-05 18:27:29.380 server[74756:2203] write Test::B +2008-09-05 18:27:29.381 server[74756:2203] write Test::A +2008-09-05 18:27:29.381 server[74756:2203] write Test::B +2008-09-05 18:27:29.381 server[74756:2203] write Test::A +2008-09-05 18:27:29.382 server[74756:2203] write Test::B +2008-09-05 18:27:29.382 server[74756:2203] write Test::A +2008-09-05 18:27:29.382 server[74756:2203] write Test::B +2008-09-05 18:27:29.383 server[74756:2203] write Test::A +2008-09-05 18:27:29.383 server[74756:2203] write Test::B +2008-09-05 18:27:29.384 server[74756:2203] write Test::A +2008-09-05 18:27:29.384 server[74756:2203] write Test::B +2008-09-05 18:27:29.384 server[74756:2203] write Test::A +2008-09-05 18:27:29.385 server[74756:2203] write Test::B +2008-09-05 18:27:29.385 server[74756:2203] write Test::A +2008-09-05 18:27:29.386 server[74756:2203] write Test::B +2008-09-05 18:27:29.386 server[74756:2203] write Test::A +2008-09-05 18:27:29.386 server[74756:2203] write Test::B +2008-09-05 18:27:29.387 server[74756:2203] write Test::A +2008-09-05 18:27:29.388 server[74756:2203] write Test::B +2008-09-05 18:27:29.388 server[74756:2203] write Test::A +2008-09-05 18:27:29.388 server[74756:2203] write Test::B +2008-09-05 18:27:29.389 server[74756:2203] write Test::A +2008-09-05 18:27:29.389 server[74756:2203] write Test::B +2008-09-05 18:27:29.389 server[74756:2203] write Test::A +2008-09-05 18:27:29.390 server[74756:2203] write Test::B +2008-09-05 18:27:29.390 server[74756:2203] write Test::A +2008-09-05 18:27:29.391 server[74756:2203] write Test::B +2008-09-05 18:27:29.391 server[74756:2203] write Test::A +2008-09-05 18:27:29.391 server[74756:2203] write Test::B +2008-09-05 18:27:29.392 server[74756:2203] write Test::A +2008-09-05 18:27:29.392 server[74756:2203] write Test::B +2008-09-05 18:27:29.393 server[74756:2203] write Test::A +2008-09-05 18:27:29.393 server[74756:2203] write Test::B +2008-09-05 18:27:29.393 server[74756:2203] write Test::A +2008-09-05 18:27:29.394 server[74756:2203] write Test::B +2008-09-05 18:27:29.394 server[74756:2203] write Test::A +2008-09-05 18:27:29.395 server[74756:2203] write Test::B +2008-09-05 18:27:29.395 server[74756:2203] write Test::A +2008-09-05 18:27:29.395 server[74756:2203] write Test::B +2008-09-05 18:27:29.396 server[74756:2203] write Test::A +2008-09-05 18:27:29.396 server[74756:2203] write Test::B +2008-09-05 18:27:29.396 server[74756:2203] write Test::A +2008-09-05 18:27:29.397 server[74756:2203] write Test::B +2008-09-05 18:27:29.397 server[74756:2203] write Test::A +2008-09-05 18:27:29.398 server[74756:2203] write Test::B +2008-09-05 18:27:29.398 server[74756:2203] write Test::A +2008-09-05 18:27:29.398 server[74756:2203] write Test::B +2008-09-05 18:27:29.399 server[74756:2203] write Test::A +2008-09-05 18:27:29.399 server[74756:2203] write Test::B +2008-09-05 18:27:29.399 server[74756:2203] write Test::A +2008-09-05 18:27:29.400 server[74756:2203] write Test::B +2008-09-05 18:27:29.400 server[74756:2203] write Test::A +2008-09-05 18:27:29.401 server[74756:2203] write Test::B +2008-09-05 18:27:29.401 server[74756:2203] write Test::A +2008-09-05 18:27:29.401 server[74756:2203] write Test::B +2008-09-05 18:27:29.402 server[74756:2203] write Test::A +2008-09-05 18:27:29.402 server[74756:2203] write Test::B +2008-09-05 18:27:29.402 server[74756:2203] write Test::A +2008-09-05 18:27:29.403 server[74756:2203] write Test::B +2008-09-05 18:27:29.403 server[74756:2203] write Test::A +2008-09-05 18:27:29.403 server[74756:2203] write Test::B +2008-09-05 18:27:29.404 server[74756:2203] write Test::A +2008-09-05 18:27:29.404 server[74756:2203] write Test::B +2008-09-05 18:27:29.405 server[74756:2203] write Test::A +2008-09-05 18:27:29.405 server[74756:2203] write Test::B +2008-09-05 18:27:29.405 server[74756:2203] write Test::A +2008-09-05 18:27:29.406 server[74756:2203] write Test::B +2008-09-05 18:27:29.406 server[74756:2203] write Test::A +2008-09-05 18:27:29.406 server[74756:2203] write Test::B +2008-09-05 18:27:29.407 server[74756:2203] write Test::A +2008-09-05 18:27:29.408 server[74756:2203] write Test::B +2008-09-05 18:27:29.408 server[74756:2203] write Test::A +2008-09-05 18:27:29.409 server[74756:2203] write Test::B +2008-09-05 18:27:29.409 server[74756:2203] write Test::A +2008-09-05 18:27:29.409 server[74756:2203] write Test::B +2008-09-05 18:27:29.410 server[74756:2203] write Test::A +2008-09-05 18:27:29.410 server[74756:2203] write Test::B +2008-09-05 18:27:29.411 server[74756:2203] write Test::A +2008-09-05 18:27:29.411 server[74756:2203] write Test::B +2008-09-05 18:27:29.411 server[74756:2203] write Test::A +2008-09-05 18:27:29.412 server[74756:2203] write Test::B +2008-09-05 18:27:29.412 server[74756:2203] write Test::A +2008-09-05 18:27:29.413 server[74756:2203] write Test::B +2008-09-05 18:27:29.413 server[74756:2203] write Test::A +2008-09-05 18:27:29.413 server[74756:2203] write Test::B +2008-09-05 18:27:29.414 server[74756:2203] write Test::A +2008-09-05 18:27:29.414 server[74756:2203] write Test::B +2008-09-05 18:27:29.415 server[74756:2203] write Test::A +2008-09-05 18:27:29.415 server[74756:2203] write Test::B +2008-09-05 18:27:29.415 server[74756:2203] write Test::A +2008-09-05 18:27:29.416 server[74756:2203] write Test::B +2008-09-05 18:27:29.416 server[74756:2203] write Test::A +2008-09-05 18:27:29.416 server[74756:2203] write Test::B +2008-09-05 18:27:29.417 server[74756:2203] write Test::A +2008-09-05 18:27:29.417 server[74756:2203] write Test::B +2008-09-05 18:27:29.418 server[74756:2203] write Test::A +2008-09-05 18:27:29.418 server[74756:2203] write Test::B +2008-09-05 18:27:29.418 server[74756:2203] write Test::A +2008-09-05 18:27:29.419 server[74756:2203] write Test::B +2008-09-05 18:27:29.419 server[74756:2203] write Test::A +2008-09-05 18:27:29.419 server[74756:2203] write Test::B +2008-09-05 18:27:29.420 server[74756:2203] write Test::A +2008-09-05 18:27:29.420 server[74756:2203] write Test::B +2008-09-05 18:27:29.420 server[74756:2203] write Test::A +2008-09-05 18:27:29.421 server[74756:2203] write Test::B +2008-09-05 18:27:29.421 server[74756:2203] write Test::A +2008-09-05 18:27:29.421 server[74756:2203] write Test::B +2008-09-05 18:27:29.422 server[74756:2203] write Test::A +2008-09-05 18:27:29.422 server[74756:2203] write Test::B +2008-09-05 18:27:29.423 server[74756:2203] write Test::A +2008-09-05 18:27:29.423 server[74756:2203] write Test::B +2008-09-05 18:27:29.423 server[74756:2203] write Test::A +2008-09-05 18:27:29.424 server[74756:2203] write Test::B +2008-09-05 18:27:29.424 server[74756:2203] write Test::A +2008-09-05 18:27:29.424 server[74756:2203] write Test::B +2008-09-05 18:27:29.425 server[74756:2203] write Test::A +2008-09-05 18:27:29.425 server[74756:2203] write Test::B +2008-09-05 18:27:29.425 server[74756:2203] write Test::A +2008-09-05 18:27:29.426 server[74756:2203] write Test::B +2008-09-05 18:27:29.426 server[74756:2203] write Test::A +2008-09-05 18:27:29.427 server[74756:2203] write Test::B +2008-09-05 18:27:29.427 server[74756:2203] write Test::A +2008-09-05 18:27:29.427 server[74756:2203] write Test::B +2008-09-05 18:27:29.428 server[74756:2203] write Test::A +2008-09-05 18:27:29.428 server[74756:2203] write Test::B +2008-09-05 18:27:29.428 server[74756:2203] write Test::A +2008-09-05 18:27:29.429 server[74756:2203] write Test::B +2008-09-05 18:27:29.429 server[74756:2203] write Test::A +2008-09-05 18:27:29.430 server[74756:2203] write Test::B +2008-09-05 18:27:29.430 server[74756:2203] write Test::A +2008-09-05 18:27:29.431 server[74756:2203] write Test::B +2008-09-05 18:27:29.431 server[74756:2203] write Test::A +2008-09-05 18:27:29.431 server[74756:2203] write Test::B +2008-09-05 18:27:29.432 server[74756:2203] write Test::A +2008-09-05 18:27:29.432 server[74756:2203] write Test::B +2008-09-05 18:27:29.432 server[74756:2203] write Test::A +2008-09-05 18:27:29.433 server[74756:2203] write Test::B +2008-09-05 18:27:29.433 server[74756:2203] write Test::A +2008-09-05 18:27:29.433 server[74756:2203] write Test::B +2008-09-05 18:27:29.434 server[74756:2203] write Test::A +2008-09-05 18:27:29.434 server[74756:2203] write Test::B +2008-09-05 18:27:29.434 server[74756:2203] write Test::A +2008-09-05 18:27:29.435 server[74756:2203] write Test::B +2008-09-05 18:27:29.435 server[74756:2203] write Test::A +2008-09-05 18:27:29.436 server[74756:2203] write Test::B +2008-09-05 18:27:29.436 server[74756:2203] write Test::A +2008-09-05 18:27:29.436 server[74756:2203] write Test::B +2008-09-05 18:27:29.437 server[74756:2203] write Test::A +2008-09-05 18:27:29.437 server[74756:2203] write Test::B +2008-09-05 18:27:29.438 server[74756:2203] write Test::A +2008-09-05 18:27:29.438 server[74756:2203] write Test::B +2008-09-05 18:27:29.438 server[74756:2203] write Test::A +2008-09-05 18:27:29.439 server[74756:2203] write Test::B +2008-09-05 18:27:29.439 server[74756:2203] write Test::A +2008-09-05 18:27:29.439 server[74756:2203] write Test::B +2008-09-05 18:27:29.440 server[74756:2203] write Test::A +2008-09-05 18:27:29.440 server[74756:2203] write Test::B +2008-09-05 18:27:29.441 server[74756:2203] write Test::A +2008-09-05 18:27:29.441 server[74756:2203] write Test::B +2008-09-05 18:27:29.441 server[74756:2203] write Test::A +2008-09-05 18:27:29.442 server[74756:2203] write Test::B +2008-09-05 18:27:29.442 server[74756:2203] write Test::A +2008-09-05 18:27:29.442 server[74756:2203] write Test::B +2008-09-05 18:27:29.443 server[74756:2203] write Test::A +2008-09-05 18:27:29.443 server[74756:2203] write Test::B +2008-09-05 18:27:29.443 server[74756:2203] write Test::A +2008-09-05 18:27:29.444 server[74756:2203] write Test::B +2008-09-05 18:27:29.444 server[74756:2203] write Test::A +2008-09-05 18:27:29.445 server[74756:2203] write Test::B +2008-09-05 18:27:29.445 server[74756:2203] write Test::A +2008-09-05 18:27:29.445 server[74756:2203] write Test::B +2008-09-05 18:27:29.446 server[74756:2203] write Test::A +2008-09-05 18:27:29.446 server[74756:2203] write Test::B +2008-09-05 18:27:29.446 server[74756:2203] write Test::A +2008-09-05 18:27:29.447 server[74756:2203] write Test::B +2008-09-05 18:27:29.447 server[74756:2203] write Test::A +2008-09-05 18:27:29.448 server[74756:2203] write Test::B +2008-09-05 18:27:29.448 server[74756:2203] write Test::A +2008-09-05 18:27:29.448 server[74756:2203] write Test::B +2008-09-05 18:27:29.449 server[74756:2203] write Test::A +2008-09-05 18:27:29.449 server[74756:2203] write Test::B +2008-09-05 18:27:29.449 server[74756:2203] write Test::A +2008-09-05 18:27:29.450 server[74756:2203] write Test::B +2008-09-05 18:27:29.450 server[74756:2203] write Test::A +2008-09-05 18:27:29.450 server[74756:2203] write Test::B +2008-09-05 18:27:29.451 server[74756:2203] write Test::A +2008-09-05 18:27:29.451 server[74756:2203] write Test::B +2008-09-05 18:27:29.452 server[74756:2203] write Test::A +2008-09-05 18:27:29.452 server[74756:2203] write Test::B +2008-09-05 18:27:29.452 server[74756:2203] write Test::A +2008-09-05 18:27:29.453 server[74756:2203] write Test::B +2008-09-05 18:27:29.453 server[74756:2203] write Test::A +2008-09-05 18:27:29.453 server[74756:2203] write Test::B +2008-09-05 18:27:29.454 server[74756:2203] write Test::A +2008-09-05 18:27:29.454 server[74756:2203] write Test::B +2008-09-05 18:27:29.454 server[74756:2203] write Test::A +2008-09-05 18:27:29.455 server[74756:2203] write Test::B +2008-09-05 18:27:29.455 server[74756:2203] write Test::A +2008-09-05 18:27:29.456 server[74756:2203] write Test::B +2008-09-05 18:27:29.456 server[74756:2203] write Test::A +2008-09-05 18:27:29.457 server[74756:2203] write Test::B +2008-09-05 18:27:29.457 server[74756:2203] write Test::A +2008-09-05 18:27:29.457 server[74756:2203] write Test::B +2008-09-05 18:27:29.458 server[74756:2203] write Test::A +2008-09-05 18:27:29.458 server[74756:2203] write Test::B +2008-09-05 18:27:29.460 server[74756:2203] write Test::A +2008-09-05 18:27:29.460 server[74756:2203] write Test::B +2008-09-05 18:27:29.461 server[74756:2203] write Test::A +2008-09-05 18:27:29.461 server[74756:2203] write Test::B +2008-09-05 18:27:29.462 server[74756:2203] write Test::A +2008-09-05 18:27:29.462 server[74756:2203] write Test::B +2008-09-05 18:27:29.462 server[74756:2203] write Test::A +2008-09-05 18:27:29.463 server[74756:2203] write Test::B +2008-09-05 18:27:29.463 server[74756:2203] write Test::A +2008-09-05 18:27:29.463 server[74756:2203] write Test::B +2008-09-05 18:27:29.464 server[74756:2203] write Test::A +2008-09-05 18:27:29.464 server[74756:2203] write Test::B +2008-09-05 18:27:29.465 server[74756:2203] write Test::A +2008-09-05 18:27:29.465 server[74756:2203] write Test::B +2008-09-05 18:27:29.465 server[74756:2203] write Test::A +2008-09-05 18:27:29.466 server[74756:2203] write Test::B +2008-09-05 18:27:29.466 server[74756:2203] write Test::A +2008-09-05 18:27:29.467 server[74756:2203] write Test::B +2008-09-05 18:27:29.467 server[74756:2203] write Test::A +2008-09-05 18:27:29.467 server[74756:2203] write Test::B +2008-09-05 18:27:29.468 server[74756:2203] write Test::A +2008-09-05 18:27:29.468 server[74756:2203] write Test::B +2008-09-05 18:27:29.468 server[74756:2203] write Test::A +2008-09-05 18:27:29.469 server[74756:2203] write Test::B +2008-09-05 18:27:29.469 server[74756:2203] write Test::A +2008-09-05 18:27:29.470 server[74756:2203] write Test::B +2008-09-05 18:27:29.470 server[74756:2203] write Test::A +2008-09-05 18:27:29.470 server[74756:2203] write Test::B +2008-09-05 18:27:29.471 server[74756:2203] write Test::A +2008-09-05 18:27:29.471 server[74756:2203] write Test::B +2008-09-05 18:27:29.472 server[74756:2203] write Test::A +2008-09-05 18:27:29.472 server[74756:2203] write Test::B +2008-09-05 18:27:29.472 server[74756:2203] write Test::A +2008-09-05 18:27:29.473 server[74756:2203] write Test::B +2008-09-05 18:27:29.473 server[74756:2203] write Test::A +2008-09-05 18:27:29.473 server[74756:2203] write Test::B +2008-09-05 18:27:29.474 server[74756:2203] write Test::A +2008-09-05 18:27:29.474 server[74756:2203] write Test::B +2008-09-05 18:27:29.475 server[74756:2203] write Test::A +2008-09-05 18:27:29.475 server[74756:2203] write Test::B +2008-09-05 18:27:29.475 server[74756:2203] write Test::A +2008-09-05 18:27:29.476 server[74756:2203] write Test::B +2008-09-05 18:27:29.476 server[74756:2203] write Test::A +2008-09-05 18:27:29.476 server[74756:2203] write Test::B +2008-09-05 18:27:29.477 server[74756:2203] write Test::A +2008-09-05 18:27:29.477 server[74756:2203] write Test::B +2008-09-05 18:27:29.478 server[74756:2203] write Test::A +2008-09-05 18:27:29.478 server[74756:2203] write Test::B +2008-09-05 18:27:29.479 server[74756:2203] write Test::A +2008-09-05 18:27:29.479 server[74756:2203] write Test::B +2008-09-05 18:27:29.479 server[74756:2203] write Test::A +2008-09-05 18:27:29.480 server[74756:2203] write Test::B +2008-09-05 18:27:29.480 server[74756:2203] write Test::A +2008-09-05 18:27:29.480 server[74756:2203] write Test::B +2008-09-05 18:27:29.481 server[74756:2203] write Test::A +2008-09-05 18:27:29.481 server[74756:2203] write Test::B +2008-09-05 18:27:29.482 server[74756:2203] write Test::A +2008-09-05 18:27:29.482 server[74756:2203] write Test::B +2008-09-05 18:27:29.482 server[74756:2203] write Test::A +2008-09-05 18:27:29.483 server[74756:2203] write Test::B +2008-09-05 18:27:29.483 server[74756:2203] write Test::A +2008-09-05 18:27:29.483 server[74756:2203] write Test::B +2008-09-05 18:27:29.484 server[74756:2203] write Test::A +2008-09-05 18:27:29.484 server[74756:2203] write Test::B +2008-09-05 18:27:29.485 server[74756:2203] write Test::A +2008-09-05 18:27:29.485 server[74756:2203] write Test::B +2008-09-05 18:27:29.485 server[74756:2203] write Test::A +2008-09-05 18:27:29.486 server[74756:2203] write Test::B +2008-09-05 18:27:29.486 server[74756:2203] write Test::A +2008-09-05 18:27:29.486 server[74756:2203] write Test::B +2008-09-05 18:27:29.487 server[74756:2203] write Test::A +2008-09-05 18:27:29.487 server[74756:2203] write Test::B +2008-09-05 18:27:29.488 server[74756:2203] write Test::A +2008-09-05 18:27:29.488 server[74756:2203] write Test::B +2008-09-05 18:27:29.488 server[74756:2203] write Test::A +2008-09-05 18:27:29.489 server[74756:2203] write Test::B +2008-09-05 18:27:29.489 server[74756:2203] write Test::A +2008-09-05 18:27:29.490 server[74756:2203] write Test::B +2008-09-05 18:27:29.491 server[74756:2203] write Test::A +2008-09-05 18:27:29.491 server[74756:2203] write Test::B +2008-09-05 18:27:29.491 server[74756:2203] write Test::A +2008-09-05 18:27:29.492 server[74756:2203] write Test::B +2008-09-05 18:27:29.492 server[74756:2203] write Test::A +2008-09-05 18:27:29.492 server[74756:2203] write Test::B +2008-09-05 18:27:29.493 server[74756:2203] write Test::A +2008-09-05 18:27:29.493 server[74756:2203] write Test::B +2008-09-05 18:27:29.494 server[74756:2203] write Test::A +2008-09-05 18:27:29.494 server[74756:2203] write Test::B +2008-09-05 18:27:29.494 server[74756:2203] write Test::A +2008-09-05 18:27:29.495 server[74756:2203] write Test::B +2008-09-05 18:27:29.495 server[74756:2203] write Test::A +2008-09-05 18:27:29.496 server[74756:2203] write Test::B +2008-09-05 18:27:29.496 server[74756:2203] write Test::A +2008-09-05 18:27:29.496 server[74756:2203] write Test::B +2008-09-05 18:27:29.497 server[74756:2203] write Test::A +2008-09-05 18:27:29.497 server[74756:2203] write Test::B +2008-09-05 18:27:29.497 server[74756:2203] write Test::A +2008-09-05 18:27:29.498 server[74756:2203] write Test::B +2008-09-05 18:27:29.498 server[74756:2203] write Test::A +2008-09-05 18:27:29.499 server[74756:2203] write Test::B +2008-09-05 18:27:29.499 server[74756:2203] write Test::A +2008-09-05 18:27:29.499 server[74756:2203] write Test::B +2008-09-05 18:27:29.500 server[74756:2203] write Test::A +2008-09-05 18:27:29.500 server[74756:2203] write Test::B +2008-09-05 18:27:29.501 server[74756:2203] write Test::A +2008-09-05 18:27:29.501 server[74756:2203] write Test::B +2008-09-05 18:27:29.501 server[74756:2203] write Test::A +2008-09-05 18:27:29.502 server[74756:2203] write Test::B +2008-09-05 18:27:29.502 server[74756:2203] write Test::A +2008-09-05 18:27:29.502 server[74756:2203] write Test::B +2008-09-05 18:27:29.503 server[74756:2203] write Test::A +2008-09-05 18:27:29.503 server[74756:2203] write Test::B +2008-09-05 18:27:29.504 server[74756:2203] write Test::A +2008-09-05 18:27:29.504 server[74756:2203] write Test::B +2008-09-05 18:27:29.504 server[74756:2203] write Test::A +2008-09-05 18:27:29.505 server[74756:2203] write Test::B +2008-09-05 18:27:29.505 server[74756:2203] write Test::A +2008-09-05 18:27:29.505 server[74756:2203] write Test::B +2008-09-05 18:27:29.506 server[74756:2203] write Test::A +2008-09-05 18:27:29.506 server[74756:2203] write Test::B +2008-09-05 18:27:29.507 server[74756:2203] write Test::A +2008-09-05 18:27:29.507 server[74756:2203] write Test::B +2008-09-05 18:27:29.507 server[74756:2203] write Test::A +2008-09-05 18:27:29.509 server[74756:2203] write Test::B +2008-09-05 18:27:29.511 server[74756:2203] write Test::A +2008-09-05 18:27:29.512 server[74756:2203] write Test::B +2008-09-05 18:27:29.512 server[74756:2203] write Test::A +2008-09-05 18:27:29.513 server[74756:2203] write Test::B +2008-09-05 18:27:29.513 server[74756:2203] write Test::A +2008-09-05 18:27:29.516 server[74756:2203] write Test::B +2008-09-05 18:27:29.518 server[74756:2203] write Test::A +2008-09-05 18:27:29.520 server[74756:2203] write Test::B +2008-09-05 18:27:29.523 server[74756:2203] write Test::A +2008-09-05 18:27:29.524 server[74756:2203] write Test::B +2008-09-05 18:27:29.526 server[74756:2203] write Test::A +2008-09-05 18:27:29.528 server[74756:2203] write Test::B +2008-09-05 18:27:29.528 server[74756:2203] write Test::A +2008-09-05 18:27:29.530 server[74756:2203] write Test::B +2008-09-05 18:27:29.530 server[74756:2203] write Test::A +2008-09-05 18:27:29.531 server[74756:2203] write Test::B +2008-09-05 18:27:29.531 server[74756:2203] write Test::A +2008-09-05 18:27:29.532 server[74756:2203] write Test::B +2008-09-05 18:27:29.532 server[74756:2203] write Test::A +2008-09-05 18:27:29.533 server[74756:2203] write Test::B +2008-09-05 18:27:29.534 server[74756:2203] write Test::A +2008-09-05 18:27:29.535 server[74756:2203] write Test::B +2008-09-05 18:27:29.538 server[74756:2203] write Test::A +2008-09-05 18:27:29.540 server[74756:2203] write Test::B +2008-09-05 18:27:29.540 server[74756:2203] write Test::A +2008-09-05 18:27:29.540 server[74756:2203] write Test::B +2008-09-05 18:27:29.541 server[74756:2203] write Test::A +2008-09-05 18:27:29.541 server[74756:2203] write Test::B +2008-09-05 18:27:29.541 server[74756:2203] write Test::A +2008-09-05 18:27:29.542 server[74756:2203] write Test::B +2008-09-05 18:27:29.543 server[74756:2203] write Test::A +2008-09-05 18:27:29.544 server[74756:2203] write Test::B +2008-09-05 18:27:29.544 server[74756:2203] write Test::A +2008-09-05 18:27:29.546 server[74756:2203] write Test::B +2008-09-05 18:27:29.546 server[74756:2203] write Test::A +2008-09-05 18:27:29.548 server[74756:2203] write Test::B +2008-09-05 18:27:29.549 server[74756:2203] write Test::A +2008-09-05 18:27:29.549 server[74756:2203] write Test::B +2008-09-05 18:27:29.549 server[74756:2203] write Test::A +2008-09-05 18:27:29.550 server[74756:2203] write Test::B +2008-09-05 18:27:29.550 server[74756:2203] write Test::A +2008-09-05 18:27:29.551 server[74756:2203] write Test::B +2008-09-05 18:27:29.551 server[74756:2203] write Test::A +2008-09-05 18:27:29.552 server[74756:2203] write Test::B +2008-09-05 18:27:29.553 server[74756:2203] write Test::A +2008-09-05 18:27:29.553 server[74756:2203] write Test::B +2008-09-05 18:27:29.554 server[74756:2203] write Test::A +2008-09-05 18:27:29.555 server[74756:2203] write Test::B +2008-09-05 18:27:29.556 server[74756:2203] write Test::A +2008-09-05 18:27:29.558 server[74756:2203] write Test::B +2008-09-05 18:27:29.558 server[74756:2203] write Test::A +2008-09-05 18:27:29.558 server[74756:2203] write Test::B +2008-09-05 18:27:29.559 server[74756:2203] write Test::A +2008-09-05 18:27:29.559 server[74756:2203] write Test::B +2008-09-05 18:27:29.560 server[74756:2203] write Test::A +2008-09-05 18:27:29.562 server[74756:2203] write Test::B +2008-09-05 18:27:29.562 server[74756:2203] write Test::A +2008-09-05 18:27:29.563 server[74756:2203] write Test::B +2008-09-05 18:27:29.563 server[74756:2203] write Test::A +2008-09-05 18:27:29.564 server[74756:2203] write Test::B +2008-09-05 18:27:29.564 server[74756:2203] write Test::A +2008-09-05 18:27:29.565 server[74756:2203] write Test::B +2008-09-05 18:27:29.566 server[74756:2203] write Test::A +2008-09-05 18:27:29.567 server[74756:2203] write Test::B +2008-09-05 18:27:29.567 server[74756:2203] write Test::A +2008-09-05 18:27:29.568 server[74756:2203] write Test::B +2008-09-05 18:27:29.570 server[74756:2203] write Test::A +2008-09-05 18:27:29.570 server[74756:2203] write Test::B +2008-09-05 18:27:29.571 server[74756:2203] write Test::A +2008-09-05 18:27:29.571 server[74756:2203] write Test::B +2008-09-05 18:27:29.571 server[74756:2203] write Test::A +2008-09-05 18:27:29.572 server[74756:2203] write Test::B +2008-09-05 18:27:29.573 server[74756:2203] write Test::A +2008-09-05 18:27:29.573 server[74756:2203] write Test::B +2008-09-05 18:27:29.573 server[74756:2203] write Test::A +2008-09-05 18:27:29.574 server[74756:2203] write Test::B +2008-09-05 18:27:29.574 server[74756:2203] write Test::A +2008-09-05 18:27:29.575 server[74756:2203] write Test::B +2008-09-05 18:27:29.576 server[74756:2203] write Test::A +2008-09-05 18:27:29.576 server[74756:2203] write Test::B +2008-09-05 18:27:29.577 server[74756:2203] write Test::A +2008-09-05 18:27:29.578 server[74756:2203] write Test::B +2008-09-05 18:27:29.578 server[74756:2203] write Test::A +2008-09-05 18:27:29.579 server[74756:2203] write Test::B +2008-09-05 18:27:29.580 server[74756:2203] write Test::A +2008-09-05 18:27:29.581 server[74756:2203] write Test::B +2008-09-05 18:27:29.581 server[74756:2203] write Test::A +2008-09-05 18:27:29.582 server[74756:2203] write Test::B +2008-09-05 18:27:29.582 server[74756:2203] write Test::A +2008-09-05 18:27:29.583 server[74756:2203] write Test::B +2008-09-05 18:27:29.583 server[74756:2203] write Test::A +2008-09-05 18:27:29.584 server[74756:2203] write Test::B +2008-09-05 18:27:29.584 server[74756:2203] write Test::A +2008-09-05 18:27:29.585 server[74756:2203] write Test::B +2008-09-05 18:27:29.585 server[74756:2203] write Test::A +2008-09-05 18:27:29.586 server[74756:2203] write Test::B +2008-09-05 18:27:29.587 server[74756:2203] write Test::A +2008-09-05 18:27:29.587 server[74756:2203] write Test::B +2008-09-05 18:27:29.588 server[74756:2203] write Test::A +2008-09-05 18:27:29.588 server[74756:2203] write Test::B +2008-09-05 18:27:29.589 server[74756:2203] write Test::A +2008-09-05 18:27:29.589 server[74756:2203] write Test::B +2008-09-05 18:27:29.590 server[74756:2203] write Test::A +2008-09-05 18:27:29.590 server[74756:2203] write Test::B +2008-09-05 18:27:29.591 server[74756:2203] write Test::A +2008-09-05 18:27:29.591 server[74756:2203] write Test::B +2008-09-05 18:27:29.592 server[74756:2203] write Test::A +2008-09-05 18:27:29.592 server[74756:2203] write Test::B +2008-09-05 18:27:29.593 server[74756:2203] write Test::A +2008-09-05 18:27:29.593 server[74756:2203] write Test::B +2008-09-05 18:27:29.594 server[74756:2203] write Test::A +2008-09-05 18:27:29.594 server[74756:2203] write Test::B +2008-09-05 18:27:29.595 server[74756:2203] write Test::A +2008-09-05 18:27:29.595 server[74756:2203] write Test::B +2008-09-05 18:27:29.596 server[74756:2203] write Test::A +2008-09-05 18:27:29.596 server[74756:2203] write Test::B +2008-09-05 18:27:29.597 server[74756:2203] write Test::A +2008-09-05 18:27:29.597 server[74756:2203] write Test::B +2008-09-05 18:27:29.598 server[74756:2203] write Test::A +2008-09-05 18:27:29.598 server[74756:2203] write Test::B +2008-09-05 18:27:29.599 server[74756:2203] write Test::A +2008-09-05 18:27:29.599 server[74756:2203] write Test::B +2008-09-05 18:27:29.600 server[74756:2203] write Test::A +2008-09-05 18:27:29.600 server[74756:2203] write Test::B +2008-09-05 18:27:29.601 server[74756:2203] write Test::A +2008-09-05 18:27:29.601 server[74756:2203] write Test::B +2008-09-05 18:27:29.602 server[74756:2203] write Test::A +2008-09-05 18:27:29.602 server[74756:2203] write Test::B +2008-09-05 18:27:29.603 server[74756:2203] write Test::A +2008-09-05 18:27:29.603 server[74756:2203] write Test::B +2008-09-05 18:27:29.604 server[74756:2203] write Test::A +2008-09-05 18:27:29.604 server[74756:2203] write Test::B +2008-09-05 18:27:29.605 server[74756:2203] write Test::A +2008-09-05 18:27:29.605 server[74756:2203] write Test::B +2008-09-05 18:27:29.606 server[74756:2203] write Test::A +2008-09-05 18:27:29.607 server[74756:2203] write Test::B +2008-09-05 18:27:29.607 server[74756:2203] write Test::A +2008-09-05 18:27:29.608 server[74756:2203] write Test::B +2008-09-05 18:27:29.608 server[74756:2203] write Test::A +2008-09-05 18:27:29.609 server[74756:2203] write Test::B +2008-09-05 18:27:29.609 server[74756:2203] write Test::A +2008-09-05 18:27:29.610 server[74756:2203] write Test::B +2008-09-05 18:27:29.611 server[74756:2203] write Test::A +2008-09-05 18:27:29.611 server[74756:2203] write Test::B +2008-09-05 18:27:29.612 server[74756:2203] write Test::A +2008-09-05 18:27:29.612 server[74756:2203] write Test::B +2008-09-05 18:27:29.613 server[74756:2203] write Test::A +2008-09-05 18:27:29.613 server[74756:2203] write Test::B +2008-09-05 18:27:29.614 server[74756:2203] write Test::A +2008-09-05 18:27:29.614 server[74756:2203] write Test::B +2008-09-05 18:27:29.615 server[74756:2203] write Test::A +2008-09-05 18:27:29.615 server[74756:2203] write Test::B +2008-09-05 18:27:29.616 server[74756:2203] write Test::A +2008-09-05 18:27:29.616 server[74756:2203] write Test::B +2008-09-05 18:27:29.617 server[74756:2203] write Test::A +2008-09-05 18:27:29.617 server[74756:2203] write Test::B +2008-09-05 18:27:29.618 server[74756:2203] write Test::A +2008-09-05 18:27:29.618 server[74756:2203] write Test::B +2008-09-05 18:27:29.619 server[74756:2203] write Test::A +2008-09-05 18:27:29.619 server[74756:2203] write Test::B +2008-09-05 18:27:29.620 server[74756:2203] write Test::A +2008-09-05 18:27:29.620 server[74756:2203] write Test::B +2008-09-05 18:27:29.621 server[74756:2203] write Test::A +2008-09-05 18:27:29.621 server[74756:2203] write Test::B +2008-09-05 18:27:29.622 server[74756:2203] write Test::A +2008-09-05 18:27:29.622 server[74756:2203] write Test::B +2008-09-05 18:27:29.623 server[74756:2203] write Test::A +2008-09-05 18:27:29.623 server[74756:2203] write Test::B +2008-09-05 18:27:29.624 server[74756:2203] write Test::A +2008-09-05 18:27:29.624 server[74756:2203] write Test::B +2008-09-05 18:27:29.625 server[74756:2203] write Test::A +2008-09-05 18:27:29.625 server[74756:2203] write Test::B +2008-09-05 18:27:29.626 server[74756:2203] write Test::A +2008-09-05 18:27:29.626 server[74756:2203] write Test::B +2008-09-05 18:27:29.627 server[74756:2203] write Test::A +2008-09-05 18:27:29.627 server[74756:2203] write Test::B +2008-09-05 18:27:29.628 server[74756:2203] write Test::A +2008-09-05 18:27:29.628 server[74756:2203] write Test::B +2008-09-05 18:27:29.629 server[74756:2203] write Test::A +2008-09-05 18:27:29.629 server[74756:2203] write Test::B +2008-09-05 18:27:29.630 server[74756:2203] write Test::A +2008-09-05 18:27:29.630 server[74756:2203] write Test::B +2008-09-05 18:27:29.631 server[74756:2203] write Test::A +2008-09-05 18:27:29.631 server[74756:2203] write Test::B +2008-09-05 18:27:29.632 server[74756:2203] write Test::A +2008-09-05 18:27:29.632 server[74756:2203] write Test::B +2008-09-05 18:27:29.633 server[74756:2203] write Test::A +2008-09-05 18:27:29.633 server[74756:2203] write Test::B +2008-09-05 18:27:29.634 server[74756:2203] write Test::A +2008-09-05 18:27:29.635 server[74756:2203] write Test::B +2008-09-05 18:27:29.635 server[74756:2203] write Test::A +2008-09-05 18:27:29.636 server[74756:2203] write Test::B +2008-09-05 18:27:29.636 server[74756:2203] write Test::A +2008-09-05 18:27:29.637 server[74756:2203] write Test::B +2008-09-05 18:27:29.637 server[74756:2203] write Test::A +2008-09-05 18:27:29.638 server[74756:2203] write Test::B +2008-09-05 18:27:29.638 server[74756:2203] write Test::A +2008-09-05 18:27:29.639 server[74756:2203] write Test::B +2008-09-05 18:27:29.639 server[74756:2203] write Test::A +2008-09-05 18:27:29.640 server[74756:2203] write Test::B +2008-09-05 18:27:29.640 server[74756:2203] write Test::A +2008-09-05 18:27:29.641 server[74756:2203] write Test::B +2008-09-05 18:27:29.641 server[74756:2203] write Test::A +2008-09-05 18:27:29.642 server[74756:2203] write Test::B +2008-09-05 18:27:29.642 server[74756:2203] write Test::A +2008-09-05 18:27:29.642 server[74756:2203] write Test::B +2008-09-05 18:27:29.643 server[74756:2203] write Test::A +2008-09-05 18:27:29.645 server[74756:2203] write Test::B +2008-09-05 18:27:29.645 server[74756:2203] write Test::A +2008-09-05 18:27:29.646 server[74756:2203] write Test::B +2008-09-05 18:27:29.646 server[74756:2203] write Test::A +2008-09-05 18:27:29.647 server[74756:2203] write Test::B +2008-09-05 18:27:29.647 server[74756:2203] write Test::A +2008-09-05 18:27:29.648 server[74756:2203] write Test::B +2008-09-05 18:27:29.648 server[74756:2203] write Test::A +2008-09-05 18:27:29.649 server[74756:2203] write Test::B +2008-09-05 18:27:29.649 server[74756:2203] write Test::A +2008-09-05 18:27:29.650 server[74756:2203] write Test::B +2008-09-05 18:27:29.650 server[74756:2203] write Test::A +2008-09-05 18:27:29.651 server[74756:2203] write Test::B +2008-09-05 18:27:29.651 server[74756:2203] write Test::A +2008-09-05 18:27:29.651 server[74756:2203] write Test::B +2008-09-05 18:27:29.652 server[74756:2203] write Test::A +2008-09-05 18:27:29.652 server[74756:2203] write Test::B +2008-09-05 18:27:29.653 server[74756:2203] write Test::A +2008-09-05 18:27:29.653 server[74756:2203] write Test::B +2008-09-05 18:27:29.654 server[74756:2203] write Test::A +2008-09-05 18:27:29.654 server[74756:2203] write Test::B +2008-09-05 18:27:29.655 server[74756:2203] write Test::A +2008-09-05 18:27:29.655 server[74756:2203] write Test::B +2008-09-05 18:27:29.656 server[74756:2203] write Test::A +2008-09-05 18:27:29.656 server[74756:2203] write Test::B +2008-09-05 18:27:29.657 server[74756:2203] write Test::A +2008-09-05 18:27:29.657 server[74756:2203] write Test::B +2008-09-05 18:27:29.658 server[74756:2203] write Test::A +2008-09-05 18:27:29.658 server[74756:2203] write Test::B +2008-09-05 18:27:29.659 server[74756:2203] write Test::A +2008-09-05 18:27:29.659 server[74756:2203] write Test::B +2008-09-05 18:27:29.660 server[74756:2203] write Test::A +2008-09-05 18:27:29.660 server[74756:2203] write Test::B +2008-09-05 18:27:29.661 server[74756:2203] write Test::A +2008-09-05 18:27:29.661 server[74756:2203] write Test::B +2008-09-05 18:27:29.662 server[74756:2203] write Test::A +2008-09-05 18:27:29.662 server[74756:2203] write Test::B +2008-09-05 18:27:29.663 server[74756:2203] write Test::A +2008-09-05 18:27:29.663 server[74756:2203] write Test::B +2008-09-05 18:27:29.664 server[74756:2203] write Test::A +2008-09-05 18:27:29.664 server[74756:2203] write Test::B +2008-09-05 18:27:29.664 server[74756:2203] write Test::A +2008-09-05 18:27:29.665 server[74756:2203] write Test::B +2008-09-05 18:27:29.665 server[74756:2203] write Test::A +2008-09-05 18:27:29.666 server[74756:2203] write Test::B +2008-09-05 18:27:29.666 server[74756:2203] write Test::A +2008-09-05 18:27:29.667 server[74756:2203] write Test::B +2008-09-05 18:27:29.667 server[74756:2203] write Test::A +2008-09-05 18:27:29.668 server[74756:2203] write Test::B +2008-09-05 18:27:29.668 server[74756:2203] write Test::A +2008-09-05 18:27:29.669 server[74756:2203] write Test::B +2008-09-05 18:27:29.669 server[74756:2203] write Test::A +2008-09-05 18:27:29.670 server[74756:2203] write Test::B +2008-09-05 18:27:29.670 server[74756:2203] write Test::A +2008-09-05 18:27:29.671 server[74756:2203] write Test::B +2008-09-05 18:27:29.671 server[74756:2203] write Test::A +2008-09-05 18:27:29.672 server[74756:2203] write Test::B +2008-09-05 18:27:29.672 server[74756:2203] write Test::A +2008-09-05 18:27:29.673 server[74756:2203] write Test::B +2008-09-05 18:27:29.673 server[74756:2203] write Test::A +2008-09-05 18:27:29.674 server[74756:2203] write Test::B +2008-09-05 18:27:29.674 server[74756:2203] write Test::A +2008-09-05 18:27:29.675 server[74756:2203] write Test::B +2008-09-05 18:27:29.675 server[74756:2203] write Test::A +2008-09-05 18:27:29.675 server[74756:2203] write Test::B +2008-09-05 18:27:29.676 server[74756:2203] write Test::A +2008-09-05 18:27:29.676 server[74756:2203] write Test::B +2008-09-05 18:27:29.677 server[74756:2203] write Test::A +2008-09-05 18:27:29.677 server[74756:2203] write Test::B +2008-09-05 18:27:29.678 server[74756:2203] write Test::A +2008-09-05 18:27:29.678 server[74756:2203] write Test::B +2008-09-05 18:27:29.679 server[74756:2203] write Test::A +2008-09-05 18:27:29.680 server[74756:2203] write Test::B +2008-09-05 18:27:29.680 server[74756:2203] write Test::A +2008-09-05 18:27:29.681 server[74756:2203] write Test::B +2008-09-05 18:27:29.681 server[74756:2203] write Test::A +2008-09-05 18:27:29.682 server[74756:2203] write Test::B +2008-09-05 18:27:29.682 server[74756:2203] write Test::A +2008-09-05 18:27:29.683 server[74756:2203] write Test::B +2008-09-05 18:27:29.683 server[74756:2203] write Test::A +2008-09-05 18:27:29.684 server[74756:2203] write Test::B +2008-09-05 18:27:29.684 server[74756:2203] write Test::A +2008-09-05 18:27:29.685 server[74756:2203] write Test::B +2008-09-05 18:27:29.685 server[74756:2203] write Test::A +2008-09-05 18:27:29.686 server[74756:2203] write Test::B +2008-09-05 18:27:29.686 server[74756:2203] write Test::A +2008-09-05 18:27:29.687 server[74756:2203] write Test::B +2008-09-05 18:27:29.688 server[74756:2203] write Test::A +2008-09-05 18:27:29.688 server[74756:2203] write Test::B +2008-09-05 18:27:29.689 server[74756:2203] write Test::A +2008-09-05 18:27:29.689 server[74756:2203] write Test::B +2008-09-05 18:27:29.690 server[74756:2203] write Test::A +2008-09-05 18:27:29.690 server[74756:2203] write Test::B +2008-09-05 18:27:29.691 server[74756:2203] write Test::A +2008-09-05 18:27:29.691 server[74756:2203] write Test::B +2008-09-05 18:27:29.692 server[74756:2203] write Test::A +2008-09-05 18:27:29.693 server[74756:2203] write Test::B +2008-09-05 18:27:29.693 server[74756:2203] write Test::A +2008-09-05 18:27:29.694 server[74756:2203] write Test::B +2008-09-05 18:27:29.694 server[74756:2203] write Test::A +2008-09-05 18:27:29.695 server[74756:2203] write Test::B +2008-09-05 18:27:29.695 server[74756:2203] write Test::A +2008-09-05 18:27:29.696 server[74756:2203] write Test::B +2008-09-05 18:27:29.696 server[74756:2203] write Test::A +2008-09-05 18:27:29.697 server[74756:2203] write Test::B +2008-09-05 18:27:29.697 server[74756:2203] write Test::A +2008-09-05 18:27:29.698 server[74756:2203] write Test::B +2008-09-05 18:27:29.698 server[74756:2203] write Test::A +2008-09-05 18:27:29.699 server[74756:2203] write Test::B +2008-09-05 18:27:29.699 server[74756:2203] write Test::A +2008-09-05 18:27:29.700 server[74756:2203] write Test::B +2008-09-05 18:27:29.700 server[74756:2203] write Test::A +2008-09-05 18:27:29.701 server[74756:2203] write Test::B +2008-09-05 18:27:29.701 server[74756:2203] write Test::A +2008-09-05 18:27:29.702 server[74756:2203] write Test::B +2008-09-05 18:27:29.702 server[74756:2203] write Test::A +2008-09-05 18:27:29.702 server[74756:2203] write Test::B +2008-09-05 18:27:29.703 server[74756:2203] write Test::A +2008-09-05 18:27:29.703 server[74756:2203] write Test::B +2008-09-05 18:27:29.704 server[74756:2203] write Test::A +2008-09-05 18:27:29.704 server[74756:2203] write Test::B +2008-09-05 18:27:29.705 server[74756:2203] write Test::A +2008-09-05 18:27:29.705 server[74756:2203] write Test::B +2008-09-05 18:27:29.706 server[74756:2203] write Test::A +2008-09-05 18:27:29.706 server[74756:2203] write Test::B +2008-09-05 18:27:29.707 server[74756:2203] write Test::A +2008-09-05 18:27:29.707 server[74756:2203] write Test::B +2008-09-05 18:27:29.708 server[74756:2203] write Test::A +2008-09-05 18:27:29.708 server[74756:2203] write Test::B +2008-09-05 18:27:29.709 server[74756:2203] write Test::A +2008-09-05 18:27:29.709 server[74756:2203] write Test::B +2008-09-05 18:27:29.710 server[74756:2203] write Test::A +2008-09-05 18:27:29.710 server[74756:2203] write Test::B +2008-09-05 18:27:29.711 server[74756:2203] write Test::A +2008-09-05 18:27:29.711 server[74756:2203] write Test::B +2008-09-05 18:27:29.712 server[74756:2203] write Test::A +2008-09-05 18:27:29.712 server[74756:2203] write Test::B +2008-09-05 18:27:29.712 server[74756:2203] write Test::A +2008-09-05 18:27:29.713 server[74756:2203] write Test::B +2008-09-05 18:27:29.713 server[74756:2203] write Test::A +2008-09-05 18:27:29.714 server[74756:2203] write Test::B +2008-09-05 18:27:29.714 server[74756:2203] write Test::A +2008-09-05 18:27:29.715 server[74756:2203] write Test::B +2008-09-05 18:27:29.715 server[74756:2203] write Test::A +2008-09-05 18:27:29.716 server[74756:2203] write Test::B +2008-09-05 18:27:29.716 server[74756:2203] write Test::A +2008-09-05 18:27:29.717 server[74756:2203] write Test::B +2008-09-05 18:27:29.717 server[74756:2203] write Test::A +2008-09-05 18:27:29.718 server[74756:2203] write Test::B +2008-09-05 18:27:29.718 server[74756:2203] write Test::A +2008-09-05 18:27:29.719 server[74756:2203] write Test::B +2008-09-05 18:27:29.719 server[74756:2203] write Test::A +2008-09-05 18:27:29.720 server[74756:2203] write Test::B +2008-09-05 18:27:29.721 server[74756:2203] write Test::A +2008-09-05 18:27:29.721 server[74756:2203] write Test::B +2008-09-05 18:27:29.722 server[74756:2203] write Test::A +Traceback (most recent call last): + File "./run.py", line 26, in <module> + TestUtil.clientServerTest(name) + File "../../../../config/TestUtil.py", line 1067, in clientServerTest + clientServerTestWithOptions(name, "", "") + File "../../../../config/TestUtil.py", line 1063, in clientServerTestWithOptions + getDefaultClientFile()) + File "../../../../config/TestUtil.py", line 1044, in clientServerTestWithOptionsAndNames + printOutputFromPipe(clientPipe) + File "../../../../config/TestUtil.py", line 657, in printOutputFromPipe + c = pipe.read(1) +KeyboardInterrupt +2008-09-05 18:27:29.722 server[74756:2203] write Test::B +2008-09-05 18:27:29.724 server[74756:2203] write Test::A +2008-09-05 18:27:29.725 server[74756:2203] write Test::B +2008-09-05 18:27:29.725 server[74756:2203] write Test::A diff --git a/objective-c/test/Ice/operations/.gitignore b/objective-c/test/Ice/operations/.gitignore new file mode 100644 index 00000000000..0b3e86fe293 --- /dev/null +++ b/objective-c/test/Ice/operations/.gitignore @@ -0,0 +1,9 @@ +// Generated by makegitignore.py + +// IMPORTANT: Do not edit this file -- any edits made here will be lost! +client +server +collocated +.depend +OperationsTest.m +OperationsTest.h diff --git a/objective-c/test/Ice/operations/AllTests.m b/objective-c/test/Ice/operations/AllTests.m new file mode 100644 index 00000000000..5674a8bd4cb --- /dev/null +++ b/objective-c/test/Ice/operations/AllTests.m @@ -0,0 +1,58 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <TestCommon.h> +#import <OperationsTest.h> + +id<TestOperationsMyClassPrx> +operationsAllTests(id<ICECommunicator> communicator) +{ + NSString* ref = @"test:default -p 12010"; + id<ICEObjectPrx> base = [communicator stringToProxy:(ref)]; + id<TestOperationsMyClassPrx> cl = [TestOperationsMyClassPrx checkedCast:base]; + id<TestOperationsMyDerivedClassPrx> derived = [TestOperationsMyDerivedClassPrx checkedCast:cl]; + + tprintf("testing twoway operations... "); + void twoways(id<ICECommunicator>, id<TestOperationsMyClassPrx>); + twoways(communicator, cl); + twoways(communicator, derived); + [derived opDerived]; + tprintf("ok\n"); + + tprintf("testing oneway operations... "); + void oneways(id<ICECommunicator>, id<TestOperationsMyClassPrx>); + oneways(communicator, cl); + tprintf("ok\n"); + + tprintf("testing twoway operations with AMI... "); + void twowaysNewAMI(id<ICECommunicator>, id<TestOperationsMyClassPrx>); + twowaysNewAMI(communicator, cl); + twowaysNewAMI(communicator, derived); + tprintf("ok\n"); + + tprintf("testing oneway operations with AMI... "); + void onewaysNewAMI(id<ICECommunicator>, id<TestOperationsMyClassPrx>); + onewaysNewAMI(communicator, cl); + tprintf("ok\n"); + + tprintf("testing batch oneway operations... "); + void batchOneways(id<TestOperationsMyClassPrx>); + batchOneways(cl); + batchOneways(derived); + tprintf("ok\n"); + + tprintf("testing batch oneway operations with AMI... "); + void batchOnewaysAMI(id<TestOperationsMyClassPrx>); + batchOnewaysAMI(cl); + batchOnewaysAMI(derived); + tprintf("ok\n"); + + return cl; +} diff --git a/objective-c/test/Ice/operations/BatchOneways.m b/objective-c/test/Ice/operations/BatchOneways.m new file mode 100644 index 00000000000..13f1ae25195 --- /dev/null +++ b/objective-c/test/Ice/operations/BatchOneways.m @@ -0,0 +1,146 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <TestCommon.h> +#import <OperationsTest.h> + +#import <Foundation/Foundation.h> + +void +batchOneways(id<TestOperationsMyClassPrx> p) +{ + ICEByte buf1[10 * 1024]; + TestOperationsMutableByteS *bs1 = [TestOperationsMutableByteS dataWithBytes:buf1 length:sizeof(buf1)]; + + id<TestOperationsMyClassPrx> batch = [TestOperationsMyClassPrx uncheckedCast:[p ice_batchOneway]]; + + [batch ice_flushBatchRequests]; // Empty flush + + int i; + [p opByteSOnewayCallCount]; + for(i = 0 ; i < 30 ; ++i) + { + @try + { + [batch opByteSOneway:bs1]; + } + @catch(ICEMemoryLimitException*) + { + test(NO); + } + } + + int count = 0; + while(count < 27) // 3 * 9 requests auto-flushed. + { + count += [p opByteSOnewayCallCount]; + [NSThread sleepForTimeInterval:10 / 1000.0]; + } + + if([batch ice_getConnection]) + { + id<TestOperationsMyClassPrx> batch1 = [TestOperationsMyClassPrx uncheckedCast:[p ice_batchOneway]]; + id<TestOperationsMyClassPrx> batch2 = [TestOperationsMyClassPrx uncheckedCast:[p ice_batchOneway]]; + + [batch1 ice_ping]; + [batch2 ice_ping]; + [batch1 ice_flushBatchRequests]; + [[batch1 ice_getConnection] close:NO]; + [batch1 ice_ping]; + [batch2 ice_ping]; + + [batch1 ice_getConnection]; + [batch2 ice_getConnection]; + + [batch1 ice_ping]; + [[batch1 ice_getConnection] close:NO]; + [batch1 ice_ping]; + [batch2 ice_ping]; + } + + ICEIdentity *identity = [ICEIdentity identity:@"invalid" category:@""]; + id<ICEObjectPrx> batch3 = [batch ice_identity:identity]; + [batch3 ice_ping]; + [batch3 ice_flushBatchRequests]; + + // Make sure that a bogus batch request doesn't cause troubles to other ones. + [batch3 ice_ping]; + [batch ice_ping]; + [batch ice_flushBatchRequests]; + [batch ice_ping]; + + if([batch ice_getConnection]) + { + ICEInitializationData* initData = [ICEInitializationData initializationData]; + initData.properties = [[[p ice_getCommunicator] getProperties] clone]; + __block int _count = 0; + __block int _size = 0; + __block int _lastRequestSize = 0; + __block BOOL _enqueue = NO; + initData.batchRequestInterceptor = ^(id<ICEBatchRequest> request, int count, int size) + { + test([[request getOperation] isEqualToString:@"opByteSOneway"] || + [[request getOperation] isEqualToString:@"ice_ping"]); + test([[request getProxy] ice_isBatchOneway]); + + if(count > 0) + { + test(_lastRequestSize + _size == size); + } + _count = count; + _size = size; + + if(_size + [request getSize] > 25000) + { + [[request getProxy] begin_ice_flushBatchRequests]; + _size = 18; // header + } + + if(_enqueue) + { + _lastRequestSize = [request getSize]; + ++_count; + [request enqueue]; + } + }; + + id<ICECommunicator> ic = [ICEUtil createCommunicator:initData]; + + batch = [TestOperationsMyClassPrx uncheckedCast:[[ic stringToProxy:[p ice_toString]] ice_batchOneway]]; + + test(_count == 0); + [batch ice_ping]; + [batch ice_ping]; + [batch ice_ping]; + test(_count == 0); + + _enqueue = YES; + [batch ice_ping]; + [batch ice_ping]; + [batch ice_ping]; + test(_count == 3); + + [batch ice_flushBatchRequests]; + [batch ice_ping]; + test(_count == 1); + + [batch opByteSOneway:bs1]; + test(_count == 2); + [batch opByteSOneway:bs1]; + test(_count == 3); + + [batch opByteSOneway:bs1]; // This should trigger the flush + [batch ice_ping]; + test(_count == 2); + + [ic destroy]; + } + +} diff --git a/objective-c/test/Ice/operations/BatchOnewaysAMI.m b/objective-c/test/Ice/operations/BatchOnewaysAMI.m new file mode 100644 index 00000000000..347000b9d8c --- /dev/null +++ b/objective-c/test/Ice/operations/BatchOnewaysAMI.m @@ -0,0 +1,74 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <TestCommon.h> +#import <OperationsTest.h> + +#import <Foundation/Foundation.h> + +void +batchOnewaysAMI(id<TestOperationsMyClassPrx> p) +{ + ICEByte buf1[10 * 1024]; + TestOperationsMutableByteS *bs1 = [TestOperationsMutableByteS dataWithBytes:buf1 length:sizeof(buf1)]; + + id<TestOperationsMyClassPrx> batch = [TestOperationsMyClassPrx uncheckedCast:[p ice_batchOneway]]; + + [batch end_ice_flushBatchRequests:[batch begin_ice_flushBatchRequests]]; // Empty flush + [[batch begin_ice_flushBatchRequests] isCompleted]; // Empty flush + [[batch begin_ice_flushBatchRequests] isSent]; // Empty flush + [[batch begin_ice_flushBatchRequests] sentSynchronously]; // Empty flush + + int i; + [p opByteSOnewayCallCount]; + for(i = 0 ; i < 30 ; ++i) + { + [batch begin_opByteSOneway:bs1]; + } + + int count = 0; + while(count < 27) // 3 * 9 requests auto-flushed. + { + count += [p opByteSOnewayCallCount]; + [NSThread sleepForTimeInterval:10 / 1000.0]; + } + + if([batch ice_getConnection]) + { + id<TestOperationsMyClassPrx> batch1 = [TestOperationsMyClassPrx uncheckedCast:[p ice_batchOneway]]; + id<TestOperationsMyClassPrx> batch2 = [TestOperationsMyClassPrx uncheckedCast:[p ice_batchOneway]]; + + [batch1 end_ice_ping:[batch1 begin_ice_ping]]; + [batch2 end_ice_ping:[batch2 begin_ice_ping]]; + [batch1 end_ice_flushBatchRequests:[batch1 begin_ice_flushBatchRequests]]; + [[batch1 ice_getConnection] close:NO]; + [batch1 end_ice_ping:[batch1 begin_ice_ping]]; + [batch2 end_ice_ping:[batch2 begin_ice_ping]]; + + [batch1 ice_getConnection]; + [batch2 ice_getConnection]; + + [batch1 end_ice_ping:[batch1 begin_ice_ping]]; + [[batch1 ice_getConnection] close:NO]; + [batch1 end_ice_ping:[batch1 begin_ice_ping]]; + [batch2 end_ice_ping:[batch2 begin_ice_ping]]; + } + + ICEIdentity *identity = [ICEIdentity identity:@"invalid" category:@""]; + id<ICEObjectPrx> batch3 = [batch ice_identity:identity]; + [batch3 begin_ice_ping]; + [batch3 end_ice_flushBatchRequests:[batch3 begin_ice_flushBatchRequests]]; + + // Make sure that a bogus batch request doesn't cause troubles to other ones. + [batch3 begin_ice_ping]; + [batch begin_ice_ping]; + [batch end_ice_flushBatchRequests:[batch begin_ice_flushBatchRequests]]; + [batch begin_ice_ping]; +} diff --git a/objective-c/test/Ice/operations/Client.m b/objective-c/test/Ice/operations/Client.m new file mode 100644 index 00000000000..ea2e0e1dad9 --- /dev/null +++ b/objective-c/test/Ice/operations/Client.m @@ -0,0 +1,98 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <TestCommon.h> +#import <OperationsTest.h> + +static int +run(id<ICECommunicator> communicator) +{ + id<TestOperationsMyClassPrx> operationsAllTests(id<ICECommunicator>); + id<TestOperationsMyClassPrx> myClass = operationsAllTests(communicator); + tprintf("testing server shutdown... "); + [myClass shutdown]; + @try + { + [myClass opVoid]; + test(false); + } + @catch(ICELocalException*) + { + tprintf("ok\n"); + } + + return EXIT_SUCCESS; +} + +#if TARGET_OS_IPHONE +# define main operationsClient +#endif + +int +main(int argc, char* argv[]) +{ + int status; + @autoreleasepool + { + id<ICECommunicator> communicator = nil; + @try + { + + ICEInitializationData* initData = [ICEInitializationData initializationData]; + initData.properties = defaultClientProperties(&argc, argv); + // + // In this test, we need at least two threads in the + // client side thread pool for nested AMI. + // + [initData.properties setProperty:@"Ice.ThreadPool.Client.Size" value:@"2"]; + [initData.properties setProperty:@"Ice.ThreadPool.Client.SizeWarn" value:@"0"]; + + [initData.properties setProperty:@"Ice.BatchAutoFlushSize" value:@"100"]; + + // + // We must set MessageSizeMax to an explicit values, because + // we run tests to check whether Ice.MemoryLimitException is + // raised as expected. + // + [initData.properties setProperty:@"Ice.MessageSizeMax" value:@"100"]; + +#if TARGET_OS_IPHONE + initData.prefixTable__ = [NSDictionary dictionaryWithObjectsAndKeys: + @"TestOperations", @"::Test", + nil]; +#endif + communicator = [ICEUtil createCommunicator:&argc argv:argv initData:initData]; + status = run(communicator); + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + @catch(TestFailedException* ex) + { + status = EXIT_FAILURE; + } + + if(communicator) + { + @try + { + [communicator destroy]; + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + } + } + return status; +} diff --git a/objective-c/test/Ice/operations/Collocated.m b/objective-c/test/Ice/operations/Collocated.m new file mode 100644 index 00000000000..d1693cd21c9 --- /dev/null +++ b/objective-c/test/Ice/operations/Collocated.m @@ -0,0 +1,78 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <operations/TestI.h> +#import <TestCommon.h> + +static int +run(id<ICECommunicator> communicator) +{ + [[communicator getProperties] setProperty:@"TestOperationsAdapter.Endpoints" value:@"default -p 12010"]; + id<ICEObjectAdapter> adapter = [communicator createObjectAdapter:@"TestOperationsAdapter"]; + id<ICEObjectPrx> prx = [adapter add:[TestOperationsMyDerivedClassI myDerivedClass] + identity:[communicator stringToIdentity:@"test"]]; + //[adapter activate]; // Don't activate OA to ensure collocation is used. + + test(![prx ice_getConnection]); + + id<TestOperationsMyClassPrx> operationsAllTests(id<ICECommunicator>); + operationsAllTests(communicator); + + return EXIT_SUCCESS; +} + +#if TARGET_OS_IPHONE +# define main operationsCollocated +#endif + +int +main(int argc, char* argv[]) +{ + int status; + @autoreleasepool + { + id<ICECommunicator> communicator = nil; + + @try + { + ICEInitializationData* initData = [ICEInitializationData initializationData]; + initData.properties = defaultServerProperties(&argc, argv); + + [initData.properties setProperty:@"Ice.BatchAutoFlushSize" value:@"100"]; +#if TARGET_OS_IPHONE + initData.prefixTable__ = [NSDictionary dictionaryWithObjectsAndKeys: + @"TestOperations", @"::Test", + nil]; +#endif + communicator = [ICEUtil createCommunicator:&argc argv:argv initData:initData]; + status = run(communicator); + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + + if(communicator) + { + @try + { + [communicator destroy]; + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + } + } + + return status; +} diff --git a/objective-c/test/Ice/operations/Makefile b/objective-c/test/Ice/operations/Makefile new file mode 100644 index 00000000000..3bab9f10ded --- /dev/null +++ b/objective-c/test/Ice/operations/Makefile @@ -0,0 +1,61 @@ +# ********************************************************************** +# +# Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +# +# This copy of Ice is licensed to you under the terms described in the +# ICE_LICENSE file included in this distribution. +# +# ********************************************************************** + +top_srcdir = ../../.. + +CLIENT = client +SERVER = server +COLLOCATED = collocated + +TARGETS = $(CLIENT) $(SERVER) $(COLLOCATED) + +SLICE_OBJS = OperationsTest.o + +COBJS = Client.o \ + AllTests.o \ + Twoways.o \ + TwowaysNewAMI.o \ + Oneways.o \ + OnewaysNewAMI.o \ + BatchOneways.o \ + BatchOnewaysAMI.o + +SOBJS = TestI.o \ + Server.o + +COLOBJS = Collocated.o \ + TestI.o \ + AllTests.o \ + Twoways.o \ + TwowaysNewAMI.o \ + Oneways.o \ + OnewaysNewAMI.o \ + BatchOneways.o \ + BatchOnewaysAMI.o + +OBJS = $(COBJS) \ + $(SOBJS) \ + $(COLOBJS) \ + $(SLICE_OBJS) + +include $(top_srcdir)/config/Make.rules + +CPPFLAGS := -I. -I.. -I../../include $(CPPFLAGS) + +$(CLIENT): $(COBJS) $(SLICE_OBJS) + rm -f $@ + $(CXX) $(LDFLAGS) $(LDEXEFLAGS) -o $@ $(COBJS) $(SLICE_OBJS) $(TEST_LIBS) + +$(SERVER): $(SOBJS) $(SLICE_OBJS) + rm -f $@ + $(CXX) $(LDFLAGS) $(LDEXEFLAGS) -o $@ $(SOBJS) $(SLICE_OBJS) $(TEST_LIBS) + +$(COLLOCATED): $(COLOBJS) $(SLICE_OBJS) + rm -f $@ + $(CXX) $(LDFLAGS) $(LDEXEFLAGS) -o $@ $(COLOBJS) $(SLICE_OBJS) $(TEST_LIBS) diff --git a/objective-c/test/Ice/operations/Oneways.m b/objective-c/test/Ice/operations/Oneways.m new file mode 100644 index 00000000000..d8318f47597 --- /dev/null +++ b/objective-c/test/Ice/operations/Oneways.m @@ -0,0 +1,37 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <TestCommon.h> +#import <OperationsTest.h> + +void +oneways(id<ICECommunicator> communicator, id<TestOperationsMyClassPrx> proxy) +{ + id<TestOperationsMyClassPrx> p = [TestOperationsMyClassPrx uncheckedCast:[proxy ice_oneway]]; + + { + [p opVoid]; + } + + { + ICEByte b; + ICEByte r; + + @try + { + r = [p opByte:(ICEByte)0xff p2:(ICEByte)0x0f p3:&b]; + test(NO); + } + @catch(ICETwowayOnlyException*) + { + } + } + +} diff --git a/objective-c/test/Ice/operations/OnewaysNewAMI.m b/objective-c/test/Ice/operations/OnewaysNewAMI.m new file mode 100644 index 00000000000..43c04c88dac --- /dev/null +++ b/objective-c/test/Ice/operations/OnewaysNewAMI.m @@ -0,0 +1,121 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <TestCommon.h> +#import <OperationsTest.h> + +#import <Foundation/Foundation.h> + +@interface OnewayNewAMICallback : NSObject +{ + BOOL called; + NSCondition* cond; +} +-(void) check; +-(void) called; +@end + +@implementation OnewayNewAMICallback +-(id) init +{ + self = [super init]; + if(!self) + { + return nil; + } + cond = [[NSCondition alloc] init]; + return self; +} + ++(id) create +{ + return ICE_AUTORELEASE([[OnewayNewAMICallback alloc] init]); +} + +#if defined(__clang__) && !__has_feature(objc_arc) +-(void) dealloc +{ + [cond release]; + [super dealloc]; +} +#endif + +-(void) check +{ + [cond lock]; + while(!called) + { + [cond wait]; + } + called = NO; + [cond unlock]; +} +-(void) called +{ + [cond lock]; + called = YES; + [cond signal]; + [cond unlock]; +} +-(void) opVoidResponse +{ + [self called]; +} +-(void) opVoidException:(ICEException*)ex +{ + test(NO); +} +-(void) opVoidExResponse +{ + test(NO); +} +-(void) opVoidExException:(ICEException*)ex +{ + test([ex isKindOfClass:[ICENoEndpointException class]]); + [self called]; +} +-(void) opByteExResponse +{ + test(NO); +} +-(void) opByteEx:(ICEException*)ex +{ + test(NO); +} +-(void) opByteExException:(ICEException*)ex +{ + test([ex isKindOfClass:[ICETwowayOnlyException class]]); + [self called]; +} +@end + +void +onewaysNewAMI(id<ICECommunicator> communicator, id<TestOperationsMyClassPrx> proxy) +{ + id<TestOperationsMyClassPrx> p = [TestOperationsMyClassPrx uncheckedCast:[proxy ice_oneway]]; + + { + OnewayNewAMICallback* cb = [OnewayNewAMICallback create]; + [p begin_opVoid:^() { [cb opVoidResponse]; } exception:^(ICEException* ex) { [cb opVoidException:ex]; }]; + } + + { + OnewayNewAMICallback* cb = [OnewayNewAMICallback create]; + @try + { + [p begin_opByte:0 p2:0 response:^(ICEByte r, ICEByte p3) { [cb opByteExResponse]; } exception:^(ICEException* ex) { [cb opByteExException:ex]; }]; + [cb check]; + } + @catch(NSException* ex) + { + test([ex name] == NSInvalidArgumentException); + } + } +} diff --git a/objective-c/test/Ice/operations/OperationsTest.ice b/objective-c/test/Ice/operations/OperationsTest.ice new file mode 100644 index 00000000000..7f8a084184b --- /dev/null +++ b/objective-c/test/Ice/operations/OperationsTest.ice @@ -0,0 +1,289 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#pragma once + +#include <Ice/Current.ice> + +["objc:prefix:TestOperations"] +module Test +{ + +enum MyEnum +{ + enum1, + enum2, + enum3 +}; + +class MyClass; + +struct AnotherStruct +{ + string s; +}; + +struct Structure +{ + MyClass* p; + MyEnum e; + AnotherStruct s; +}; + +sequence<byte> ByteS; +sequence<bool> BoolS; +sequence<short> ShortS; +sequence<int> IntS; +sequence<long> LongS; +sequence<float> FloatS; +sequence<double> DoubleS; +sequence<string> StringS; +sequence<MyEnum> MyEnumS; +sequence<MyClass*> MyClassS; + +sequence<ByteS> ByteSS; +sequence<BoolS> BoolSS; +sequence<ShortS> ShortSS; +sequence<IntS> IntSS; +sequence<LongS> LongSS; +sequence<FloatS> FloatSS; +sequence<DoubleS> DoubleSS; +sequence<StringS> StringSS; +sequence<MyEnumS> MyEnumSS; +sequence<MyClassS> MyClassSS; + +sequence<StringSS> StringSSS; + +struct MyStruct +{ + int i; + int j; +}; + +dictionary<byte, bool> ByteBoolD; +dictionary<short, int> ShortIntD; +dictionary<long, float> LongFloatD; +dictionary<string, string> StringStringD; +dictionary<string, MyEnum> StringMyEnumD; +dictionary<MyEnum, string> MyEnumStringD; +dictionary<MyStruct, MyEnum> MyStructMyEnumD; + +sequence<ByteBoolD> ByteBoolDS; +sequence<ShortIntD> ShortIntDS; +sequence<LongFloatD> LongFloatDS; +sequence<StringStringD> StringStringDS; +sequence<StringMyEnumD> StringMyEnumDS; +sequence<MyEnumStringD> MyEnumStringDS; +sequence<MyStructMyEnumD> MyStructMyEnumDS; + +dictionary<byte, ByteS> ByteByteSD; +dictionary<bool, BoolS> BoolBoolSD; +dictionary<short, ShortS> ShortShortSD; +dictionary<int, IntS> IntIntSD; +dictionary<long, LongS> LongLongSD; +dictionary<string, FloatS> StringFloatSD; +dictionary<string, DoubleS> StringDoubleSD; +dictionary<string, StringS> StringStringSD; +dictionary<MyEnum, MyEnumS> MyEnumMyEnumSD; + +sequence<Structure> StructS; // Used by Objective-C test only. + +struct Struct2 // Ensures the generated code for this struct compiles +{ + bool b; + int i; + float f; + double d; + byte by; + short sh; + long l; + StructS ss; + ByteBoolD dict; + MyEnumSS seq; +}; + +class A // Used Objective-C test only. +{ + int i; +}; + +sequence<A> AS; // Used by Objective-C test only. + +class MyClass +{ + void shutdown(); + + void opVoid(); + + byte opByte(byte p1, byte p2, + out byte p3); + + bool opBool(bool p1, bool p2, + out bool p3); + + long opShortIntLong(short p1, int p2, long p3, + out short p4, out int p5, out long p6); + + double opFloatDouble(float p1, double p2, + out float p3, out double p4); + + string opString(string p1, string p2, + out string p3); + + MyEnum opMyEnum(MyEnum p1, out MyEnum p2); + + MyClass* opMyClass(MyClass* p1, out MyClass* p2, out MyClass* p3); + + Structure opStruct(Structure p1, Structure p2, + out Structure p3); + + ByteS opByteS(ByteS p1, ByteS p2, + out ByteS p3); + + BoolS opBoolS(BoolS p1, BoolS p2, + out BoolS p3); + + LongS opShortIntLongS(Test::ShortS p1, IntS p2, LongS p3, + out ::Test::ShortS p4, out IntS p5, out LongS p6); + + DoubleS opFloatDoubleS(FloatS p1, DoubleS p2, + out FloatS p3, out DoubleS p4); + + StringS opStringS(StringS p1, StringS p2, + out StringS p3); + + MyEnumS opMyEnumS(MyEnumS p1, MyEnumS p2, + out MyEnumS p3); + + MyClassS opMyClassS(MyClassS p1, MyClassS p2, + out MyClassS p3); + + ByteSS opByteSS(ByteSS p1, ByteSS p2, + out ByteSS p3); + + BoolSS opBoolSS(BoolSS p1, BoolSS p2, + out BoolSS p3); + + LongSS opShortIntLongSS(ShortSS p1, IntSS p2, LongSS p3, + out ShortSS p4, out IntSS p5, out LongSS p6); + + + DoubleSS opFloatDoubleSS(FloatSS p1, DoubleSS p2, + out FloatSS p3, out DoubleSS p4); + + StringSS opStringSS(StringSS p1, StringSS p2, + out StringSS p3); + + StringSSS opStringSSS(StringSSS p1, StringSSS p2, + out StringSSS p3); + + ByteBoolD opByteBoolD(ByteBoolD p1, ByteBoolD p2, + out ByteBoolD p3); + + ShortIntD opShortIntD(ShortIntD p1, ShortIntD p2, + out ShortIntD p3); + + LongFloatD opLongFloatD(LongFloatD p1, LongFloatD p2, + out LongFloatD p3); + + StringStringD opStringStringD(StringStringD p1, StringStringD p2, + out StringStringD p3); + + StringMyEnumD opStringMyEnumD(StringMyEnumD p1, StringMyEnumD p2, + out StringMyEnumD p3); + + MyEnumStringD opMyEnumStringD(MyEnumStringD p1, MyEnumStringD p2, + out MyEnumStringD p3); + + MyStructMyEnumD opMyStructMyEnumD(MyStructMyEnumD p1, MyStructMyEnumD p2, + out MyStructMyEnumD p3); + + ByteBoolDS opByteBoolDS(ByteBoolDS p1, ByteBoolDS p2, + out ByteBoolDS p3); + + ShortIntDS opShortIntDS(ShortIntDS p1, ShortIntDS p2, + out ShortIntDS p3); + + LongFloatDS opLongFloatDS(LongFloatDS p1, LongFloatDS p2, + out LongFloatDS p3); + + StringStringDS opStringStringDS(StringStringDS p1, StringStringDS p2, + out StringStringDS p3); + + StringMyEnumDS opStringMyEnumDS(StringMyEnumDS p1, StringMyEnumDS p2, + out StringMyEnumDS p3); + + MyEnumStringDS opMyEnumStringDS(MyEnumStringDS p1, MyEnumStringDS p2, + out MyEnumStringDS p3); + + MyStructMyEnumDS opMyStructMyEnumDS(MyStructMyEnumDS p1, MyStructMyEnumDS p2, + out MyStructMyEnumDS p3); + + ByteByteSD opByteByteSD(ByteByteSD p1, ByteByteSD p2, + out ByteByteSD p3); + + BoolBoolSD opBoolBoolSD(BoolBoolSD p1, BoolBoolSD p2, + out BoolBoolSD p3); + + ShortShortSD opShortShortSD(ShortShortSD p1, ShortShortSD p2, + out ShortShortSD p3); + + IntIntSD opIntIntSD(IntIntSD p1, IntIntSD p2, + out IntIntSD p3); + + LongLongSD opLongLongSD(LongLongSD p1, LongLongSD p2, + out LongLongSD p3); + + StringFloatSD opStringFloatSD(StringFloatSD p1, StringFloatSD p2, + out StringFloatSD p3); + + StringDoubleSD opStringDoubleSD(StringDoubleSD p1, StringDoubleSD p2, + out StringDoubleSD p3); + + StringStringSD opStringStringSD(StringStringSD p1, StringStringSD p2, + out StringStringSD p3); + + MyEnumMyEnumSD opMyEnumMyEnumSD(MyEnumMyEnumSD p1, MyEnumMyEnumSD p2, + out MyEnumMyEnumSD p3); + + IntS opIntS(IntS s); + + void opByteSOneway(ByteS s); + + int opByteSOnewayCallCount(); + + Ice::Context opContext(); + + void opDoubleMarshaling(double p1, DoubleS p2); + + idempotent void opIdempotent(); + + ["nonmutating"] idempotent void opNonmutating(); + + // + // Operations below are specific to Objective-C + // + + StringS getNSNullStringSeq(); + AS getNSNullASeq(); + StructS getNSNullStructSeq(); + StringSS getNSNullStringSeqSeq(); + + StringStringD getNSNullStringStringDict(); + void putNSNullStringStringDict(StringStringD d); + void putNSNullShortIntDict(ShortIntD d); + void putNSNullStringMyEnumDict(StringMyEnumD d); +}; + +class MyDerivedClass extends MyClass +{ + void opDerived(); +}; + +}; diff --git a/objective-c/test/Ice/operations/Server.m b/objective-c/test/Ice/operations/Server.m new file mode 100644 index 00000000000..e6aefe0a16d --- /dev/null +++ b/objective-c/test/Ice/operations/Server.m @@ -0,0 +1,81 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <operations/TestI.h> +#import <TestCommon.h> + +static int +run(id<ICECommunicator> communicator) +{ + [[communicator getProperties] setProperty:@"TestOperationsAdapter.Endpoints" value:@"default -p 12010:udp"]; + id<ICEObjectAdapter> adapter = [communicator createObjectAdapter:@"TestOperationsAdapter"]; + [adapter add:[TestOperationsMyDerivedClassI myDerivedClass] + identity:[communicator stringToIdentity:@"test"]]; + [adapter activate]; + + serverReady(communicator); + + [communicator waitForShutdown]; + return EXIT_SUCCESS; +} + +#if TARGET_OS_IPHONE +# define main operationsServer +#endif + +int +main(int argc, char* argv[]) +{ + int status; + @autoreleasepool + { + id<ICECommunicator> communicator = nil; + + @try + { + ICEInitializationData* initData = [ICEInitializationData initializationData]; + initData.properties = defaultServerProperties(&argc, argv); + + // + // Its possible to have batch oneway requests dispatched after + // the adapter is deactivated due to thread scheduling so we + // supress this warning. + // + [initData.properties setProperty:@"Ice.Warn.Dispatch" value:@"0"]; +#if TARGET_OS_IPHONE + initData.prefixTable__ = [NSDictionary dictionaryWithObjectsAndKeys: + @"TestOperations", @"::Test", + nil]; +#endif + communicator = [ICEUtil createCommunicator:&argc argv:argv initData:initData]; + status = run(communicator); + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + + if(communicator) + { + @try + { + [communicator destroy]; + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + } + } + + return status; +} diff --git a/objective-c/test/Ice/operations/TestI.h b/objective-c/test/Ice/operations/TestI.h new file mode 100644 index 00000000000..faa1c8634dd --- /dev/null +++ b/objective-c/test/Ice/operations/TestI.h @@ -0,0 +1,21 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <OperationsTest.h> +#import <Foundation/Foundation.h> + +// +// Servant implementation +// +@interface TestOperationsMyDerivedClassI : TestOperationsMyDerivedClass<TestOperationsMyDerivedClass> +{ + int _opByteSOnewayCallCount; + NSCondition* _cond; +} +@end diff --git a/objective-c/test/Ice/operations/TestI.m b/objective-c/test/Ice/operations/TestI.m new file mode 100644 index 00000000000..e04a68e8c37 --- /dev/null +++ b/objective-c/test/Ice/operations/TestI.m @@ -0,0 +1,715 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> + +#import <operations/TestI.h> +#import <TestCommon.h> + +@implementation TestOperationsMyDerivedClassI +-(id) init +{ + self = [super init]; + if(!self) + { + return nil; + } + _opByteSOnewayCallCount = 0; + _cond = [[NSCondition alloc] init]; + return self; +} + +#if defined(__clang__) && !__has_feature(objc_arc) +-(void) dealloc +{ + [_cond release]; + [super dealloc]; +} +#endif + +-(void) opVoid:(ICECurrent*)current +{ +} + +-(void) opDerived:(ICECurrent*)current +{ +} + +-(ICEByte) opByte:(ICEByte)p1 p2:(ICEByte)p2 p3:(ICEByte *)p3 current:(ICECurrent *)current +{ + *p3 = p1 ^ p2; + return p1; +} + +-(BOOL) opBool:(BOOL)p1 p2:(BOOL)p2 p3:(BOOL *)p3 current:(ICECurrent*)current +{ + *p3 = p1; + return p2; +} + +-(ICELong) opShortIntLong:(ICEShort)p1 p2:(ICEInt)p2 p3:(ICELong)p3 + p4:(ICEShort *)p4 p5:(ICEInt *)p5 p6:(ICELong *)p6 + current:(ICECurrent *)current +{ + *p4 = p1; + *p5 = p2; + *p6 = p3; + return p3; +} + +-(ICEDouble) opFloatDouble:(ICEFloat)p1 p2:(ICEDouble)p2 p3:(ICEFloat *)p3 p4:(ICEDouble *)p4 + current:(ICECurrent *)current +{ + *p3 = p1; + *p4 = p2; + return p2; +} + +-(NSString *) opString:(NSMutableString *)p1 p2:(NSMutableString *)p2 p3:(NSString **)p3 current:(ICECurrent *)current +{ + NSMutableString *sout = [NSMutableString stringWithCapacity:([p2 length] + 1 + [p1 length])]; + [sout appendString:p2]; + [sout appendString:@" "]; + [sout appendString:p1]; + *p3 = sout; + + NSMutableString *ret = [NSMutableString stringWithCapacity:([p1 length] + 1 + [p2 length])]; + [ret appendString:p1]; + [ret appendString:@" "]; + [ret appendString:p2]; + return ret; +} + +-(TestOperationsMyEnum) opMyEnum:(TestOperationsMyEnum)p1 p2:(TestOperationsMyEnum *)p2 current:(ICECurrent *)current +{ + *p2 = p1; + return TestOperationsenum3; +} + +-(id<TestOperationsMyClassPrx>) opMyClass:(id<TestOperationsMyClassPrx>)p1 p2:(id<TestOperationsMyClassPrx> *)p2 p3:(id<TestOperationsMyClassPrx> *)p3 + current:(ICECurrent *)current +{ + *p2 = p1; + *p3 = [TestOperationsMyClassPrx uncheckedCast:[current.adapter + createProxy:[[current.adapter getCommunicator] + stringToIdentity:@"noSuchIdentity"]]]; + return [TestOperationsMyClassPrx uncheckedCast:[current.adapter createProxy:[current id_]]]; +} + +-(TestOperationsStructure *) opStruct:(TestOperationsStructure *)p1 p2:(TestOperationsStructure *)p2 p3:(TestOperationsStructure **)p3 + current:(ICECurrent *)current; +{ + *p3 = ICE_AUTORELEASE([p1 copy]); + (*p3).s.s = @"a new string"; + return p2; +} + +-(TestOperationsByteS *) opByteS:(TestOperationsMutableByteS *)p1 p2:(TestOperationsMutableByteS *)p2 p3:(TestOperationsByteS **)p3 + current:(ICECurrent *)current +{ + *p3 = [TestOperationsMutableByteS dataWithLength:[p1 length]]; + ICEByte *target = (ICEByte *)[*p3 bytes]; + ICEByte *src = (ICEByte *)[p1 bytes] + [p1 length]; + int i; + for(i = 0; i != [p1 length]; ++i) + { + *target++ = *--src; + } + TestOperationsMutableByteS *r = [TestOperationsMutableByteS dataWithData:p1]; + [r appendData:p2]; + return r; +} + +-(TestOperationsBoolS *) opBoolS:(TestOperationsMutableBoolS *)p1 p2:(TestOperationsMutableBoolS *)p2 p3:(TestOperationsBoolS **)p3 + current:(ICECurrent *)current +{ + *p3 = [TestOperationsMutableBoolS dataWithData:p1]; + [(TestOperationsMutableBoolS *)*p3 appendData:p2]; + + TestOperationsMutableBoolS *r = [TestOperationsMutableBoolS dataWithLength:[p1 length] * sizeof(BOOL)]; + BOOL *target = (BOOL *)[r bytes]; + BOOL *src = (BOOL *)([p1 bytes] + [p1 length]); + int i; + for(i = 0; i != [p1 length]; ++i) + { + *target++ = *--src; + } + return r; +} + +-(TestOperationsLongS *) opShortIntLongS:(TestOperationsMutableShortS *)p1 p2:(TestOperationsMutableIntS *)p2 p3:(TestOperationsMutableLongS *)p3 + p4:(TestOperationsShortS **)p4 p5:(TestOperationsIntS **)p5 p6:(TestOperationsLongS **)p6 + current:(ICECurrent *)current +{ + *p4 = [TestOperationsMutableShortS dataWithData:p1]; + *p5 = [TestOperationsMutableIntS dataWithLength:[p2 length]]; + ICEInt *target = (ICEInt *)[*p5 bytes]; + ICEInt *src = (ICEInt *)([p2 bytes] + [p2 length]); + int i; + for(i = 0; i != [p2 length] / sizeof(ICEInt); ++i) + { + *target++ = *--src; + } + *p6 = [TestOperationsMutableLongS dataWithData:p3]; + [(TestOperationsMutableLongS *)*p6 appendData:p3]; + return p3; +} + +-(TestOperationsDoubleS *) opFloatDoubleS:(TestOperationsMutableFloatS *)p1 p2:(TestOperationsMutableDoubleS *)p2 + p3:(TestOperationsFloatS **)p3 p4:(TestOperationsDoubleS **)p4 current:(ICECurrent *)current +{ + *p3 = [TestOperationsMutableFloatS dataWithData:p1]; + *p4 = [TestOperationsMutableDoubleS dataWithLength:[p2 length]]; + ICEDouble *target = (ICEDouble *)[*p4 bytes]; + ICEDouble *src = (ICEDouble *)([p2 bytes] + [p2 length]); + int i; + for(i = 0; i != [p2 length] / sizeof(ICEDouble); ++i) + { + *target++ = *--src; + } + TestOperationsDoubleS *r = [TestOperationsMutableDoubleS dataWithLength:([p2 length] + + ([p1 length] / sizeof(ICEFloat) * sizeof(ICEDouble)))]; + ICEDouble *rp = (ICEDouble *)[r bytes]; + ICEDouble *p2p = (ICEDouble *)[p2 bytes]; + for(i = 0; i < [p2 length] / sizeof(ICEDouble); ++i) + { + *rp++ = *p2p++; + } + ICEFloat *bp1 = (ICEFloat *)[p1 bytes]; + for(i = 0; i < [p1 length] / sizeof(ICEFloat); ++i) + { + *rp++ = bp1[i]; + } + return r; +} + +-(TestOperationsStringS *) opStringS:(TestOperationsMutableStringS *)p1 p2:(TestOperationsMutableStringS *)p2 + p3:(TestOperationsStringS **)p3 current:(ICECurrent *)current +{ + *p3 = [TestOperationsMutableStringS arrayWithArray:p1]; + [(TestOperationsMutableStringS *)*p3 addObjectsFromArray:p2]; + TestOperationsMutableStringS *r = [TestOperationsMutableStringS arrayWithCapacity:[p1 count]]; + NSEnumerator *enumerator = [p1 reverseObjectEnumerator]; + for(NSString *element in enumerator) + { + [r addObject:element]; + } + return r; +} + +-(TestOperationsMyEnumS *) opMyEnumS:(TestOperationsMutableMyEnumS *)p1 p2:(TestOperationsMutableMyEnumS *)p2 + p3:(TestOperationsMyEnumS **)p3 current:(ICECurrent *)current +{ + *p3 = [TestOperationsMutableMyEnumS dataWithLength:[p1 length]]; + TestOperationsMyEnum *target = (TestOperationsMyEnum *)[*p3 bytes]; + TestOperationsMyEnum *src = (TestOperationsMyEnum *)([p1 bytes] + [p1 length]); + int i; + for(i = 0; i != [p1 length] / sizeof(TestOperationsMyEnum); ++i) + { + *target++ = *--src; + } + TestOperationsMutableMyEnumS *r = [TestOperationsMutableMyEnumS dataWithData:p1]; + [r appendData:p2]; + return r; +} + +-(TestOperationsMyClassS *) opMyClassS:(TestOperationsMutableMyClassS *)p1 p2:(TestOperationsMutableMyClassS *)p2 + p3:(TestOperationsMyClassS **)p3 current:(ICECurrent *)current +{ + *p3 = [TestOperationsMutableMyClassS arrayWithArray:p1]; + [(TestOperationsMutableMyClassS *)*p3 addObjectsFromArray:p2]; + TestOperationsMutableMyClassS *r = [TestOperationsMutableMyClassS arrayWithCapacity:[p1 count]]; + NSEnumerator *enumerator = [p1 reverseObjectEnumerator]; + for(NSString *element in enumerator) + { + [r addObject:element]; + } + return r; +} + +-(TestOperationsByteSS *) opByteSS:(TestOperationsMutableByteSS *)p1 p2:(TestOperationsMutableByteSS *)p2 p3:(TestOperationsByteSS * *)p3 + current:(ICECurrent *)current +{ + *p3 = [TestOperationsMutableByteSS array]; + NSEnumerator *enumerator = [p1 reverseObjectEnumerator]; + for(TestOperationsByteS *element in enumerator) + { + [(TestOperationsMutableByteSS *)*p3 addObject:element]; + } + + TestOperationsMutableByteSS *r = [TestOperationsMutableByteSS arrayWithArray:p1]; + [r addObjectsFromArray:p2]; + return r; +} + +-(TestOperationsBoolSS *) opBoolSS:(TestOperationsMutableBoolSS *)p1 p2:(TestOperationsMutableBoolSS *)p2 p3:(TestOperationsBoolSS * *)p3 + current:(ICECurrent *)current +{ + *p3 = [TestOperationsMutableBoolSS arrayWithArray:p1]; + [(TestOperationsMutableBoolSS *)*p3 addObjectsFromArray:p2]; + + TestOperationsMutableBoolSS *r = [TestOperationsMutableBoolSS array]; + NSEnumerator *enumerator = [p1 reverseObjectEnumerator]; + for(TestOperationsBoolS *element in enumerator) + { + [r addObject:element]; + } + return r; +} + +-(TestOperationsLongSS *) opShortIntLongSS:(TestOperationsMutableShortSS *)p1 p2:(TestOperationsMutableIntSS *)p2 p3:(TestOperationsMutableLongSS *)p3 + p4:(TestOperationsShortSS **)p4 p5:(TestOperationsIntSS **)p5 p6:(TestOperationsLongSS **)p6 + current:(ICECurrent *)current +{ + *p4 = [TestOperationsShortSS arrayWithArray:p1]; + *p5 = [TestOperationsMutableIntSS array]; + NSEnumerator *enumerator = [p2 reverseObjectEnumerator]; + for(TestOperationsIntS *element in enumerator) + { + [(TestOperationsMutableIntSS *)*p5 addObject:element]; + } + *p6 = [TestOperationsMutableLongSS arrayWithArray:p3]; + [(TestOperationsMutableLongSS *)*p6 addObjectsFromArray:p3]; + return p3; +} + +-(TestOperationsDoubleSS *) opFloatDoubleSS:(TestOperationsMutableFloatSS *)p1 p2:(TestOperationsMutableDoubleSS *)p2 + p3:(TestOperationsFloatSS **)p3 p4:(TestOperationsDoubleSS **)p4 current:(ICECurrent *)current +{ + *p3 = [TestOperationsFloatSS arrayWithArray:p1]; + *p4 = [TestOperationsMutableDoubleSS array]; + NSEnumerator *enumerator = [p2 reverseObjectEnumerator]; + for(TestOperationsDoubleS *element in enumerator) + { + [(TestOperationsMutableDoubleSS *)*p4 addObject:element]; + } + TestOperationsMutableDoubleSS *r = [TestOperationsMutableDoubleSS arrayWithArray:p2]; + [r addObjectsFromArray:p2]; + return r; +} + +-(TestOperationsStringSS *) opStringSS:(TestOperationsMutableStringSS *)p1 p2:(TestOperationsMutableStringSS *)p2 p3:(TestOperationsStringSS **)p3 + current:(ICECurrent *)current +{ + *p3 = [TestOperationsMutableStringSS arrayWithArray:p1]; + [(TestOperationsMutableStringSS *)*p3 addObjectsFromArray:p2]; + TestOperationsMutableStringSS *r = [TestOperationsMutableStringSS array]; + NSEnumerator *enumerator = [p2 reverseObjectEnumerator]; + for(TestOperationsStringS *element in enumerator) + { + [r addObject:element]; + } + return r; +} + +-(TestOperationsStringSSS *) opStringSSS:(TestOperationsMutableStringSSS *)p1 p2:(TestOperationsMutableStringSSS *)p2 p3:(TestOperationsStringSSS **)p3 + current:(ICECurrent *)current +{ + *p3 = [TestOperationsMutableStringSSS arrayWithArray:p1]; + [(TestOperationsMutableStringSSS *)*p3 addObjectsFromArray:p2]; + TestOperationsMutableStringSSS *r = [TestOperationsMutableStringSSS array]; + NSEnumerator *enumerator = [p2 reverseObjectEnumerator]; + for(TestOperationsStringSS *element in enumerator) + { + [r addObject:element]; + } + return r; +} + +-(TestOperationsByteBoolD *) opByteBoolD:(TestOperationsMutableByteBoolD *)p1 p2:(TestOperationsMutableByteBoolD *)p2 p3:(TestOperationsByteBoolD **)p3 + current:(ICECurrent *)current +{ + *p3 = [TestOperationsMutableByteBoolD dictionaryWithDictionary:p1]; + TestOperationsMutableByteBoolD *r = [TestOperationsMutableByteBoolD dictionaryWithDictionary:p1]; + [r addEntriesFromDictionary:p2]; + return r; +} + +-(TestOperationsShortIntD *) opShortIntD:(TestOperationsMutableShortIntD *)p1 p2:(TestOperationsMutableShortIntD *)p2 p3:(TestOperationsShortIntD **)p3 + current:(ICECurrent *)current +{ + *p3 = [TestOperationsMutableShortIntD dictionaryWithDictionary:p1]; + TestOperationsMutableShortIntD *r = [TestOperationsMutableShortIntD dictionaryWithDictionary:p1]; + [r addEntriesFromDictionary:p2]; + return r; +} + +-(TestOperationsLongFloatD *) opLongFloatD:(TestOperationsMutableLongFloatD *)p1 p2:(TestOperationsMutableLongFloatD *)p2 p3:(TestOperationsLongFloatD **)p3 + current:(ICECurrent *)current +{ + *p3 = [TestOperationsMutableLongFloatD dictionaryWithDictionary:p1]; + TestOperationsMutableLongFloatD *r = [TestOperationsMutableLongFloatD dictionaryWithDictionary:p1]; + [r addEntriesFromDictionary:p2]; + return r; +} + +-(TestOperationsStringStringD *) opStringStringD:(TestOperationsMutableStringStringD *)p1 p2:(TestOperationsMutableStringStringD *)p2 + p3:(TestOperationsStringStringD **)p3 current:(ICECurrent *)current +{ + *p3 = [TestOperationsMutableStringStringD dictionaryWithDictionary:p1]; + TestOperationsMutableStringStringD *r = [TestOperationsMutableStringStringD dictionaryWithDictionary:p1]; + [r addEntriesFromDictionary:p2]; + return r; +} + +-(TestOperationsStringMyEnumD *) opStringMyEnumD:(TestOperationsMutableStringMyEnumD *)p1 + p2:(TestOperationsMutableStringMyEnumD *)p2 + p3:(TestOperationsStringMyEnumD **)p3 current:(ICECurrent *)current +{ + *p3 = [TestOperationsMutableStringMyEnumD dictionaryWithDictionary:p1]; + TestOperationsMutableStringMyEnumD *r = [TestOperationsMutableStringMyEnumD dictionaryWithDictionary:p1]; + [r addEntriesFromDictionary:p2]; + return r; +} + +-(TestOperationsMyEnumStringD *) opMyEnumStringD:(TestOperationsMyEnumStringD*)p1 + p2:(TestOperationsMyEnumStringD*)p2 + p3:(TestOperationsMyEnumStringD**)p3 + current:(ICECurrent*)current +{ + *p3 = [TestOperationsMutableMyEnumStringD dictionaryWithDictionary:p1]; + TestOperationsMutableMyEnumStringD *r = [TestOperationsMutableMyEnumStringD dictionaryWithDictionary:p1]; + [r addEntriesFromDictionary:p2]; + return r; +} + +-(TestOperationsMyStructMyEnumD *) opMyStructMyEnumD:(TestOperationsMyStructMyEnumD*)p1 + p2:(TestOperationsMyStructMyEnumD*)p2 + p3:(TestOperationsMyStructMyEnumD**)p3 + current:(ICECurrent*)current +{ + *p3 = [TestOperationsMutableMyStructMyEnumD dictionaryWithDictionary:p1]; + TestOperationsMutableMyStructMyEnumD *r = [TestOperationsMutableMyStructMyEnumD dictionaryWithDictionary:p1]; + [r addEntriesFromDictionary:p2]; + return r; +} + +-(TestOperationsByteBoolDS*) opByteBoolDS:(TestOperationsMutableByteBoolDS*)p1 + p2:(TestOperationsMutableByteBoolDS*)p2 + p3:(TestOperationsByteBoolDS**)p3 + current:(ICECurrent *)current +{ + *p3 = [TestOperationsMutableByteBoolDS arrayWithArray:p2]; + [(TestOperationsMutableByteBoolDS *)*p3 addObjectsFromArray:p1]; + TestOperationsMutableByteBoolDS *r = [TestOperationsMutableByteBoolDS array]; + NSEnumerator *enumerator = [p1 reverseObjectEnumerator]; + for(TestOperationsByteBoolDS *element in enumerator) + { + [r addObject:element]; + } + return r; +} + +-(TestOperationsShortIntDS*) opShortIntDS:(TestOperationsMutableShortIntDS*)p1 + p2:(TestOperationsMutableShortIntDS*)p2 + p3:(TestOperationsShortIntDS**)p3 + current:(ICECurrent *)current +{ + *p3 = [TestOperationsMutableShortIntDS arrayWithArray:p2]; + [(TestOperationsMutableShortIntDS *)*p3 addObjectsFromArray:p1]; + TestOperationsMutableShortIntDS *r = [TestOperationsMutableShortIntDS array]; + NSEnumerator *enumerator = [p1 reverseObjectEnumerator]; + for(TestOperationsShortIntDS *element in enumerator) + { + [r addObject:element]; + } + return r; +} + +-(TestOperationsLongFloatDS*) opLongFloatDS:(TestOperationsMutableLongFloatDS*)p1 + p2:(TestOperationsMutableLongFloatDS*)p2 + p3:(TestOperationsLongFloatDS**)p3 + current:(ICECurrent *)current +{ + *p3 = [TestOperationsMutableLongFloatDS arrayWithArray:p2]; + [(TestOperationsMutableLongFloatDS *)*p3 addObjectsFromArray:p1]; + TestOperationsMutableLongFloatDS *r = [TestOperationsMutableLongFloatDS array]; + NSEnumerator *enumerator = [p1 reverseObjectEnumerator]; + for(TestOperationsLongFloatDS *element in enumerator) + { + [r addObject:element]; + } + return r; +} + +-(TestOperationsStringStringDS*) opStringStringDS:(TestOperationsMutableStringStringDS*)p1 + p2:(TestOperationsMutableStringStringDS*)p2 + p3:(TestOperationsStringStringDS**)p3 + current:(ICECurrent *)current +{ + *p3 = [TestOperationsMutableStringStringDS arrayWithArray:p2]; + [(TestOperationsMutableStringStringDS *)*p3 addObjectsFromArray:p1]; + TestOperationsMutableStringStringDS *r = [TestOperationsMutableStringStringDS array]; + NSEnumerator *enumerator = [p1 reverseObjectEnumerator]; + for(TestOperationsStringStringDS *element in enumerator) + { + [r addObject:element]; + } + return r; +} + +-(TestOperationsStringMyEnumDS*) opStringMyEnumDS:(TestOperationsMutableStringMyEnumDS*)p1 + p2:(TestOperationsMutableStringMyEnumDS*)p2 + p3:(TestOperationsStringMyEnumDS**)p3 + current:(ICECurrent *)current +{ + *p3 = [TestOperationsMutableStringMyEnumDS arrayWithArray:p2]; + [(TestOperationsMutableStringMyEnumDS *)*p3 addObjectsFromArray:p1]; + TestOperationsMutableStringMyEnumDS *r = [TestOperationsMutableStringMyEnumDS array]; + NSEnumerator *enumerator = [p1 reverseObjectEnumerator]; + for(TestOperationsStringMyEnumDS *element in enumerator) + { + [r addObject:element]; + } + return r; +} + +-(TestOperationsMyEnumStringDS*) opMyEnumStringDS:(TestOperationsMutableMyEnumStringDS*)p1 + p2:(TestOperationsMutableMyEnumStringDS*)p2 + p3:(TestOperationsMyEnumStringDS**)p3 + current:(ICECurrent *)current +{ + *p3 = [TestOperationsMutableMyEnumStringDS arrayWithArray:p2]; + [(TestOperationsMutableMyEnumStringDS *)*p3 addObjectsFromArray:p1]; + TestOperationsMutableMyEnumStringDS *r = [TestOperationsMutableMyEnumStringDS array]; + NSEnumerator *enumerator = [p1 reverseObjectEnumerator]; + for(TestOperationsMyEnumStringDS *element in enumerator) + { + [r addObject:element]; + } + return r; +} + +-(TestOperationsMyStructMyEnumDS*) opMyStructMyEnumDS:(TestOperationsMutableMyStructMyEnumDS*)p1 + p2:(TestOperationsMutableMyStructMyEnumDS*)p2 + p3:(TestOperationsMyStructMyEnumDS**)p3 + current:(ICECurrent *)current +{ + *p3 = [TestOperationsMutableMyStructMyEnumDS arrayWithArray:p2]; + [(TestOperationsMutableMyStructMyEnumDS *)*p3 addObjectsFromArray:p1]; + TestOperationsMutableMyStructMyEnumDS *r = [TestOperationsMutableMyStructMyEnumDS array]; + NSEnumerator *enumerator = [p1 reverseObjectEnumerator]; + for(TestOperationsMyStructMyEnumDS *element in enumerator) + { + [r addObject:element]; + } + return r; +} + +-(TestOperationsByteByteSD*) opByteByteSD:(TestOperationsMutableByteByteSD*)p1 + p2:(TestOperationsMutableByteByteSD*)p2 + p3:(TestOperationsByteByteSD**)p3 + current:(ICECurrent *)current +{ + *p3 = [TestOperationsMutableByteByteSD dictionaryWithDictionary:p2]; + TestOperationsMutableByteByteSD *r = [TestOperationsMutableByteByteSD dictionaryWithDictionary:p1]; + [r addEntriesFromDictionary:p2]; + return r; +} + +-(TestOperationsBoolBoolSD*) opBoolBoolSD:(TestOperationsMutableBoolBoolSD*)p1 + p2:(TestOperationsMutableBoolBoolSD*)p2 + p3:(TestOperationsBoolBoolSD**)p3 + current:(ICECurrent *)current +{ + *p3 = [TestOperationsMutableBoolBoolSD dictionaryWithDictionary:p2]; + TestOperationsMutableBoolBoolSD *r = [TestOperationsMutableBoolBoolSD dictionaryWithDictionary:p1]; + [r addEntriesFromDictionary:p2]; + return r; +} + +-(TestOperationsShortShortSD*) opShortShortSD:(TestOperationsMutableShortShortSD*)p1 + p2:(TestOperationsMutableShortShortSD*)p2 + p3:(TestOperationsShortShortSD**)p3 + current:(ICECurrent *)current +{ + *p3 = [TestOperationsMutableShortShortSD dictionaryWithDictionary:p2]; + TestOperationsMutableShortShortSD *r = [TestOperationsMutableShortShortSD dictionaryWithDictionary:p1]; + [r addEntriesFromDictionary:p2]; + return r; +} + +-(TestOperationsIntIntSD*) opIntIntSD:(TestOperationsMutableIntIntSD*)p1 + p2:(TestOperationsMutableIntIntSD*)p2 + p3:(TestOperationsIntIntSD**)p3 + current:(ICECurrent *)current +{ + *p3 = [TestOperationsMutableIntIntSD dictionaryWithDictionary:p2]; + TestOperationsMutableIntIntSD *r = [TestOperationsMutableIntIntSD dictionaryWithDictionary:p1]; + [r addEntriesFromDictionary:p2]; + return r; +} + +-(TestOperationsLongLongSD*) opLongLongSD:(TestOperationsMutableLongLongSD*)p1 + p2:(TestOperationsMutableLongLongSD*)p2 + p3:(TestOperationsLongLongSD**)p3 + current:(ICECurrent *)current +{ + *p3 = [TestOperationsMutableLongLongSD dictionaryWithDictionary:p2]; + TestOperationsMutableLongLongSD *r = [TestOperationsMutableLongLongSD dictionaryWithDictionary:p1]; + [r addEntriesFromDictionary:p2]; + return r; +} + +-(TestOperationsStringFloatSD*) opStringFloatSD:(TestOperationsMutableStringFloatSD*)p1 + p2:(TestOperationsMutableStringFloatSD*)p2 + p3:(TestOperationsStringFloatSD**)p3 + current:(ICECurrent *)current +{ + *p3 = [TestOperationsMutableStringFloatSD dictionaryWithDictionary:p2]; + TestOperationsMutableStringFloatSD *r = [TestOperationsMutableStringFloatSD dictionaryWithDictionary:p1]; + [r addEntriesFromDictionary:p2]; + return r; +} + +-(TestOperationsStringDoubleSD*) opStringDoubleSD:(TestOperationsMutableStringDoubleSD*)p1 + p2:(TestOperationsMutableStringDoubleSD*)p2 + p3:(TestOperationsStringDoubleSD**)p3 + current:(ICECurrent *)current +{ + *p3 = [TestOperationsMutableStringDoubleSD dictionaryWithDictionary:p2]; + TestOperationsMutableStringDoubleSD *r = [TestOperationsMutableStringDoubleSD dictionaryWithDictionary:p1]; + [r addEntriesFromDictionary:p2]; + return r; +} + +-(TestOperationsStringStringSD*) opStringStringSD:(TestOperationsMutableStringStringSD*)p1 + p2:(TestOperationsMutableStringStringSD*)p2 + p3:(TestOperationsStringStringSD**)p3 + current:(ICECurrent *)current +{ + *p3 = [TestOperationsMutableStringStringSD dictionaryWithDictionary:p2]; + TestOperationsMutableStringStringSD *r = [TestOperationsMutableStringStringSD dictionaryWithDictionary:p1]; + [r addEntriesFromDictionary:p2]; + return r; +} + +-(TestOperationsMyEnumMyEnumSD*) opMyEnumMyEnumSD:(TestOperationsMutableMyEnumMyEnumSD*)p1 + p2:(TestOperationsMutableMyEnumMyEnumSD*)p2 + p3:(TestOperationsMyEnumMyEnumSD**)p3 + current:(ICECurrent *)current +{ + *p3 = [TestOperationsMutableMyEnumMyEnumSD dictionaryWithDictionary:p2]; + TestOperationsMutableMyEnumMyEnumSD *r = [TestOperationsMutableMyEnumMyEnumSD dictionaryWithDictionary:p1]; + [r addEntriesFromDictionary:p2]; + return r; +} + +-(TestOperationsIntS *) opIntS:(TestOperationsMutableIntS *)p1 current:(ICECurrent *)current +{ + NSUInteger count = [p1 length] / sizeof(ICEInt); + TestOperationsMutableIntS *r = [TestOperationsMutableIntS dataWithLength:[p1 length]]; + const int *src = [p1 bytes]; + int *target = (int *)[r bytes]; + while(count-- > 0) + { + *target++ = -*src++; + } + return r; +} + +-(void) opByteSOneway:(TestOperationsMutableByteS *)p1 current:(ICECurrent *)current +{ + [_cond lock]; + ++_opByteSOnewayCallCount; + [_cond unlock]; +} + +-(ICEInt) opByteSOnewayCallCount:(ICECurrent *)current +{ + [_cond lock]; + ICEInt count = _opByteSOnewayCallCount; + _opByteSOnewayCallCount = 0; + @try + { + return count; + } + @finally + { + [_cond unlock]; + } +} + +-(ICEContext *) opContext:(ICECurrent *)current +{ + return current.ctx; +} + +-(void) opDoubleMarshaling:(ICEDouble)p1 p2:(TestOperationsMutableDoubleS *)p2 current:(ICECurrent *)current +{ + ICEDouble d = 1278312346.0 / 13.0; + test(p1 == d); + const ICEDouble *p = [p2 bytes]; + int i; + for(i = 0; i < [p2 length] / sizeof(ICEDouble); ++i) + { + test(p[i] == d); + } +} + +-(void) opIdempotent:(ICECurrent*)current +{ + test([current mode] == ICEIdempotent); +} + +-(void) opNonmutating:(ICECurrent*)current +{ + test([current mode] == ICENonmutating); +} + +-(TestOperationsStringS *) getNSNullStringSeq:(ICECurrent *)current +{ + return [NSArray arrayWithObjects:@"first", [NSNull null], nil]; +} + +-(TestOperationsMyClassS *) getNSNullASeq:(ICECurrent *)current +{ + return [NSArray arrayWithObjects:[TestOperationsA a:99], [NSNull null], nil]; +} + +-(TestOperationsStructS *) getNSNullStructSeq:(ICECurrent *)current +{ + TestOperationsStructure *s = [TestOperationsStructure structure:nil e:TestOperationsenum2 s:[TestOperationsAnotherStruct anotherStruct:@"Hello"]]; + return [NSArray arrayWithObjects:s, [NSNull null], nil]; +} + +-(TestOperationsStringSS *) getNSNullStringSeqSeq:(ICECurrent *)current +{ + TestOperationsStringSS *s = [NSArray arrayWithObjects:@"first", nil]; + return [NSArray arrayWithObjects:s, [NSNull null], nil]; +} + +-(TestOperationsStringStringD *) getNSNullStringStringDict:(ICECurrent *)current +{ + TestOperationsMutableStringStringD *d = [TestOperationsMutableStringStringD dictionary]; + [d setObject:@"ONE" forKey:@"one"]; + [d setObject:[NSNull null] forKey:@"two"]; + return d; +} + +-(void) putNSNullStringStringDict:(TestOperationsMutableStringStringD *)d current:(ICECurrent *)current +{ + // Nothing to do because this tests that an exception is thrown on the client side. +} + +-(void) putNSNullShortIntDict:(TestOperationsMutableShortIntD *)d current:(ICECurrent *)current +{ + // Nothing to do because this tests that an exception is thrown on the client side. +} + +-(void) putNSNullStringMyEnumDict:(TestOperationsMutableStringMyEnumD *)d current:(ICECurrent *)current +{ + // Nothing to do because this tests that an exception is thrown on the client side. +} + +-(void) shutdown:(ICECurrent*)current +{ + [[current.adapter getCommunicator] shutdown]; +} +@end diff --git a/objective-c/test/Ice/operations/Twoways.m b/objective-c/test/Ice/operations/Twoways.m new file mode 100644 index 00000000000..f067dbe0159 --- /dev/null +++ b/objective-c/test/Ice/operations/Twoways.m @@ -0,0 +1,1778 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <TestCommon.h> +#import <OperationsTest.h> +#import <limits.h> +#import <float.h> + +#import <Foundation/Foundation.h> + +@interface PerThreadContextInvokeThread : NSThread +{ + id<TestOperationsMyClassPrx> proxy; + NSCondition* cond; + BOOL called; +} +-(id) init:(id<TestOperationsMyClassPrx>)proxy_; ++(id) create:(id<TestOperationsMyClassPrx>)proxy_; +-(void) join; +-(void) run; +@end + +@implementation PerThreadContextInvokeThread +-(id) init:(id<TestOperationsMyClassPrx>)proxy_ +{ + self = [super initWithTarget:self selector:@selector(run) object:nil]; + if(self) + { + self->called = NO; + self->proxy = ICE_RETAIN(proxy_); + cond = [[NSCondition alloc] init]; + } + return self; +} + ++(id) create:(id<TestOperationsMyClassPrx>)proxy_ +{ + return ICE_AUTORELEASE([[PerThreadContextInvokeThread alloc] init:proxy_]); +} + +#if defined(__clang__) && !__has_feature(objc_arc) +-(void) dealloc +{ + [proxy release]; + [cond release]; + [super dealloc]; +} +#endif + +-(void) run +{ + [cond lock]; + ICEMutableContext* ctx = [[[proxy ice_getCommunicator] getImplicitContext] getContext]; + test([ctx count] == 0); + [ctx setObject:@"UN" forKey:@"one" ]; + [[[proxy ice_getCommunicator] getImplicitContext] setContext:ctx]; + called = YES; + [cond signal]; + [cond unlock]; +} + +-(void) join +{ + [cond lock]; + while(!called) + { + [cond wait]; + } + [cond unlock]; +} +@end + +void +twoways(id<ICECommunicator> communicator, id<TestOperationsMyClassPrx> p) +{ + { + [p opVoid]; + } + + { + ICEByte b; + ICEByte r; + + r = [p opByte:(ICEByte)0xff p2:(ICEByte)0x0f p3:&b]; + test(b == (ICEByte)0xf0); + test(r == (ICEByte)0xff); + } + + { + BOOL b; + BOOL r; + + r = [p opBool:YES p2:NO p3:&b]; + test(b); + test(!r); + } + + { + ICEShort s; + ICEInt i; + ICELong l; + ICELong r; + + r = [p opShortIntLong:10 p2:11 p3:12 p4:&s p5:&i p6:&l]; + test(s == 10); + test(i == 11); + test(l == 12); + test(r == 12); + +#ifndef SHORT_MIN +#define SHORT_MIN (-0x7fff) +#endif + r = [p opShortIntLong:SHORT_MIN p2:INT_MIN p3:LONG_MIN p4:&s p5:&i p6:&l]; + test(s == SHORT_MIN); + test(i == INT_MIN); + test(l == LONG_MIN); + test(r == LONG_MIN); + +#ifndef SHORT_MAX +#define SHORT_MAX 0x7fff +#endif + r = [p opShortIntLong:SHORT_MAX p2:INT_MAX p3:LONG_MAX p4:&s p5:&i p6:&l]; + test(s == SHORT_MAX); + test(i == INT_MAX); + test(l == LONG_MAX); + test(r == LONG_MAX); + } + + { + ICEFloat f; + ICEDouble d; + ICEDouble r; + + r = [p opFloatDouble:3.14f p2:1.1E10 p3:&f p4:&d]; + test(f == 3.14f); + test(d == 1.1E10); + test(r == 1.1E10); + + r = [p opFloatDouble:FLT_MIN p2:DBL_MIN p3:&f p4:&d]; + test(f == FLT_MIN); + test(d == DBL_MIN); + test(r == DBL_MIN); + + r = [p opFloatDouble:FLT_MAX p2:DBL_MAX p3:&f p4:&d]; + test(f == FLT_MAX); + test(d == DBL_MAX); + test(r == DBL_MAX); + } + + { + NSMutableString *s = nil; + NSMutableString *r; + + r = [p opString:@"hello" p2:@"world" p3:&s]; + r = [p opString:@"hello" p2:@"world" p3:&s]; + r = [p opString:@"hello" p2:@"world" p3:&s]; + r = [p opString:@"hello" p2:@"world" p3:&s]; + test([s isEqualToString:@"world hello"]); + test([r isEqualToString:@"hello world"]); + } + + { + TestOperationsMyEnum e; + TestOperationsMyEnum r; + + r = [p opMyEnum:TestOperationsenum2 p2:&e]; + test(e == TestOperationsenum2); + test(r == TestOperationsenum3); + } + + { + id<TestOperationsMyClassPrx> c1; + id<TestOperationsMyClassPrx> c2; + id<TestOperationsMyClassPrx> r; + + r = [p opMyClass:p p2:&c1 p3:&c2]; + test([c1 compareIdentityAndFacet:p] == NSOrderedSame); + test([c2 compareIdentityAndFacet:p] != NSOrderedSame); + test([r compareIdentityAndFacet:p] == NSOrderedSame); + test([[c1 ice_getIdentity] isEqual:[communicator stringToIdentity:@"test"]]); + test([[c2 ice_getIdentity]isEqual:[communicator stringToIdentity:@"noSuchIdentity"]]); + test([[r ice_getIdentity] isEqual:[communicator stringToIdentity:@"test"]]); + [r opVoid]; + [c1 opVoid]; + @try + { + [c2 opVoid]; + test(NO); + } + @catch(ICEObjectNotExistException*) + { + } + + r = [p opMyClass:0 p2:&c1 p3:&c2]; + test(c1 == nil); + test(c2 != nil); + test([r compareIdentityAndFacet:p] == NSOrderedSame); + [r opVoid]; + } + + { + TestOperationsStructure *si1 = [TestOperationsStructure structure]; + si1.p = p; + si1.e = TestOperationsenum3; + si1.s = [TestOperationsAnotherStruct anotherStruct]; + si1.s.s = @"abc"; + TestOperationsStructure *si2 = [TestOperationsStructure structure]; + si2.p = nil; + si2.e = TestOperationsenum2; + si2.s = [TestOperationsAnotherStruct anotherStruct]; + si2.s.s = @"def"; + + TestOperationsStructure *so; + TestOperationsStructure *rso = [p opStruct:si1 p2:si2 p3:&so]; + + test(rso.p == nil); + test(rso.e == TestOperationsenum2); + test([rso.s.s isEqualToString:@"def"]); + test(so.p != nil); + test([so.p isEqual:p]); + test(so.e == TestOperationsenum3); + test([so.s.s isEqualToString:@"a new string"]); + [so.p opVoid]; + + // Testing null struct + si1 = [TestOperationsStructure structure]; + si2 = nil; + rso = [p opStruct:si1 p2:si2 p3:&so]; + + test(rso.p == nil); + test(rso.e == TestOperationsenum1); + test([rso.s.s isEqualToString:@""]); + test(so.p == nil); + test(so.e == TestOperationsenum1); + test([so.s.s isEqualToString:@"a new string"]); + } + + { + ICEByte buf1[] = { 0x01, 0x11, 0x12, 0x22 }; + ICEByte buf2[] = { 0xf1, 0xf2, 0xf3, 0xf4 }; + + TestOperationsMutableByteS *bsi1 = [TestOperationsMutableByteS data]; + TestOperationsMutableByteS *bsi2 = [TestOperationsMutableByteS data]; + + [bsi1 appendBytes:buf1 length:sizeof(buf1)]; + [bsi2 appendBytes:buf2 length:sizeof(buf2)]; + + TestOperationsMutableByteS *bso; + TestOperationsByteS *rso; + + rso = [p opByteS:bsi1 p2:bsi2 p3:&bso]; + + test([bso length] == 4); + ICEByte *bbso = (ICEByte *)[bso bytes]; + test(bbso[0] == 0x22); + test(bbso[1] == 0x12); + test(bbso[2] == 0x11); + test(bbso[3] == 0x01); + test([rso length] == 8); + ICEByte *brso = (ICEByte *)[rso bytes]; + test(brso[0] == 0x01); + test(brso[1] == 0x11); + test(brso[2] == 0x12); + test(brso[3] == 0x22); + test(brso[4] == 0xf1); + test(brso[5] == 0xf2); + test(brso[6] == 0xf3); + test(brso[7] == 0xf4); + } + + { + BOOL buf1[] = { YES, YES, NO }; + BOOL buf2[] = { NO }; + + TestOperationsMutableBoolS *bsi1 = [TestOperationsMutableBoolS data]; + TestOperationsMutableBoolS *bsi2 = [TestOperationsMutableBoolS data]; + + [bsi1 appendBytes:buf1 length:sizeof(buf1)]; + [bsi2 appendBytes:buf2 length:sizeof(buf2)]; + + TestOperationsMutableBoolS *bso; + TestOperationsBoolS *rso; + + rso = [p opBoolS:bsi1 p2:bsi2 p3:&bso]; + + test([bso length] == 4 * sizeof(BOOL)); + BOOL *bbso = (BOOL *)[bso bytes]; + test(bbso[0]); + test(bbso[1]); + test(!bbso[2]); + test(!bbso[3]); + test([rso length] == 3 * sizeof(BOOL)); + BOOL *brso = (BOOL *)[rso bytes]; + test(!brso[0]); + test(brso[1]); + test(brso[2]); + } + + { + ICEShort buf1[] = { 1, 2, 3 }; + ICEInt buf2[] = { 5, 6, 7, 8 }; + ICELong buf3[] = { 10, 30, 20 }; + + TestOperationsMutableShortS *ssi = [TestOperationsMutableShortS data]; + TestOperationsMutableIntS *isi = [TestOperationsMutableIntS data]; + TestOperationsMutableLongS *lsi = [TestOperationsMutableLongS data]; + + [ssi appendBytes:buf1 length:sizeof(buf1)]; + [isi appendBytes:buf2 length:sizeof(buf2)]; + [lsi appendBytes:buf3 length:sizeof(buf3)]; + + TestOperationsMutableShortS *sso; + TestOperationsMutableIntS *iso; + TestOperationsMutableLongS *lso; + TestOperationsLongS *rso; + + rso = [p opShortIntLongS:ssi p2:isi p3:lsi p4:&sso p5:&iso p6:&lso]; + + test([sso length] == 3 * sizeof(ICEShort)); + ICEShort *bsso = (ICEShort *)[sso bytes]; + test(bsso[0] == 1); + test(bsso[1] == 2); + test(bsso[2] == 3); + test([iso length] == 4 * sizeof(ICEInt)); + ICEInt *biso = (ICEInt *)[iso bytes]; + test(biso[0] == 8); + test(biso[1] == 7); + test(biso[2] == 6); + test(biso[3] == 5); + test([lso length] == 6 * sizeof(ICELong)); + ICELong *blso = (ICELong *)[lso bytes]; + test(blso[0] == 10); + test(blso[1] == 30); + test(blso[2] == 20); + test(blso[3] == 10); + test(blso[4] == 30); + test(blso[5] == 20); + test([rso length] == 3 * sizeof(ICELong)); + ICELong *brso = (ICELong *)[rso bytes]; + test(brso[0] == 10); + test(brso[1] == 30); + test(brso[2] == 20); + } + + { + ICEFloat buf1[] = { 3.14f, 1.11f }; + ICEDouble buf2[] = { 1.1E10, 1.2E10, 1.3E10 }; + + TestOperationsMutableFloatS *fsi = [TestOperationsMutableFloatS data]; + TestOperationsMutableDoubleS *dsi = [TestOperationsMutableDoubleS data]; + + [fsi appendBytes:buf1 length:sizeof(buf1)]; + [dsi appendBytes:buf2 length:sizeof(buf2)]; + + TestOperationsMutableFloatS *fso; + TestOperationsMutableDoubleS *dso; + TestOperationsDoubleS *rso; + + rso = [p opFloatDoubleS:fsi p2:dsi p3:&fso p4:&dso]; + + test([fso length] == 2 * sizeof(ICEFloat)); + ICEFloat *bfso = (ICEFloat *)[fso bytes]; + test(bfso[0] == 3.14f); + test(bfso[1] == 1.11f); + test([dso length] == 3 * sizeof(ICEDouble)); + ICEDouble *bdso = (ICEDouble *)[dso bytes]; + test(bdso[0] == 1.3E10); + test(bdso[1] == 1.2E10); + test(bdso[2] == 1.1E10); + test([rso length] == 5 * sizeof(ICEDouble)); + ICEDouble *brso = (ICEDouble *)[rso bytes]; + test(brso[0] == 1.1E10); + test(brso[1] == 1.2E10); + test(brso[2] == 1.3E10); + test((ICEFloat)brso[3] == 3.14f); + test((ICEFloat)brso[4] == 1.11f); + } + + { + TestOperationsMutableStringS *ssi1 = [TestOperationsMutableStringS arrayWithCapacity:3]; + TestOperationsMutableStringS *ssi2 = [TestOperationsMutableStringS arrayWithCapacity:1]; + + [ssi1 addObject:@"abc"]; + [ssi1 addObject:@"de"]; + [ssi1 addObject:@"fghi"]; + + [ssi2 addObject:@"xyz"]; + + TestOperationsMutableStringS *sso; + TestOperationsStringS *rso; + + rso = [p opStringS:ssi1 p2:ssi2 p3:&sso]; + + test([sso count] == 4); + test([[sso objectAtIndex:0] isEqualToString:@"abc"]); + test([[sso objectAtIndex:1] isEqualToString:@"de"]); + test([[sso objectAtIndex:2] isEqualToString:@"fghi"]); + test([[sso objectAtIndex:3] isEqualToString:@"xyz"]); + test([rso count] == 3); + test([[rso objectAtIndex:0] isEqualToString:@"fghi"]); + test([[rso objectAtIndex:1] isEqualToString:@"de"]); + test([[rso objectAtIndex:2] isEqualToString:@"abc"]); + } + + @try + { + TestOperationsMutableMyClassS *ssi1 = [TestOperationsMutableMyClassS arrayWithCapacity:3]; + TestOperationsMutableMyClassS *ssi2 = [TestOperationsMutableMyClassS arrayWithCapacity:1]; + + ICEIdentity *i1 = [ICEIdentity identity:@"abc" category:@""]; + ICEIdentity *i2 = [ICEIdentity identity:@"de" category:@""]; + ICEIdentity *i3 = [ICEIdentity identity:@"fhgi" category:@""]; + ICEIdentity *i4 = [ICEIdentity identity:@"xyz" category:@""]; + + [ssi1 addObject:[p ice_identity:i1]]; + [ssi1 addObject:[p ice_identity:i2]]; + [ssi1 addObject:[p ice_identity:i3]]; + + [ssi2 addObject:[p ice_identity:i4]]; + + TestOperationsMutableMyClassS *sso; + TestOperationsMyClassS *rso; + + rso = [p opMyClassS:ssi1 p2:ssi2 p3:&sso]; + + test([sso count] == 4); + test([[[sso objectAtIndex:0] ice_getIdentity] isEqual:i1]); + test([[[sso objectAtIndex:1] ice_getIdentity] isEqual:i2]); + test([[[sso objectAtIndex:2] ice_getIdentity] isEqual:i3]); + test([[[sso objectAtIndex:3] ice_getIdentity] isEqual:i4]); + test([rso count] == 3); + test([[[rso objectAtIndex:0] ice_getIdentity] isEqual:i3]); + test([[[rso objectAtIndex:1] ice_getIdentity] isEqual:i2]); + test([[[rso objectAtIndex:2] ice_getIdentity] isEqual:i1]); + } + @catch(ICEOperationNotExistException*) + { + // Some mapping don't implement this method. + } + + @try + { + TestOperationsMyEnum buf1[] = { TestOperationsenum2, TestOperationsenum3, TestOperationsenum3 }; + TestOperationsMyEnum buf2[] = { TestOperationsenum1 }; + + TestOperationsMutableMyEnumS *esi1 = [TestOperationsMutableMyEnumS data]; + TestOperationsMutableMyEnumS *esi2 = [TestOperationsMutableMyEnumS data]; + + [esi1 appendBytes:buf1 length:sizeof(buf1)]; + [esi2 appendBytes:buf2 length:sizeof(buf2)]; + + TestOperationsMutableMyEnumS *eso; + TestOperationsMyEnumS *rso; + + rso = [p opMyEnumS:esi1 p2:esi2 p3:&eso]; + + test([eso length] / sizeof(TestOperationsMyEnum) == 3); + const TestOperationsMyEnum *beso = (const TestOperationsMyEnum *)[eso bytes]; + test(beso[0] == TestOperationsenum3); + test(beso[1] == TestOperationsenum3); + test(beso[2] == TestOperationsenum2); + test([rso length] / sizeof(TestOperationsMyEnum) == 4); + const TestOperationsMyEnum *brso = (const TestOperationsMyEnum *)[rso bytes]; + test(brso[0] == TestOperationsenum2); + test(brso[1] == TestOperationsenum3); + test(brso[2] == TestOperationsenum3); + test(brso[3] == TestOperationsenum1); + } + @catch(ICEOperationNotExistException*) + { + // Some mapping don't implement this method. + } + + { + TestOperationsMutableByteSS *bsi1 = [TestOperationsMutableByteSS array]; + TestOperationsMutableByteSS *bsi2 = [TestOperationsMutableByteSS array]; + + ICEByte b; + TestOperationsMutableByteS *tmp = [TestOperationsMutableByteS data]; + + b = 0x01; + [tmp appendBytes:&b length:sizeof(b)]; + b = 0x11; + [tmp appendBytes:&b length:sizeof(b)]; + b = 0x12; + [tmp appendBytes:&b length:sizeof(b)]; + [bsi1 addObject:tmp]; + + tmp = [TestOperationsMutableByteS data]; + b = 0xff; + [tmp appendBytes:&b length:sizeof(b)]; + [bsi1 addObject:tmp]; + + tmp = [TestOperationsMutableByteS data]; + b = 0x0e; + [tmp appendBytes:&b length:sizeof(b)]; + [bsi2 addObject:tmp]; + + tmp = [TestOperationsMutableByteS data]; + b = 0xf2; + [tmp appendBytes:&b length:sizeof(b)]; + b = 0xf1; + [tmp appendBytes:&b length:sizeof(b)]; + [bsi2 addObject:tmp]; + + TestOperationsMutableByteSS *bso; + TestOperationsByteSS *rso; + + rso = [p opByteSS:bsi1 p2:bsi2 p3:&bso]; + + const ICEByte *p; + test([bso count] == 2); + test([[bso objectAtIndex:0] length] / sizeof(ICEByte) == 1); + p = [[bso objectAtIndex:0] bytes]; + test(p[0] == (ICEByte)0x0ff); + test([[bso objectAtIndex:1] length] / sizeof(ICEByte) == 3); + p = [[bso objectAtIndex:1] bytes]; + test(p[0] == (ICEByte)0x01); + test(p[1] == (ICEByte)0x11); + test(p[2] == (ICEByte)0x12); + test([rso count] == 4); + test([[rso objectAtIndex:0] length] / sizeof(ICEByte) == 3); + p = [[rso objectAtIndex:0] bytes]; + test(p[0] == (ICEByte)0x01); + test(p[1] == (ICEByte)0x11); + test(p[2] == (ICEByte)0x12); + test([[rso objectAtIndex:1] length] / sizeof(ICEByte) == 1); + p = [[rso objectAtIndex:1] bytes]; + test(p[0] == (ICEByte)0xff); + test([[rso objectAtIndex:2] length] / sizeof(ICEByte) == 1); + p = [[rso objectAtIndex:2] bytes]; + test(p[0] == (ICEByte)0x0e); + test([[rso objectAtIndex:3] length] / sizeof(ICEByte) == 2); + p = [[rso objectAtIndex:3] bytes]; + test(p[0] == (ICEByte)0xf2); + test(p[1] == (ICEByte)0xf1); + } + + { + TestOperationsMutableFloatSS *fsi = [TestOperationsMutableFloatSS array]; + TestOperationsMutableDoubleSS *dsi = [TestOperationsMutableDoubleSS array]; + + ICEFloat f; + TestOperationsMutableFloatS *ftmp; + + ftmp = [TestOperationsMutableFloatS data]; + f = 3.14f; + [ftmp appendBytes:&f length:sizeof(f)]; + [fsi addObject:ftmp]; + ftmp = [TestOperationsMutableFloatS data]; + f = 1.11f; + [ftmp appendBytes:&f length:sizeof(f)]; + [fsi addObject:ftmp]; + ftmp = [TestOperationsMutableFloatS data]; + [fsi addObject:ftmp]; + + ICEDouble d; + TestOperationsMutableDoubleS *dtmp; + + dtmp = [TestOperationsMutableDoubleS data]; + d = 1.1E10; + [dtmp appendBytes:&d length:sizeof(d)]; + d = 1.2E10; + [dtmp appendBytes:&d length:sizeof(d)]; + d = 1.3E10; + [dtmp appendBytes:&d length:sizeof(d)]; + [dsi addObject:dtmp]; + + TestOperationsMutableFloatSS *fso; + TestOperationsMutableDoubleSS *dso; + TestOperationsDoubleSS *rso; + + rso = [p opFloatDoubleSS:fsi p2:dsi p3:&fso p4:&dso]; + + const ICEFloat *fp; + const ICEDouble *dp; + + test([fso count] == 3); + test([[fso objectAtIndex:0] length] / sizeof(ICEFloat) == 1); + fp = [[fso objectAtIndex:0] bytes]; + test(fp[0] == 3.14f); + test([[fso objectAtIndex:1] length] / sizeof(ICEFloat) == 1); + fp = [[fso objectAtIndex:1] bytes]; + test(fp[0] == 1.11f); + test([[fso objectAtIndex:2] length] / sizeof(ICEFloat) == 0); + test([dso count] == 1); + test([[dso objectAtIndex:0] length] / sizeof(ICEDouble) == 3); + dp = [[dso objectAtIndex:0] bytes]; + test(dp[0] == 1.1E10); + test(dp[1] == 1.2E10); + test(dp[2] == 1.3E10); + test([rso count] == 2); + test([[rso objectAtIndex:0] length] / sizeof(ICEDouble) == 3); + dp = [[rso objectAtIndex:0] bytes]; + test(dp[0] == 1.1E10); + test(dp[1] == 1.2E10); + test(dp[2] == 1.3E10); + test([[rso objectAtIndex:1] length] / sizeof(ICEDouble) == 3); + dp = [[rso objectAtIndex:1] bytes]; + test(dp[0] == 1.1E10); + test(dp[1] == 1.2E10); + test(dp[2] == 1.3E10); + } + + { + TestOperationsMutableStringSS * ssi1 = [TestOperationsMutableStringSS array]; + TestOperationsMutableStringSS * ssi2 = [TestOperationsMutableStringSS array]; + + TestOperationsMutableStringS *tmp; + + tmp = [TestOperationsMutableStringS array]; + [tmp addObject:@"abc"]; + [ssi1 addObject:tmp]; + tmp = [TestOperationsMutableStringS array]; + [tmp addObject:@"de"]; + [tmp addObject:@"fghi"]; + [ssi1 addObject:tmp]; + + [ssi2 addObject:[TestOperationsStringS array]]; + [ssi2 addObject:[TestOperationsStringS array]]; + tmp = [TestOperationsMutableStringS array]; + [tmp addObject:@"xyz"]; + [ssi2 addObject:tmp]; + + TestOperationsMutableStringSS *sso; + TestOperationsStringSS *rso; + + rso = [p opStringSS:ssi1 p2:ssi2 p3:&sso]; + + test([sso count] == 5); + test([[sso objectAtIndex:0] count] == 1); + test([[[sso objectAtIndex:0] objectAtIndex:0] isEqualToString:@"abc"]); + test([[sso objectAtIndex:1] count] == 2); + test([[[sso objectAtIndex:1] objectAtIndex:0] isEqualToString:@"de"]); + test([[[sso objectAtIndex:1] objectAtIndex:1] isEqualToString:@"fghi"]); + test([[sso objectAtIndex:2] count] == 0); + test([[sso objectAtIndex:3] count] == 0); + test([[sso objectAtIndex:4] count] == 1); + test([[[sso objectAtIndex:4] objectAtIndex:0] isEqualToString:@"xyz"]); + test([rso count] == 3); + test([[rso objectAtIndex:0] count] == 1); + test([[[rso objectAtIndex:0] objectAtIndex:0] isEqualToString:@"xyz"]); + test([[rso objectAtIndex:1] count] == 0); + test([[rso objectAtIndex:2] count] == 0); + } + + { + TestOperationsMutableStringSSS *sssi1 = [TestOperationsMutableStringSSS array]; + TestOperationsMutableStringSSS *sssi2 = [TestOperationsMutableStringSSS array]; + + TestOperationsMutableStringSS *tmpss; + TestOperationsMutableStringS *tmps; + + tmps = [TestOperationsMutableStringS array]; + [tmps addObject:@"abc"]; + [tmps addObject:@"de"]; + tmpss = [TestOperationsMutableStringSS array]; + [tmpss addObject:tmps]; + tmps = [TestOperationsMutableStringS array]; + [tmps addObject:@"xyz"]; + [tmpss addObject:tmps]; + [sssi1 addObject:tmpss]; + tmps = [TestOperationsMutableStringS array]; + [tmps addObject:@"hello"]; + tmpss = [TestOperationsMutableStringSS array]; + [tmpss addObject:tmps]; + [sssi1 addObject:tmpss]; + + tmps = [TestOperationsMutableStringS array]; + [tmps addObject:@""]; + [tmps addObject:@""]; + tmpss = [TestOperationsMutableStringSS array]; + [tmpss addObject:tmps]; + tmps = [TestOperationsMutableStringS array]; + [tmps addObject:@"abcd"]; + [tmpss addObject:tmps]; + [sssi2 addObject:tmpss]; + tmps = [TestOperationsMutableStringS array]; + [tmps addObject:@""]; + tmpss = [TestOperationsMutableStringSS array]; + [tmpss addObject:tmps]; + [sssi2 addObject:tmpss]; + tmpss = [TestOperationsMutableStringSS array]; + [sssi2 addObject:tmpss]; + + TestOperationsMutableStringSSS *ssso; + TestOperationsStringSSS *rsso; + + rsso = [p opStringSSS:sssi1 p2:sssi2 p3:&ssso]; + + test([ssso count] == 5); + test([[ssso objectAtIndex:0] count] == 2); + test([[[ssso objectAtIndex:0] objectAtIndex:0] count] == 2); + test([[[ssso objectAtIndex:0] objectAtIndex:1] count] == 1); + test([[ssso objectAtIndex:1] count] == 1); + test([[[ssso objectAtIndex:1] objectAtIndex:0] count] == 1); + test([[ssso objectAtIndex:2] count] == 2); + test([[[ssso objectAtIndex:2] objectAtIndex:0] count] == 2); + test([[[ssso objectAtIndex:2] objectAtIndex:1] count] == 1); + test([[ssso objectAtIndex:3] count] == 1); + test([[[ssso objectAtIndex:3] objectAtIndex:0] count] == 1); + test([[ssso objectAtIndex:4] count] == 0); + test([[[[ssso objectAtIndex:0] objectAtIndex:0] objectAtIndex:0] isEqualToString:@"abc"]); + test([[[[ssso objectAtIndex:0] objectAtIndex:0] objectAtIndex:1] isEqualToString:@"de"]); + test([[[[ssso objectAtIndex:0] objectAtIndex:1] objectAtIndex:0] isEqualToString:@"xyz"]); + test([[[[ssso objectAtIndex:1] objectAtIndex:0] objectAtIndex:0] isEqualToString:@"hello"]); + test([[[[ssso objectAtIndex:2] objectAtIndex:0] objectAtIndex:0] isEqualToString:@""]); + test([[[[ssso objectAtIndex:2] objectAtIndex:0] objectAtIndex:1] isEqualToString:@""]); + test([[[[ssso objectAtIndex:2] objectAtIndex:1] objectAtIndex:0] isEqualToString:@"abcd"]); + test([[[[ssso objectAtIndex:3] objectAtIndex:0] objectAtIndex:0] isEqualToString:@""]); + + test([rsso count] == 3); + test([[rsso objectAtIndex:0] count] == 0); + test([[rsso objectAtIndex:1] count] == 1); + test([[[rsso objectAtIndex:1] objectAtIndex:0] count] == 1); + test([[rsso objectAtIndex:2] count] == 2); + test([[[rsso objectAtIndex:2] objectAtIndex:0] count] == 2); + test([[[rsso objectAtIndex:2] objectAtIndex:1] count] == 1); + test([[[[rsso objectAtIndex:1] objectAtIndex:0] objectAtIndex:0] isEqualToString:@""]); + test([[[[rsso objectAtIndex:2] objectAtIndex:0] objectAtIndex:0] isEqualToString:@""]); + test([[[[rsso objectAtIndex:2] objectAtIndex:0] objectAtIndex:1] isEqualToString:@""]); + test([[[[rsso objectAtIndex:2] objectAtIndex:1] objectAtIndex:0] isEqualToString:@"abcd"]); + } + + { + TestOperationsMutableByteBoolD *di1 = [TestOperationsMutableByteBoolD dictionary]; + [di1 setObject:[NSNumber numberWithBool:YES] forKey:[NSNumber numberWithUnsignedChar:10]]; + [di1 setObject:[NSNumber numberWithBool:NO] forKey:[NSNumber numberWithUnsignedChar:100]]; + TestOperationsMutableByteBoolD *di2 = [TestOperationsMutableByteBoolD dictionary]; + [di2 setObject:[NSNumber numberWithBool:YES] forKey:[NSNumber numberWithUnsignedChar:10]]; + [di2 setObject:[NSNumber numberWithBool:NO] forKey:[NSNumber numberWithUnsignedChar:11]]; + [di2 setObject:[NSNumber numberWithBool:TRUE] forKey:[NSNumber numberWithUnsignedChar:101]]; + + TestOperationsMutableByteBoolD *_do; + TestOperationsMutableByteBoolD *ro = [p opByteBoolD:di1 p2:di2 p3:&_do]; + + test([_do isEqualToDictionary:di1]); + test([ro count] == 4); + test([[ro objectForKey:[NSNumber numberWithUnsignedChar:10]] boolValue] == YES); + test([[ro objectForKey:[NSNumber numberWithUnsignedChar:11]] boolValue] == NO); + test([[ro objectForKey:[NSNumber numberWithUnsignedChar:100]] boolValue] == NO); + test([[ro objectForKey:[NSNumber numberWithUnsignedChar:101]] boolValue] == YES); + } + + { + TestOperationsMutableShortIntD *di1 = [TestOperationsMutableShortIntD dictionary]; + [di1 setObject:[NSNumber numberWithInt:-1] forKey:[NSNumber numberWithShort:110]]; + [di1 setObject:[NSNumber numberWithInt:123123] forKey:[NSNumber numberWithShort:1100]]; + TestOperationsMutableShortIntD *di2 = [TestOperationsMutableShortIntD dictionary]; + [di2 setObject:[NSNumber numberWithInt:-1] forKey:[NSNumber numberWithShort:110]]; + [di2 setObject:[NSNumber numberWithInt:-100] forKey:[NSNumber numberWithShort:111]]; + [di2 setObject:[NSNumber numberWithInt:0] forKey:[NSNumber numberWithShort:1101]]; + + TestOperationsMutableShortIntD *_do; + TestOperationsMutableShortIntD *ro = [p opShortIntD:di1 p2:di2 p3:&_do]; + + test([_do isEqualToDictionary:di1]); + test([ro count] == 4); + test([[ro objectForKey:[NSNumber numberWithShort:110]] intValue] == -1); + test([[ro objectForKey:[NSNumber numberWithShort:111]] intValue] == -100); + test([[ro objectForKey:[NSNumber numberWithShort:1100]] intValue] == 123123); + test([[ro objectForKey:[NSNumber numberWithShort:1101]] intValue] == 0); + } + + { + TestOperationsMutableLongFloatD *di1 = [TestOperationsMutableLongFloatD dictionary]; + [di1 setObject:[NSNumber numberWithFloat:-1.1f] forKey:[NSNumber numberWithLong:999999110]]; + [di1 setObject:[NSNumber numberWithFloat:123123.2f] forKey:[NSNumber numberWithLong:999999111]]; + TestOperationsMutableLongFloatD *di2 = [TestOperationsMutableLongFloatD dictionary]; + [di2 setObject:[NSNumber numberWithFloat:-1.1f] forKey:[NSNumber numberWithLong:999999110]]; + [di2 setObject:[NSNumber numberWithFloat:-100.4f] forKey:[NSNumber numberWithLong:999999120]]; + [di2 setObject:[NSNumber numberWithFloat:0.5f] forKey:[NSNumber numberWithLong:999999130]]; + + TestOperationsMutableLongFloatD *_do; + TestOperationsMutableLongFloatD *ro = [p opLongFloatD:di1 p2:di2 p3:&_do]; + + test([_do isEqualToDictionary:di1]); + test([ro count] == 4); + test((ICEFloat)[[ro objectForKey:[NSNumber numberWithLong:999999110]] floatValue] == -1.1f); + test((ICEFloat)[[ro objectForKey:[NSNumber numberWithLong:999999120]] floatValue] == -100.4f); + test((ICEFloat)[[ro objectForKey:[NSNumber numberWithLong:999999111]] floatValue] == 123123.2f); + test((ICEFloat)[[ro objectForKey:[NSNumber numberWithLong:999999130]] floatValue] == 0.5f); + } + + { + TestOperationsMutableStringStringD *di1 = [TestOperationsMutableStringStringD dictionary]; + [di1 setObject:@"abc -1.1" forKey:@"foo"]; + [di1 setObject:@"abc 123123.2" forKey:@"bar"]; + TestOperationsMutableStringStringD *di2 = [TestOperationsMutableStringStringD dictionary]; + [di2 setObject:@"abc -1.1" forKey:@"foo"]; + [di2 setObject:@"abc -100.4" forKey:@"FOO"]; + [di2 setObject:@"abc 0.5" forKey:@"BAR"]; + + TestOperationsMutableStringStringD *_do; + TestOperationsMutableStringStringD *ro = [p opStringStringD:di1 p2:di2 p3:&_do]; + + test([_do isEqualToDictionary:di1]); + test([ro count] == 4); + test([[ro objectForKey:@"foo"] isEqualToString:@"abc -1.1"]); + test([[ro objectForKey:@"FOO"] isEqualToString:@"abc -100.4"]); + test([[ro objectForKey:@"bar"] isEqualToString:@"abc 123123.2"]); + test([[ro objectForKey:@"BAR"] isEqualToString:@"abc 0.5"]); + } + + { + TestOperationsMutableStringMyEnumD *di1 = [TestOperationsMutableStringMyEnumD dictionary]; + [di1 setObject:[NSNumber numberWithInt:TestOperationsenum1] forKey:@"abc"]; + [di1 setObject:[NSNumber numberWithInt:TestOperationsenum2] forKey:@""]; + TestOperationsMutableStringMyEnumD *di2 = [TestOperationsMutableStringMyEnumD dictionary]; + [di2 setObject:[NSNumber numberWithInt:TestOperationsenum1] forKey:@"abc"]; + [di2 setObject:[NSNumber numberWithInt:TestOperationsenum3] forKey:@"querty"]; + [di2 setObject:[NSNumber numberWithInt:TestOperationsenum2] forKey:@"Hello!!"]; + + TestOperationsMutableStringMyEnumD *_do; + TestOperationsMutableStringMyEnumD *ro = [p opStringMyEnumD:di1 p2:di2 p3:&_do]; + + test([_do isEqualToDictionary:di1]); + test([ro count] == 4); + test([[ro objectForKey:@"abc"] intValue] == TestOperationsenum1); + test([[ro objectForKey:@"querty"] intValue] == TestOperationsenum3); + test([[ro objectForKey:@""] intValue] == TestOperationsenum2); + test([[ro objectForKey:@"Hello!!"] intValue] == TestOperationsenum2); + } + + { + TestOperationsMutableMyEnumStringD *di1 = [TestOperationsMutableMyEnumStringD dictionary]; + [di1 setObject:@"abc" forKey:@(TestOperationsenum1)]; + TestOperationsMutableMyEnumStringD *di2 = [TestOperationsMutableMyEnumStringD dictionary]; + [di2 setObject:@"Hello!!" forKey:@(TestOperationsenum2)]; + [di2 setObject:@"querty" forKey:@(TestOperationsenum3)]; + + TestOperationsMutableMyEnumStringD *_do; + TestOperationsMutableMyEnumStringD *ro = [p opMyEnumStringD:di1 p2:di2 p3:&_do]; + + test([_do isEqualToDictionary:di1]); + test([ro count] == 3); + test([[ro objectForKey:@(TestOperationsenum1)] isEqualToString:@"abc"]); + test([[ro objectForKey:@(TestOperationsenum3)] isEqualToString:@"querty"]); + test([[ro objectForKey:@(TestOperationsenum2)] isEqualToString:@"Hello!!"]); + } + + { + TestOperationsMyStruct* s11 = [TestOperationsMyStruct myStruct:1 j:1]; + TestOperationsMyStruct* s12 = [TestOperationsMyStruct myStruct:1 j:2]; + TestOperationsMutableMyStructMyEnumD* di1 = [TestOperationsMutableMyStructMyEnumD dictionary]; + [di1 setObject:@(TestOperationsenum1) forKey:s11]; + [di1 setObject:@(TestOperationsenum2) forKey:s12]; + + TestOperationsMyStruct* s22 = [TestOperationsMyStruct myStruct:2 j:2]; + TestOperationsMyStruct* s23 = [TestOperationsMyStruct myStruct:2 j:3]; + TestOperationsMutableMyStructMyEnumD* di2 = [TestOperationsMutableMyStructMyEnumD dictionary]; + [di2 setObject:@(TestOperationsenum1) forKey:s11]; + [di2 setObject:@(TestOperationsenum3) forKey:s22]; + [di2 setObject:@(TestOperationsenum2) forKey:s23]; + + TestOperationsMutableMyStructMyEnumD* _do; + TestOperationsMyStructMyEnumD* ro = [p opMyStructMyEnumD:di1 p2:di2 p3:&_do]; + + test([_do isEqual:di1]); + test([ro count] == 4); + test([[ro objectForKey:s11] isEqual:@(TestOperationsenum1)]); + test([[ro objectForKey:s12] isEqual:@(TestOperationsenum2)]); + test([[ro objectForKey:s22] isEqual:@(TestOperationsenum3)]); + test([[ro objectForKey:s23] isEqual:@(TestOperationsenum2)]); + } + + { + TestOperationsMutableByteBoolDS* dsi1 = [TestOperationsMutableByteBoolDS array]; + TestOperationsMutableByteBoolDS* dsi2 = [TestOperationsMutableByteBoolDS array]; + + TestOperationsMutableByteBoolD *di1 = [TestOperationsMutableByteBoolD dictionary]; + [di1 setObject:[NSNumber numberWithBool:YES] forKey:[NSNumber numberWithUnsignedChar:10]]; + [di1 setObject:[NSNumber numberWithBool:NO] forKey:[NSNumber numberWithUnsignedChar:100]]; + TestOperationsMutableByteBoolD *di2 = [TestOperationsMutableByteBoolD dictionary]; + [di2 setObject:[NSNumber numberWithBool:YES] forKey:[NSNumber numberWithUnsignedChar:10]]; + [di2 setObject:[NSNumber numberWithBool:NO] forKey:[NSNumber numberWithUnsignedChar:11]]; + [di2 setObject:[NSNumber numberWithBool:TRUE] forKey:[NSNumber numberWithUnsignedChar:101]]; + TestOperationsMutableByteBoolD *di3 = [TestOperationsMutableByteBoolD dictionary]; + [di3 setObject:[NSNumber numberWithBool:NO] forKey:[NSNumber numberWithUnsignedChar:100]]; + [di3 setObject:[NSNumber numberWithBool:NO] forKey:[NSNumber numberWithUnsignedChar:101]]; + + [dsi1 addObject:di1]; + [dsi1 addObject:di2]; + [dsi2 addObject:di3]; + + TestOperationsMutableByteBoolDS* _do; + TestOperationsByteBoolDS* ro = [p opByteBoolDS:dsi1 p2:dsi2 p3:&_do]; + + test([ro count] == 2); + test([[ro objectAtIndex:0] count] == 3); + test([[[ro objectAtIndex:0] objectForKey:[NSNumber numberWithUnsignedChar:10]] boolValue] == YES); + test([[[ro objectAtIndex:0] objectForKey:[NSNumber numberWithUnsignedChar:11]] boolValue] == NO); + test([[[ro objectAtIndex:0] objectForKey:[NSNumber numberWithUnsignedChar:101]] boolValue] == YES); + test([[ro objectAtIndex:1] count] == 2); + test([[[ro objectAtIndex:1] objectForKey:[NSNumber numberWithUnsignedChar:10]] boolValue] == YES); + test([[[ro objectAtIndex:1] objectForKey:[NSNumber numberWithUnsignedChar:100]] boolValue] == NO); + test([_do count] == 3); + test([[_do objectAtIndex:0] count] == 2); + test([[[_do objectAtIndex:0] objectForKey:[NSNumber numberWithUnsignedChar:100]] boolValue] == NO); + test([[[_do objectAtIndex:0] objectForKey:[NSNumber numberWithUnsignedChar:101]] boolValue] == NO); + test([[_do objectAtIndex:1] count] == 2); + test([[[_do objectAtIndex:1] objectForKey:[NSNumber numberWithUnsignedChar:10]] boolValue] == YES); + test([[[_do objectAtIndex:1] objectForKey:[NSNumber numberWithUnsignedChar:100]] boolValue] == NO); + test([[_do objectAtIndex:2] count] == 3); + test([[[_do objectAtIndex:2] objectForKey:[NSNumber numberWithUnsignedChar:10]] boolValue] == YES); + test([[[_do objectAtIndex:2] objectForKey:[NSNumber numberWithUnsignedChar:11]] boolValue] == NO); + test([[[_do objectAtIndex:2] objectForKey:[NSNumber numberWithUnsignedChar:101]] boolValue] == YES); + } + + { + TestOperationsMutableShortIntDS *dsi1 = [TestOperationsMutableShortIntDS array]; + TestOperationsMutableShortIntDS *dsi2 = [TestOperationsMutableShortIntDS array]; + + TestOperationsMutableShortIntD *di1 = [TestOperationsMutableShortIntD dictionary]; + [di1 setObject:[NSNumber numberWithInt:-1] forKey:[NSNumber numberWithShort:110]]; + [di1 setObject:[NSNumber numberWithInt:123123] forKey:[NSNumber numberWithShort:1100]]; + TestOperationsMutableShortIntD *di2 = [TestOperationsMutableShortIntD dictionary]; + [di2 setObject:[NSNumber numberWithInt:-1] forKey:[NSNumber numberWithShort:110]]; + [di2 setObject:[NSNumber numberWithInt:-100] forKey:[NSNumber numberWithShort:111]]; + [di2 setObject:[NSNumber numberWithInt:0] forKey:[NSNumber numberWithShort:1101]]; + TestOperationsMutableShortIntD *di3 = [TestOperationsMutableShortIntD dictionary]; + [di3 setObject:[NSNumber numberWithInt:-1001] forKey:[NSNumber numberWithShort:100]]; + + [dsi1 addObject:di1]; + [dsi1 addObject:di2]; + [dsi2 addObject:di3]; + + TestOperationsMutableShortIntDS *_do; + TestOperationsShortIntDS *ro = [p opShortIntDS:dsi1 p2:dsi2 p3:&_do]; + + test([ro count] == 2); + test([[ro objectAtIndex:0] count] == 3); + test([[[ro objectAtIndex:0] objectForKey:[NSNumber numberWithShort:110]] intValue] == -1); + test([[[ro objectAtIndex:0] objectForKey:[NSNumber numberWithShort:111]] intValue] == -100); + test([[[ro objectAtIndex:0] objectForKey:[NSNumber numberWithShort:1101]] intValue] == 0); + test([[ro objectAtIndex:1] count] == 2); + test([[[ro objectAtIndex:1] objectForKey:[NSNumber numberWithShort:110]] intValue] == -1); + test([[[ro objectAtIndex:1] objectForKey:[NSNumber numberWithShort:1100]] intValue] == 123123); + test([_do count] == 3); + test([[_do objectAtIndex:0] count] == 1); + test([[[_do objectAtIndex:0] objectForKey:[NSNumber numberWithShort:100]] intValue] == -1001); + test([[_do objectAtIndex:1] count] == 2); + test([[[_do objectAtIndex:1] objectForKey:[NSNumber numberWithShort:110]] intValue] == -1); + test([[[_do objectAtIndex:1] objectForKey:[NSNumber numberWithShort:1100]] intValue] == 123123); + test([[_do objectAtIndex:2] count] == 3); + test([[[_do objectAtIndex:2] objectForKey:[NSNumber numberWithShort:110]] intValue] == -1); + test([[[_do objectAtIndex:2] objectForKey:[NSNumber numberWithShort:111]] intValue] == -100); + test([[[_do objectAtIndex:2] objectForKey:[NSNumber numberWithShort:1101]] intValue] == 0); + } + + { + TestOperationsMutableLongFloatDS *dsi1 = [TestOperationsMutableLongFloatDS array]; + TestOperationsMutableLongFloatDS *dsi2 = [TestOperationsMutableLongFloatDS array]; + + TestOperationsMutableLongFloatD *di1 = [TestOperationsMutableLongFloatD dictionary]; + [di1 setObject:[NSNumber numberWithFloat:-1.1f] forKey:[NSNumber numberWithLong:999999110]]; + [di1 setObject:[NSNumber numberWithFloat:123123.2f] forKey:[NSNumber numberWithLong:999999111]]; + TestOperationsMutableLongFloatD *di2 = [TestOperationsMutableLongFloatD dictionary]; + [di2 setObject:[NSNumber numberWithFloat:-1.1f] forKey:[NSNumber numberWithLong:999999110]]; + [di2 setObject:[NSNumber numberWithFloat:-100.4f] forKey:[NSNumber numberWithLong:999999120]]; + [di2 setObject:[NSNumber numberWithFloat:0.5f] forKey:[NSNumber numberWithLong:999999130]]; + TestOperationsMutableLongFloatD *di3 = [TestOperationsMutableLongFloatD dictionary]; + [di3 setObject:[NSNumber numberWithFloat:3.14f] forKey:[NSNumber numberWithLong:999999140]]; + + [dsi1 addObject:di1]; + [dsi1 addObject:di2]; + [dsi2 addObject:di3]; + + TestOperationsMutableLongFloatDS *_do; + TestOperationsLongFloatDS *ro = [p opLongFloatDS:dsi1 p2:dsi2 p3:&_do]; + + test([ro count] == 2); + test([[ro objectAtIndex:0] count] == 3); + test([[[ro objectAtIndex:0] objectForKey:[NSNumber numberWithLong:999999110]] floatValue] == -1.1f); + test([[[ro objectAtIndex:0] objectForKey:[NSNumber numberWithLong:999999120]] floatValue] == -100.4f); + test([[[ro objectAtIndex:0] objectForKey:[NSNumber numberWithLong:999999130]] floatValue] == 0.5f); + test([[ro objectAtIndex:1] count] == 2); + test([[[ro objectAtIndex:1] objectForKey:[NSNumber numberWithLong:999999110]] floatValue] == -1.1f); + test([[[ro objectAtIndex:1] objectForKey:[NSNumber numberWithLong:999999111]] floatValue] == 123123.2f); + test([_do count] == 3); + test([[_do objectAtIndex:0] count] == 1); + test([[[_do objectAtIndex:0] objectForKey:[NSNumber numberWithLong:999999140]] floatValue] == 3.14f); + test([[_do objectAtIndex:1] count] == 2); + test([[[_do objectAtIndex:1] objectForKey:[NSNumber numberWithLong:999999110]] floatValue] == -1.1f); + test([[[_do objectAtIndex:1] objectForKey:[NSNumber numberWithLong:999999111]] floatValue] == 123123.2f); + test([[_do objectAtIndex:2] count] == 3); + test([[[_do objectAtIndex:2] objectForKey:[NSNumber numberWithLong:999999110]] floatValue] == -1.1f); + test([[[_do objectAtIndex:2] objectForKey:[NSNumber numberWithLong:999999120]] floatValue] == -100.4f); + test([[[_do objectAtIndex:2] objectForKey:[NSNumber numberWithLong:999999130]] floatValue] == 0.5f); + } + + { + TestOperationsMutableStringStringDS *dsi1 = [TestOperationsMutableStringStringDS array]; + TestOperationsMutableStringStringDS *dsi2 = [TestOperationsMutableStringStringDS array]; + + TestOperationsMutableStringStringD *di1 = [TestOperationsMutableStringStringD dictionary]; + [di1 setObject:@"abc -1.1" forKey:@"foo"]; + [di1 setObject:@"abc 123123.2" forKey:@"bar"]; + TestOperationsMutableStringStringD *di2 = [TestOperationsMutableStringStringD dictionary]; + [di2 setObject:@"abc -1.1" forKey:@"foo"]; + [di2 setObject:@"abc -100.4" forKey:@"FOO"]; + [di2 setObject:@"abc 0.5" forKey:@"BAR"]; + TestOperationsMutableStringStringD *di3 = [TestOperationsMutableStringStringD dictionary]; + [di3 setObject:@"ABC -3.14" forKey:@"f00"]; + + [dsi1 addObject:di1]; + [dsi1 addObject:di2]; + [dsi2 addObject:di3]; + + TestOperationsMutableStringStringDS *_do; + TestOperationsStringStringDS *ro = [p opStringStringDS:dsi1 p2:dsi2 p3:&_do]; + + test([ro count] == 2); + test([[ro objectAtIndex:0] count] == 3); + test([[[ro objectAtIndex:0] objectForKey:@"foo"] isEqualToString:@"abc -1.1"]); + test([[[ro objectAtIndex:0] objectForKey:@"FOO"] isEqualToString:@"abc -100.4"]); + test([[[ro objectAtIndex:0] objectForKey:@"BAR"] isEqualToString:@"abc 0.5"]); + test([[ro objectAtIndex:1] count] == 2); + test([[[ro objectAtIndex:1] objectForKey:@"foo"] isEqualToString:@"abc -1.1"]); + test([[[ro objectAtIndex:1] objectForKey:@"bar"] isEqualToString:@"abc 123123.2"]); + test([_do count] == 3); + test([[_do objectAtIndex:0] count] == 1); + test([[[_do objectAtIndex:0] objectForKey:@"f00"] isEqualToString:@"ABC -3.14"]); + test([[_do objectAtIndex:1] count] == 2); + test([[[_do objectAtIndex:1] objectForKey:@"foo"] isEqualToString:@"abc -1.1"]); + test([[[_do objectAtIndex:1] objectForKey:@"bar"] isEqualToString:@"abc 123123.2"]); + test([[_do objectAtIndex:2] count] == 3); + test([[[_do objectAtIndex:2] objectForKey:@"foo"] isEqualToString:@"abc -1.1"]); + test([[[_do objectAtIndex:2] objectForKey:@"FOO"] isEqualToString:@"abc -100.4"]); + test([[[_do objectAtIndex:2] objectForKey:@"BAR"] isEqualToString:@"abc 0.5"]); + } + + { + TestOperationsMutableStringMyEnumDS *dsi1 = [TestOperationsMutableStringMyEnumDS array]; + TestOperationsMutableStringMyEnumDS *dsi2 = [TestOperationsMutableStringMyEnumDS array]; + + TestOperationsMutableStringMyEnumD *di1 = [TestOperationsMutableStringMyEnumD dictionary]; + [di1 setObject:[NSNumber numberWithInt:TestOperationsenum1] forKey:@"abc"]; + [di1 setObject:[NSNumber numberWithInt:TestOperationsenum2] forKey:@""]; + TestOperationsMutableStringMyEnumD *di2 = [TestOperationsMutableStringMyEnumD dictionary]; + [di2 setObject:[NSNumber numberWithInt:TestOperationsenum1] forKey:@"abc"]; + [di2 setObject:[NSNumber numberWithInt:TestOperationsenum3] forKey:@"querty"]; + [di2 setObject:[NSNumber numberWithInt:TestOperationsenum2] forKey:@"Hello!!"]; + TestOperationsMutableStringMyEnumD *di3 = [TestOperationsMutableStringMyEnumD dictionary]; + [di3 setObject:[NSNumber numberWithInt:TestOperationsenum1] forKey:@"Goodbye"]; + + [dsi1 addObject:di1]; + [dsi1 addObject:di2]; + [dsi2 addObject:di3]; + + TestOperationsMutableStringMyEnumDS *_do; + TestOperationsStringMyEnumDS *ro = [p opStringMyEnumDS:dsi1 p2:dsi2 p3:&_do]; + + test([ro count] == 2); + test([[ro objectAtIndex:0] count] == 3); + test([[[ro objectAtIndex:0] objectForKey:@"abc"] intValue] == TestOperationsenum1); + test([[[ro objectAtIndex:0] objectForKey:@"querty"] intValue] == TestOperationsenum3); + test([[[ro objectAtIndex:0] objectForKey:@"Hello!!"] intValue] == TestOperationsenum2); + test([[ro objectAtIndex:1] count] == 2); + test([[[ro objectAtIndex:1] objectForKey:@"abc"] intValue] == TestOperationsenum1); + test([[[ro objectAtIndex:1] objectForKey:@""] intValue] == TestOperationsenum2); + test([_do count] == 3); + test([[_do objectAtIndex:0] count] == 1); + test([[[_do objectAtIndex:0] objectForKey:@"Goodbye"] intValue] == TestOperationsenum1); + test([[_do objectAtIndex:1] count] == 2); + test([[[_do objectAtIndex:1] objectForKey:@"abc"] intValue] == TestOperationsenum1); + test([[[_do objectAtIndex:1] objectForKey:@""] intValue] == TestOperationsenum2); + test([[_do objectAtIndex:2] count] == 3); + test([[[_do objectAtIndex:2] objectForKey:@"abc"] intValue] == TestOperationsenum1); + test([[[_do objectAtIndex:2] objectForKey:@"querty"] intValue] == TestOperationsenum3); + test([[[_do objectAtIndex:2] objectForKey:@"Hello!!"] intValue] == TestOperationsenum2); + } + + { + TestOperationsMutableMyEnumStringDS *dsi1 = [TestOperationsMutableMyEnumStringDS array]; + TestOperationsMutableMyEnumStringDS *dsi2 = [TestOperationsMutableMyEnumStringDS array]; + + TestOperationsMutableMyEnumStringD *di1 = [TestOperationsMutableMyEnumStringD dictionary]; + [di1 setObject:@"abc" forKey:@(TestOperationsenum1)]; + TestOperationsMutableMyEnumStringD *di2 = [TestOperationsMutableMyEnumStringD dictionary]; + [di2 setObject:@"Hello!!" forKey:@(TestOperationsenum2)]; + [di2 setObject:@"querty" forKey:@(TestOperationsenum3)]; + TestOperationsMutableMyEnumStringD *di3 = [TestOperationsMutableMyEnumStringD dictionary]; + [di3 setObject:@"Goodbye" forKey:@(TestOperationsenum1)]; + + [dsi1 addObject:di1]; + [dsi1 addObject:di2]; + [dsi2 addObject:di3]; + + TestOperationsMutableMyEnumStringDS *_do; + TestOperationsMyEnumStringDS *ro = [p opMyEnumStringDS:dsi1 p2:dsi2 p3:&_do]; + + test([ro count] == 2); + test([[ro objectAtIndex:0] count] == 2); + test([[[ro objectAtIndex:0] objectForKey:@(TestOperationsenum2)] isEqualToString:@"Hello!!"]); + test([[[ro objectAtIndex:0] objectForKey:@(TestOperationsenum3)] isEqualToString:@"querty"]); + test([[ro objectAtIndex:1] count] == 1); + test([[[ro objectAtIndex:1] objectForKey:@(TestOperationsenum1)] isEqualToString:@"abc"]); + test([_do count] == 3); + test([[_do objectAtIndex:0] count] == 1); + test([[[_do objectAtIndex:0] objectForKey:@(TestOperationsenum1)] isEqualToString:@"Goodbye"]); + test([[_do objectAtIndex:1] count] == 1); + test([[[_do objectAtIndex:1] objectForKey:@(TestOperationsenum1)] isEqualToString:@"abc"]); + test([[_do objectAtIndex:2] count] == 2); + test([[[_do objectAtIndex:2] objectForKey:@(TestOperationsenum2)] isEqualToString:@"Hello!!"]); + test([[[_do objectAtIndex:2] objectForKey:@(TestOperationsenum3)] isEqualToString:@"querty"]); + } + + { + TestOperationsMutableMyStructMyEnumDS *dsi1 = [TestOperationsMutableMyStructMyEnumDS array]; + TestOperationsMutableMyStructMyEnumDS *dsi2 = [TestOperationsMutableMyStructMyEnumDS array]; + + TestOperationsMyStruct* s11 = [TestOperationsMyStruct myStruct:1 j:1]; + TestOperationsMyStruct* s12 = [TestOperationsMyStruct myStruct:1 j:2]; + TestOperationsMutableMyStructMyEnumD* di1 = [TestOperationsMutableMyStructMyEnumD dictionary]; + [di1 setObject:@(TestOperationsenum1) forKey:s11]; + [di1 setObject:@(TestOperationsenum2) forKey:s12]; + + TestOperationsMyStruct* s22 = [TestOperationsMyStruct myStruct:2 j:2]; + TestOperationsMyStruct* s23 = [TestOperationsMyStruct myStruct:2 j:3]; + TestOperationsMutableMyStructMyEnumD* di2 = [TestOperationsMutableMyStructMyEnumD dictionary]; + [di2 setObject:@(TestOperationsenum1) forKey:s11]; + [di2 setObject:@(TestOperationsenum3) forKey:s22]; + [di2 setObject:@(TestOperationsenum2) forKey:s23]; + + TestOperationsMutableMyStructMyEnumD* di3 = [TestOperationsMutableMyStructMyEnumD dictionary]; + [di3 setObject:@(TestOperationsenum3) forKey:s23]; + + [dsi1 addObject:di1]; + [dsi1 addObject:di2]; + [dsi2 addObject:di3]; + + TestOperationsMutableMyStructMyEnumDS* _do; + TestOperationsMyStructMyEnumDS* ro = [p opMyStructMyEnumDS:dsi1 p2:dsi2 p3:&_do]; + + test([ro count] == 2); + test([[ro objectAtIndex:0] count] == 3); + test([[[ro objectAtIndex:0] objectForKey:s11] intValue] == TestOperationsenum1); + test([[[ro objectAtIndex:0] objectForKey:s22] intValue] == TestOperationsenum3); + test([[[ro objectAtIndex:0] objectForKey:s23] intValue] == TestOperationsenum2); + test([[ro objectAtIndex:1] count] == 2); + test([[[ro objectAtIndex:1] objectForKey:s11] intValue] == TestOperationsenum1); + test([[[ro objectAtIndex:1] objectForKey:s12] intValue] == TestOperationsenum2); + test([_do count] == 3); + test([[_do objectAtIndex:0] count] == 1); + test([[[_do objectAtIndex:0] objectForKey:s23] intValue] == TestOperationsenum3); + test([[_do objectAtIndex:1] count] == 2); + test([[[_do objectAtIndex:1] objectForKey:s11] intValue] == TestOperationsenum1); + test([[[_do objectAtIndex:1] objectForKey:s12] intValue] == TestOperationsenum2); + test([[_do objectAtIndex:2] count] == 3); + test([[[_do objectAtIndex:2] objectForKey:s11] intValue] == TestOperationsenum1); + test([[[_do objectAtIndex:2] objectForKey:s22] intValue] == TestOperationsenum3); + test([[[_do objectAtIndex:2] objectForKey:s23] intValue] == TestOperationsenum2); + } + + { + TestOperationsMutableByteByteSD *sdi1 = [TestOperationsMutableByteByteSD dictionary]; + TestOperationsMutableByteByteSD *sdi2 = [TestOperationsMutableByteByteSD dictionary]; + + ICEByte buf1[] = { 0x01, 0x11 }; + ICEByte buf2[] = { 0x12 }; + ICEByte buf3[] = { 0xf2, 0xf3 }; + + TestOperationsMutableByteS *si1 = [TestOperationsMutableBoolS data]; + TestOperationsMutableBoolS *si2 = [TestOperationsMutableBoolS data]; + TestOperationsMutableBoolS *si3 = [TestOperationsMutableBoolS data]; + + [si1 appendBytes:buf1 length:sizeof(buf1)]; + [si2 appendBytes:buf2 length:sizeof(buf2)]; + [si3 appendBytes:buf3 length:sizeof(buf3)]; + + [sdi1 setObject:si1 forKey:[NSNumber numberWithUnsignedChar:(ICEByte)0x01]]; + [sdi1 setObject:si2 forKey:[NSNumber numberWithUnsignedChar:(ICEByte)0x22]]; + [sdi2 setObject:si3 forKey:[NSNumber numberWithUnsignedChar:(ICEByte)0xf1]]; + + TestOperationsMutableByteByteSD *_do; + TestOperationsByteByteSD *ro = [p opByteByteSD:sdi1 p2:sdi2 p3:&_do]; + + const ICEByte *p; + test([_do count] == 1); + test([[_do objectForKey:[NSNumber numberWithUnsignedChar:(ICEByte)0xf1]] length] / sizeof(ICEByte) == 2); + p = [[_do objectForKey:[NSNumber numberWithUnsignedChar:(ICEByte)0xf1]] bytes]; + test(p[0] == 0xf2); + test(p[1] == 0xf3); + test([ro count] == 3); + test([[ro objectForKey:[NSNumber numberWithUnsignedChar:(ICEByte)0x01]] length] / sizeof(ICEByte) == 2); + p = [[ro objectForKey:[NSNumber numberWithUnsignedChar:(ICEByte)0x01]] bytes]; + test(p[0] == 0x01); + test(p[1] == 0x11); + test([[ro objectForKey:[NSNumber numberWithUnsignedChar:(ICEByte)0x22]] length] / sizeof(ICEByte) == 1); + p = [[ro objectForKey:[NSNumber numberWithUnsignedChar:(ICEByte)0x22]] bytes]; + test(p[0] == 0x12); + test([[ro objectForKey:[NSNumber numberWithUnsignedChar:(ICEByte)0xf1]] length] / sizeof(ICEByte) == 2); + p = [[ro objectForKey:[NSNumber numberWithUnsignedChar:(ICEByte)0xf1]] bytes]; + test(p[0] == 0xf2); + test(p[1] == 0xf3); + } + + { + TestOperationsMutableBoolBoolSD *sdi1 = [TestOperationsMutableBoolBoolSD dictionary]; + TestOperationsMutableBoolBoolSD *sdi2 = [TestOperationsMutableBoolBoolSD dictionary]; + + BOOL buf1[] = { YES, NO }; + BOOL buf2[] = { NO, YES, YES }; + + TestOperationsMutableBoolS *si1 = [TestOperationsMutableBoolS data]; + TestOperationsMutableBoolS *si2 = [TestOperationsMutableBoolS data]; + + [si1 appendBytes:buf1 length:sizeof(buf1)]; + [si2 appendBytes:buf2 length:sizeof(buf2)]; + + [sdi1 setObject:si1 forKey:[NSNumber numberWithBool:NO]]; + [sdi1 setObject:si2 forKey:[NSNumber numberWithBool:YES]]; + [sdi2 setObject:si1 forKey:[NSNumber numberWithBool:NO]]; + + TestOperationsMutableBoolBoolSD *_do; + TestOperationsBoolBoolSD *ro = [p opBoolBoolSD:sdi1 p2:sdi2 p3:&_do]; + + const BOOL *p; + test([_do count] == 1); + test([[_do objectForKey:[NSNumber numberWithBool:NO]] length] / sizeof(BOOL) == 2); + p = [[_do objectForKey:[NSNumber numberWithBool:NO]] bytes]; + test(p[0] == YES); + test(p[1] == NO); + test([ro count] == 2); + test([[ro objectForKey:[NSNumber numberWithBool:NO]] length] / sizeof(BOOL) == 2); + p = [[ro objectForKey:[NSNumber numberWithBool:NO]] bytes]; + test(p[0] == YES); + test(p[1] == NO); + test([[ro objectForKey:[NSNumber numberWithBool:YES]] length] / sizeof(BOOL) == 3); + p = [[ro objectForKey:[NSNumber numberWithBool:YES]] bytes]; + test(p[0] == NO); + test(p[1] == YES); + test(p[2] == YES); + } + + { + TestOperationsMutableShortShortSD *sdi1 = [TestOperationsMutableShortShortSD dictionary]; + TestOperationsMutableShortShortSD *sdi2 = [TestOperationsMutableShortShortSD dictionary]; + + ICEShort buf1[] = { 1, 2, 3 }; + ICEShort buf2[] = { 4, 5 }; + ICEShort buf3[] = { 6, 7 }; + + TestOperationsMutableShortS *si1 = [TestOperationsMutableShortS data]; + TestOperationsMutableShortS *si2 = [TestOperationsMutableShortS data]; + TestOperationsMutableShortS *si3 = [TestOperationsMutableShortS data]; + + [si1 appendBytes:buf1 length:sizeof(buf1)]; + [si2 appendBytes:buf2 length:sizeof(buf2)]; + [si3 appendBytes:buf3 length:sizeof(buf3)]; + + [sdi1 setObject:si1 forKey:[NSNumber numberWithShort:1]]; + [sdi1 setObject:si2 forKey:[NSNumber numberWithShort:2]]; + [sdi2 setObject:si3 forKey:[NSNumber numberWithShort:4]]; + + TestOperationsMutableShortShortSD *_do; + TestOperationsShortShortSD *ro = [p opShortShortSD:sdi1 p2:sdi2 p3:&_do]; + + const ICEShort *p; + test([_do count] == 1); + test([[_do objectForKey:[NSNumber numberWithShort:4]] length] / sizeof(ICEShort) == 2); + p = [[_do objectForKey:[NSNumber numberWithShort:4]] bytes]; + test(p[0] == 6); + test(p[1] == 7); + test([ro count] == 3); + test([[ro objectForKey:[NSNumber numberWithShort:1]] length] / sizeof(ICEShort) == 3); + p = [[ro objectForKey:[NSNumber numberWithShort:1]] bytes]; + test(p[0] == 1); + test(p[1] == 2); + test(p[2] == 3); + test([[ro objectForKey:[NSNumber numberWithShort:2]] length] / sizeof(ICEShort) == 2); + p = [[ro objectForKey:[NSNumber numberWithShort:2]] bytes]; + test(p[0] == 4); + test(p[1] == 5); + test([[ro objectForKey:[NSNumber numberWithShort:4]] length] / sizeof(ICEShort) == 2); + p = [[ro objectForKey:[NSNumber numberWithShort:4]] bytes]; + test(p[0] == 6); + test(p[1] == 7); + } + + { + TestOperationsMutableIntIntSD *sdi1 = [TestOperationsMutableIntIntSD dictionary]; + TestOperationsMutableIntIntSD *sdi2 = [TestOperationsMutableIntIntSD dictionary]; + + ICEInt buf1[] = { 100, 200, 300 }; + ICEInt buf2[] = { 400, 500 }; + ICEInt buf3[] = { 600, 700 }; + + TestOperationsMutableIntS *si1 = [TestOperationsMutableIntS data]; + TestOperationsMutableIntS *si2 = [TestOperationsMutableIntS data]; + TestOperationsMutableIntS *si3 = [TestOperationsMutableIntS data]; + + [si1 appendBytes:buf1 length:sizeof(buf1)]; + [si2 appendBytes:buf2 length:sizeof(buf2)]; + [si3 appendBytes:buf3 length:sizeof(buf3)]; + + [sdi1 setObject:si1 forKey:[NSNumber numberWithInt:100]]; + [sdi1 setObject:si2 forKey:[NSNumber numberWithInt:200]]; + [sdi2 setObject:si3 forKey:[NSNumber numberWithInt:400]]; + + TestOperationsMutableIntIntSD *_do; + TestOperationsIntIntSD *ro = [p opIntIntSD:sdi1 p2:sdi2 p3:&_do]; + + const ICEInt *p; + test([_do count] == 1); + test([[_do objectForKey:[NSNumber numberWithInt:400]] length] / sizeof(ICEInt) == 2); + p = [[_do objectForKey:[NSNumber numberWithInt:400]] bytes]; + test(p[0] == 600); + test(p[1] == 700); + test([ro count] == 3); + test([[ro objectForKey:[NSNumber numberWithInt:100]] length] / sizeof(ICEInt) == 3); + p = [[ro objectForKey:[NSNumber numberWithInt:100]] bytes]; + test(p[0] == 100); + test(p[1] == 200); + test(p[2] == 300); + test([[ro objectForKey:[NSNumber numberWithInt:200]] length] / sizeof(ICEInt) == 2); + p = [[ro objectForKey:[NSNumber numberWithInt:200]] bytes]; + test(p[0] == 400); + test(p[1] == 500); + test([[ro objectForKey:[NSNumber numberWithInt:400]] length] / sizeof(ICEInt) == 2); + p = [[ro objectForKey:[NSNumber numberWithInt:400]] bytes]; + test(p[0] == 600); + test(p[1] == 700); + } + + { + TestOperationsMutableLongLongSD *sdi1 = [TestOperationsMutableLongLongSD dictionary]; + TestOperationsMutableLongLongSD *sdi2 = [TestOperationsMutableLongLongSD dictionary]; + + ICELong buf1[] = { 999999110, 999999111, 999999110 }; + ICELong buf2[] = { 999999120, 999999130 }; + ICELong buf3[] = { 999999110, 999999120 }; + + TestOperationsMutableLongS *si1 = [TestOperationsMutableLongS data]; + TestOperationsMutableLongS *si2 = [TestOperationsMutableLongS data]; + TestOperationsMutableLongS *si3 = [TestOperationsMutableLongS data]; + + [si1 appendBytes:buf1 length:sizeof(buf1)]; + [si2 appendBytes:buf2 length:sizeof(buf2)]; + [si3 appendBytes:buf3 length:sizeof(buf3)]; + + [sdi1 setObject:si1 forKey:[NSNumber numberWithLong:999999990]]; + [sdi1 setObject:si2 forKey:[NSNumber numberWithLong:999999991]]; + [sdi2 setObject:si3 forKey:[NSNumber numberWithLong:999999992]]; + + TestOperationsMutableLongLongSD *_do; + TestOperationsLongLongSD *ro = [p opLongLongSD:sdi1 p2:sdi2 p3:&_do]; + + const ICELong *p; + test([_do count] == 1); + test([[_do objectForKey:[NSNumber numberWithLong:999999992]] length] / sizeof(ICELong) == 2); + p = [[_do objectForKey:[NSNumber numberWithLong:999999992]] bytes]; + test(p[0] == 999999110); + test(p[1] == 999999120); + test([ro count] == 3); + test([[ro objectForKey:[NSNumber numberWithLong:999999990]] length] / sizeof(ICELong) == 3); + p = [[ro objectForKey:[NSNumber numberWithLong:999999990]] bytes]; + test(p[0] == 999999110); + test(p[1] == 999999111); + test(p[2] == 999999110); + test([[ro objectForKey:[NSNumber numberWithLong:999999991]] length] / sizeof(ICELong) == 2); + p = [[ro objectForKey:[NSNumber numberWithLong:999999991]] bytes]; + test(p[0] == 999999120); + test(p[1] == 999999130); + test([[ro objectForKey:[NSNumber numberWithLong:999999992]] length] / sizeof(ICELong) == 2); + p = [[ro objectForKey:[NSNumber numberWithLong:999999992]] bytes]; + test(p[0] == 999999110); + test(p[1] == 999999120); + } + + { + TestOperationsMutableStringFloatSD *sdi1 = [TestOperationsMutableStringFloatSD dictionary]; + TestOperationsMutableStringFloatSD *sdi2 = [TestOperationsMutableStringFloatSD dictionary]; + + ICEFloat buf1[] = { -1.1f, 123123.2f, 100.0f }; + ICEFloat buf2[] = { 42.24f, -1.61f }; + ICEFloat buf3[] = { -3.14, 3.14 }; + + TestOperationsMutableFloatS *si1 = [TestOperationsMutableFloatS data]; + TestOperationsMutableFloatS *si2 = [TestOperationsMutableFloatS data]; + TestOperationsMutableFloatS *si3 = [TestOperationsMutableFloatS data]; + + [si1 appendBytes:buf1 length:sizeof(buf1)]; + [si2 appendBytes:buf2 length:sizeof(buf2)]; + [si3 appendBytes:buf3 length:sizeof(buf3)]; + + [sdi1 setObject:si1 forKey:@"abc"]; + [sdi1 setObject:si2 forKey:@"ABC"]; + [sdi2 setObject:si3 forKey:@"aBc"]; + + TestOperationsMutableStringFloatSD *_do; + TestOperationsStringFloatSD *ro = [p opStringFloatSD:sdi1 p2:sdi2 p3:&_do]; + + const ICEFloat *p; + test([_do count] == 1); + test([[_do objectForKey:@"aBc"] length] / sizeof(ICEFloat) == 2); + p = [[_do objectForKey:@"aBc"] bytes]; + test(p[0] == -3.14f); + test(p[1] == 3.14f); + test([ro count] == 3); + test([[ro objectForKey:@"abc"] length] / sizeof(ICEFloat) == 3); + p = [[ro objectForKey:@"abc"] bytes]; + test(p[0] == -1.1f); + test(p[1] == 123123.2f); + test(p[2] == 100.0f); + test([[ro objectForKey:@"ABC"] length] / sizeof(ICEFloat) == 2); + p = [[ro objectForKey:@"ABC"] bytes]; + test(p[0] == 42.24f); + test(p[1] == -1.61f); + test([[ro objectForKey:@"aBc"] length] / sizeof(ICEFloat) == 2); + p = [[ro objectForKey:@"aBc"] bytes]; + test(p[0] == -3.14f); + test(p[1] == 3.14f); + } + + { + TestOperationsMutableStringDoubleSD *sdi1 = [TestOperationsMutableStringDoubleSD dictionary]; + TestOperationsMutableStringDoubleSD *sdi2 = [TestOperationsMutableStringDoubleSD dictionary]; + + ICEDouble buf1[] = { 1.1E10, 1.2E10, 1.3E10 }; + ICEDouble buf2[] = { 1.4E10, 1.5E10 }; + ICEDouble buf3[] = { 1.6E10, 1.7E10 }; + + TestOperationsMutableDoubleS *si1 = [TestOperationsMutableDoubleS data]; + TestOperationsMutableDoubleS *si2 = [TestOperationsMutableDoubleS data]; + TestOperationsMutableDoubleS *si3 = [TestOperationsMutableDoubleS data]; + + [si1 appendBytes:buf1 length:sizeof(buf1)]; + [si2 appendBytes:buf2 length:sizeof(buf2)]; + [si3 appendBytes:buf3 length:sizeof(buf3)]; + + [sdi1 setObject:si1 forKey:@"Hello!!"]; + [sdi1 setObject:si2 forKey:@"Goodbye"]; + [sdi2 setObject:si3 forKey:@""]; + + TestOperationsMutableStringDoubleSD *_do; + TestOperationsStringDoubleSD *ro = [p opStringDoubleSD:sdi1 p2:sdi2 p3:&_do]; + + const ICEDouble *p; + test([_do count] == 1); + test([[_do objectForKey:@""] length] / sizeof(ICEDouble) == 2); + p = [[_do objectForKey:@""] bytes]; + test(p[0] == 1.6E10); + test(p[1] == 1.7E10); + test([ro count] == 3); + test([[ro objectForKey:@"Hello!!"] length] / sizeof(ICEDouble) == 3); + p = [[ro objectForKey:@"Hello!!"] bytes]; + test(p[0] == 1.1E10); + test(p[1] == 1.2E10); + test(p[2] == 1.3E10); + test([[ro objectForKey:@"Goodbye"] length] / sizeof(ICEDouble) == 2); + p = [[ro objectForKey:@"Goodbye"] bytes]; + test(p[0] == 1.4E10); + test(p[1] == 1.5E10); + test([[ro objectForKey:@""] length] / sizeof(ICEDouble) == 2); + p = [[ro objectForKey:@""] bytes]; + test(p[0] == 1.6E10); + test(p[1] == 1.7E10); + } + + { + TestOperationsMutableStringStringSD *sdi1 = [TestOperationsMutableStringStringSD dictionary]; + TestOperationsMutableStringStringSD *sdi2 = [TestOperationsMutableStringStringSD dictionary]; + + TestOperationsMutableStringS *si1 = [TestOperationsMutableStringS array]; + TestOperationsMutableStringS *si2 = [TestOperationsMutableStringS array]; + TestOperationsMutableStringS *si3 = [TestOperationsMutableStringS array]; + + [si1 addObject:@"abc"]; + [si1 addObject:@"de"]; + [si1 addObject:@"fghi"]; + [si2 addObject:@"xyz"]; + [si2 addObject:@"or"]; + [si3 addObject:@"and"]; + [si3 addObject:@"xor"]; + + [sdi1 setObject:si1 forKey:@"abc"]; + [sdi1 setObject:si2 forKey:@"def"]; + [sdi2 setObject:si3 forKey:@"ghi"]; + + TestOperationsMutableStringStringSD *_do; + TestOperationsStringStringSD *ro = [p opStringStringSD:sdi1 p2:sdi2 p3:&_do]; + + test([[_do objectForKey:@"ghi"] count] == 2); + test([[[_do objectForKey:@"ghi"] objectAtIndex:0] isEqualToString:@"and"]); + test([[[_do objectForKey:@"ghi"] objectAtIndex:1] isEqualToString:@"xor"]); + test([ro count] == 3); + test([[ro objectForKey:@"abc"] count] == 3); + test([[[ro objectForKey:@"abc"] objectAtIndex:0] isEqualToString:@"abc"]); + test([[[ro objectForKey:@"abc"] objectAtIndex:1] isEqualToString:@"de"]); + test([[[ro objectForKey:@"abc"] objectAtIndex:2] isEqualToString:@"fghi"]); + test([[ro objectForKey:@"def"] count] == 2); + test([[[ro objectForKey:@"def"] objectAtIndex:0] isEqualToString:@"xyz"]); + test([[[ro objectForKey:@"def"] objectAtIndex:1] isEqualToString:@"or"]); + test([[ro objectForKey:@"ghi"] count] == 2); + test([[[ro objectForKey:@"ghi"] objectAtIndex:0] isEqualToString:@"and"]); + test([[[ro objectForKey:@"ghi"] objectAtIndex:1] isEqualToString:@"xor"]); + } + + { + TestOperationsMutableMyEnumMyEnumSD *sdi1 = [TestOperationsMutableMyEnumMyEnumSD dictionary]; + TestOperationsMutableMyEnumMyEnumSD *sdi2 = [TestOperationsMutableMyEnumMyEnumSD dictionary]; + + + TestOperationsMyEnum buf1[] = { TestOperationsenum1, TestOperationsenum1, TestOperationsenum2 }; + TestOperationsMyEnum buf2[] = { TestOperationsenum1, TestOperationsenum2 }; + TestOperationsMyEnum buf3[] = { TestOperationsenum3, TestOperationsenum3 }; + + TestOperationsMutableMyEnumS *si1 = [TestOperationsMutableMyEnumS data]; + TestOperationsMutableMyEnumS *si2 = [TestOperationsMutableMyEnumS data]; + TestOperationsMutableMyEnumS *si3 = [TestOperationsMutableMyEnumS data]; + + [si1 appendBytes:buf1 length:sizeof(buf1)]; + [si2 appendBytes:buf2 length:sizeof(buf2)]; + [si3 appendBytes:buf3 length:sizeof(buf3)]; + + [sdi1 setObject:si1 forKey:@(TestOperationsenum3)]; + [sdi1 setObject:si2 forKey:@(TestOperationsenum2)]; + [sdi2 setObject:si3 forKey:@(TestOperationsenum1)]; + + TestOperationsMutableMyEnumMyEnumSD *_do; + TestOperationsMyEnumMyEnumSD *ro = [p opMyEnumMyEnumSD:sdi1 p2:sdi2 p3:&_do]; + + const TestOperationsMyEnum *p; + test([_do count] == 1); + test([[_do objectForKey:@(TestOperationsenum1)] length] / sizeof(TestOperationsMyEnum) == 2); + p = [[_do objectForKey:@(TestOperationsenum1)] bytes]; + test(p[0] == TestOperationsenum3); + test(p[1] == TestOperationsenum3); + test([ro count] == 3); + test([[ro objectForKey:@(TestOperationsenum3)] length] / sizeof(TestOperationsMyEnum) == 3); + p = [[ro objectForKey:@(TestOperationsenum3)] bytes]; + test(p[0] == TestOperationsenum1); + test(p[1] == TestOperationsenum1); + test(p[2] == TestOperationsenum2); + test([[ro objectForKey:@(TestOperationsenum2)] length] / sizeof(TestOperationsMyEnum) == 2); + p = [[ro objectForKey:@(TestOperationsenum2)] bytes]; + test(p[0] == TestOperationsenum1); + test(p[1] == TestOperationsenum2); + test([[ro objectForKey:@(TestOperationsenum1)] length] / sizeof(TestOperationsMyEnum) == 2); + p = [[ro objectForKey:@(TestOperationsenum1)] bytes]; + test(p[0] == TestOperationsenum3); + test(p[1] == TestOperationsenum3); + } + + { + const int lengths[] = { 0, 1, 2, 126, 127, 128, 129, 253, 254, 255, 256, 257, 1000 }; + + int l; + for(l = 0; l != sizeof(lengths) / sizeof(*lengths); ++l) + { + TestOperationsMutableIntS *s = [TestOperationsMutableIntS dataWithLength:(lengths[l] * sizeof(ICEInt))]; + ICEInt *ip = (ICEInt *)[s bytes]; + int i; + for(i = 0; i < lengths[l]; ++i) + { + *ip++ = i; + } + TestOperationsIntS *r = [p opIntS:s]; + test([r length] == lengths[l] * sizeof(ICEInt)); + const ICEInt *rp = [r bytes]; + int j; + for(j = 0; j < [r length] / sizeof(ICEInt); ++j) + { + test(rp[j] == -j); + } + } + } + + { + ICEMutableContext *ctx = [ICEMutableContext dictionary]; + [ctx setObject:@"ONE" forKey:@"one"]; + [ctx setObject:@"TWO" forKey:@"two"]; + [ctx setObject:@"THREE" forKey:@"three"]; + { + ICEContext *r = [p opContext]; + test([[p ice_getContext] count] == 0); + test(![r isEqual:ctx]); + } + { + ICEContext *r = [p opContext:ctx]; + test([[p ice_getContext] count] == 0); + test([r isEqual:ctx]); + } + { + id<TestOperationsMyClassPrx> p2 = [TestOperationsMyClassPrx checkedCast:[p ice_context:ctx]]; + test([[p2 ice_getContext] isEqual:ctx]); + ICEContext *r = [p2 opContext]; + test([r isEqual:ctx]); + r = [p2 opContext:ctx]; + test([r isEqual:ctx]); + } + } + + if([p ice_getConnection]) + { + // + // TestOperations implicit context propagation + // + NSString *impls[] = { @"Shared", @"PerThread" }; + int i; + for(i = 0; i < 2; i++) + { + ICEInitializationData *initData = [ICEInitializationData initializationData]; + initData.properties = [[communicator getProperties] clone]; + [initData.properties setProperty:@"Ice.ImplicitContext" value:impls[i]]; + + id<ICECommunicator> ic = [ICEUtil createCommunicator:initData]; + + ICEMutableContext *ctx = [ICEMutableContext dictionary]; + [ctx setObject:@"ONE" forKey:@"one" ]; + [ctx setObject:@"TWO" forKey:@"two" ]; + [ctx setObject:@"THREE" forKey:@"three"]; + + id<TestOperationsMyClassPrx> p = [TestOperationsMyClassPrx uncheckedCast:[ic stringToProxy:@"test:default -p 12010"]]; + + [[ic getImplicitContext] setContext:ctx]; + test([[[ic getImplicitContext] getContext] isEqual:ctx]); + test([[p opContext] isEqual:ctx]); + + test([[ic getImplicitContext] get:@"zero"] == nil); + [[ic getImplicitContext] put:@"zero" value:@"ZERO"]; + test([[[ic getImplicitContext] get:@"zero"] isEqualToString:@"ZERO"]); + + ctx = [[ic getImplicitContext] getContext]; + test([[p opContext] isEqual:ctx]); + + ICEMutableContext *prxContext = [ICEMutableContext dictionary]; + [prxContext setObject:@"UN" forKey:@"one"]; + [prxContext setObject:@"QUATRE" forKey:@"four"]; + + ICEMutableContext *combined = [ICEMutableContext dictionaryWithDictionary:ctx]; + [combined addEntriesFromDictionary:prxContext]; + + p = [TestOperationsMyClassPrx uncheckedCast:[p ice_context:prxContext]]; + + [[ic getImplicitContext] setContext:[ICEContext dictionary]]; + test([[p opContext] isEqualToDictionary:prxContext]); + + [[ic getImplicitContext] setContext:ctx]; + test([[p opContext] isEqualToDictionary:combined]); + + test([[[ic getImplicitContext] get:@"one"] isEqualToString:@"ONE"]); + [[ic getImplicitContext] remove:@"one"]; + + if([impls[i] isEqualToString:@"PerThread"]) + { + PerThreadContextInvokeThread* thread = [PerThreadContextInvokeThread create:[p ice_context:[ICEMutableContext dictionary]]]; + [thread start]; + [thread join]; + } + + [[ic getImplicitContext] setContext:[ICEContext dictionary]]; + [ic destroy]; + } + } + + { + ICEDouble d = 1278312346.0 / 13.0; + TestOperationsMutableDoubleS *ds = [TestOperationsMutableDoubleS dataWithLength:(5 * sizeof(ICEDouble))]; + ICEDouble *pb = (ICEDouble *)[ds bytes]; + int i = 5; + while(i-- > 0) + { + *pb++ = d; + } + [p opDoubleMarshaling:d p2:ds]; + } + + [p opIdempotent]; + + [p opNonmutating]; + + // + // TestOperationss below are for Objective-C only. They test that we do the right thing if NSNull + // is passed as part of the sequence or dictionary. + // + @try + { + { + TestOperationsStringS *s = [p getNSNullStringSeq]; + test([s count] == 2); + test([[s objectAtIndex:0] isEqualToString:@"first"]); + test([[s objectAtIndex:1] isEqualToString:@""]); + } + + { + TestOperationsAS *s = [p getNSNullASeq]; + test([s count] == 2); + test(((TestOperationsA *)[s objectAtIndex:0]).i == 99); + test([s objectAtIndex:1] == [NSNull null]); + } + + { + TestOperationsStructS *seq = [p getNSNullStructSeq]; + test([seq count] == 2); + TestOperationsStructure *s = [seq objectAtIndex:0]; + test(s.p == nil); + test(s.e == TestOperationsenum2); + test([s.s.s isEqualToString:@"Hello"]); + s = [seq objectAtIndex:1]; + test(s.p == nil); + test(s.e == TestOperationsenum1); + test([s.s.s isEqualToString:@""]); + } + + { + TestOperationsStringSS *seq = [p getNSNullStringSeqSeq]; + test([seq count] == 2); + TestOperationsStringS *s = [seq objectAtIndex:0]; + test([s count] == 1); + test([(NSString *)[s objectAtIndex:0] isEqualToString:@"first"]); + s = [seq objectAtIndex:1]; + test([s count] == 0); + } + + { + TestOperationsStringStringD *d = [p getNSNullStringStringDict]; + test([d count] == 2); + test([(NSString *)[d objectForKey:@"one"] isEqualToString:@"ONE"]); + test([(NSString *)[d objectForKey:@"two"] isEqualToString:@""]); + } + + { + @try + { + TestOperationsMutableStringStringD *d = [TestOperationsMutableStringStringD dictionary]; + [d setObject:@"bad key" forKey:[NSNull null]]; + [p putNSNullStringStringDict:d]; + test(NO); + } + @catch(ICEMarshalException *) + { + // Expected + } + } + + { + @try + { + TestOperationsMutableShortIntD *d = [TestOperationsMutableShortIntD dictionary]; + [d setObject:[NSNull null] forKey:[NSNumber numberWithInt:1]]; + [p putNSNullShortIntDict:d]; + test(NO); + } + @catch(ICEMarshalException *) + { + // Expected + } + } + + { + @try + { + TestOperationsMutableStringMyEnumD *d = [TestOperationsMutableStringMyEnumD dictionary]; + [d setObject:[NSNull null] forKey:@"key"]; + [p putNSNullStringMyEnumDict:d]; + test(NO); + } + @catch(ICEMarshalException *) + { + // Expected + } + } + } + @catch(ICEOperationNotExistException *) + { + // Client is talking to non-Objective-C server. + } +} diff --git a/objective-c/test/Ice/operations/TwowaysNewAMI.m b/objective-c/test/Ice/operations/TwowaysNewAMI.m new file mode 100644 index 00000000000..a3eade4e93c --- /dev/null +++ b/objective-c/test/Ice/operations/TwowaysNewAMI.m @@ -0,0 +1,2077 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <TestCommon.h> +#import <OperationsTest.h> +#import <limits.h> +#import <float.h> + +#import <Foundation/Foundation.h> + +@interface TestNewAMIOperationsCallback : NSObject +{ + BOOL called; + NSCondition* cond; +} +-(BOOL) check; +-(void) called; +@end + +@implementation TestNewAMIOperationsCallback +-(id) init +{ + self = [super init]; + if(!self) + { + return nil; + } + cond = [[NSCondition alloc] init]; + return self; +} + ++(id) create +{ + return ICE_AUTORELEASE([[TestNewAMIOperationsCallback alloc] init]); +} + +#if defined(__clang__) && !__has_feature(objc_arc) +-(void) dealloc +{ + [cond release]; + [super dealloc]; +} +#endif + +-(BOOL) check +{ + [cond lock]; + while(!called) + { + if(![cond waitUntilDate:[NSDate dateWithTimeIntervalSinceNow:50]]) + { + return NO; + } + } + called = NO; + [cond unlock]; + return YES; +} +-(void) called +{ + [cond lock]; + called = YES; + [cond signal]; + [cond unlock]; +} +-(void) opVoidExResponse +{ + test(NO); +} +-(void) opVoidExException:(ICEException*)ex +{ + test([ex isKindOfClass:[ICENoEndpointException class]]); + [self called]; +} +-(void) opVoidResponse +{ + [self called]; +} +-(void) opVoidException:(ICEException*)ex +{ + test(NO); +} +-(void) opByteExResponse:(ICEByte)ret p3:(ICEByte)p3 +{ + test(NO); +} +-(void) opByteExException:(ICEException*)ex +{ + test([ex isKindOfClass:[ICENoEndpointException class]]); + [self called]; +} +-(void) opByteResponse:(ICEByte)ret p3:(ICEByte)p3 +{ + [self called]; +} +-(void) opByteException:(ICEException*)ex +{ + test(NO); +} +-(void) opBoolResponse:(BOOL)r p3:(BOOL)b +{ + test(b); + test(!r); + [self called]; +} +-(void) opBoolException:(ICEException*)ex +{ + test(NO); +} +-(void) opShortIntLongResponse:(ICELong)r p4:(ICEShort)s p5:(ICEInt)i p6:(ICELong)l +{ + test(s == 10); + test(i == 11); + test(l == 12); + test(r == 12); + [self called]; +} +-(void) opShortIntLongException:(ICEException*)ex +{ + test(NO); +} +-(void) opFloatDoubleResponse:(ICEDouble)r p3:(ICEFloat)f p4:(ICEDouble)d +{ + test(f == 3.14f); + test(d == 1.1E10); + test(r == 1.1E10); + [self called]; +} +-(void) opFloatDoubleException:(ICEException*)ex +{ + test(NO); +} +-(void) opStringResponse:(NSString*)r p3:(NSString*)s +{ + test([s isEqualToString:@"world hello"]); + test([r isEqualToString:@"hello world"]); + [self called]; +} + +-(void) opStringException:(ICEException*)ex +{ + test(NO); +}; + +-(void) opMyEnumResponse:(TestOperationsMyEnum)r p2:(TestOperationsMyEnum)e +{ + test(e == TestOperationsenum2); + test(r == TestOperationsenum3); + [self called]; +} + +-(void) opMyEnumException:(ICEException*)ex +{ + test(NO); +} + +-(void) opMyClassResponse:(id<TestOperationsMyClassPrx>)r p2:(id<TestOperationsMyClassPrx>)c1 p3:(id<TestOperationsMyClassPrx>)c2 +{ + test([[c1 ice_getIdentity] isEqual:[[c1 ice_getCommunicator] stringToIdentity:@"test"]]); + test([[c2 ice_getIdentity] isEqual:[[c1 ice_getCommunicator] stringToIdentity:@"noSuchIdentity"]]); + test([[r ice_getIdentity] isEqual:[[c1 ice_getCommunicator] stringToIdentity:@"test"]]); + // We can't do the callbacks below in connection serialization mode. + if([[[c1 ice_getCommunicator] getProperties] getPropertyAsInt:@"Ice.ThreadPool.Client.Serialize"]) + { + [r opVoid]; + [c1 opVoid]; + @try + { + [c2 opVoid]; + test(NO); + } + @catch(ICEObjectNotExistException*) + { + } + } + [self called]; +} + +-(void) opMyClassException:(ICEException*)ex +{ + test(NO); +} + +-(void) opStructResponse:(TestOperationsStructure*)rso p3:(TestOperationsStructure*)so +{ + test(rso.p == nil); + test(rso.e == TestOperationsenum2); + test([rso.s.s isEqualToString:@"def"]); + test([so e] == TestOperationsenum3); + test(so.p != nil); + test([so.s.s isEqualToString:@"a new string"]); + // We can't do the callbacks below in connection serialization mode. + if([[[so.p ice_getCommunicator] getProperties] getPropertyAsInt:@"Ice.ThreadPool.Client.Serialize"]) + { + [so.p opVoid]; + } + [self called]; +} + +-(void) opStructException:(ICEException*)ex +{ + test(NO); +} + +-(void) opByteSResponse:(TestOperationsByteS*)rso p3:(TestOperationsByteS*)bso +{ + test([bso length] == 4); + ICEByte *bbso = (ICEByte *)[bso bytes]; + test(bbso[0] == 0x22); + test(bbso[1] == 0x12); + test(bbso[2] == 0x11); + test(bbso[3] == 0x01); + test([rso length] == 8); + ICEByte *brso = (ICEByte *)[rso bytes]; + test(brso[0] == 0x01); + test(brso[1] == 0x11); + test(brso[2] == 0x12); + test(brso[3] == 0x22); + test(brso[4] == 0xf1); + test(brso[5] == 0xf2); + test(brso[6] == 0xf3); + test(brso[7] == 0xf4); + [self called]; +} + +-(void) opByteSException:(ICEException*)ex +{ + test(NO); +} + +-(void) opBoolSResponse:(TestOperationsBoolS*)rso p3:(TestOperationsBoolS*)bso +{ + test([bso length] == 4 * sizeof(BOOL)); + BOOL *bbso = (BOOL *)[bso bytes]; + test(bbso[0]); + test(bbso[1]); + test(!bbso[2]); + test(!bbso[3]); + test([rso length] == 3 * sizeof(BOOL)); + BOOL *brso = (BOOL *)[rso bytes]; + test(!brso[0]); + test(brso[1]); + test(brso[2]); + [self called]; +} + +-(void) opBoolSException:(ICEException*)ex +{ + test(NO); +} + +-(void) opShortIntLongSResponse:(TestOperationsLongS*)rso p4:(TestOperationsShortS*)sso p5:(TestOperationsIntS*)iso p6:(TestOperationsLongS*)lso +{ + test([sso length] == 3 * sizeof(ICEShort)); + ICEShort *bsso = (ICEShort *)[sso bytes]; + test(bsso[0] == 1); + test(bsso[1] == 2); + test(bsso[2] == 3); + test([iso length] == 4 * sizeof(ICEInt)); + ICEInt *biso = (ICEInt *)[iso bytes]; + test(biso[0] == 8); + test(biso[1] == 7); + test(biso[2] == 6); + test(biso[3] == 5); + test([lso length] == 6 * sizeof(ICELong)); + ICELong *blso = (ICELong *)[lso bytes]; + test(blso[0] == 10); + test(blso[1] == 30); + test(blso[2] == 20); + test(blso[3] == 10); + test(blso[4] == 30); + test(blso[5] == 20); + test([rso length] == 3 * sizeof(ICELong)); + ICELong *brso = (ICELong *)[rso bytes]; + test(brso[0] == 10); + test(brso[1] == 30); + test(brso[2] == 20); + [self called]; +} + +-(void) opShortIntLongSException:(ICEException*)ex +{ + test(NO); +} + +-(void) opFloatDoubleSResponse:(TestOperationsDoubleS*)rso p3:(TestOperationsFloatS*)fso p4:(TestOperationsDoubleS*)dso +{ + test([fso length] == 2 * sizeof(ICEFloat)); + ICEFloat *bfso = (ICEFloat *)[fso bytes]; + test(bfso[0] == 3.14f); + test(bfso[1] == 1.11f); + test([dso length] == 3 * sizeof(ICEDouble)); + ICEDouble *bdso = (ICEDouble *)[dso bytes]; + test(bdso[0] == 1.3E10); + test(bdso[1] == 1.2E10); + test(bdso[2] == 1.1E10); + test([rso length] == 5 * sizeof(ICEDouble)); + ICEDouble *brso = (ICEDouble *)[rso bytes]; + test(brso[0] == 1.1E10); + test(brso[1] == 1.2E10); + test(brso[2] == 1.3E10); + test((ICEFloat)brso[3] == 3.14f); + test((ICEFloat)brso[4] == 1.11f); + [self called]; +} + +-(void) opFloatDoubleSException:(ICEException*)ex +{ + test(NO); +} + +-(void) opStringSResponse:(TestOperationsStringS*)rso p3:(TestOperationsStringS*)sso +{ + test([sso count] == 4); + test([[sso objectAtIndex:0] isEqualToString:@"abc"]); + test([[sso objectAtIndex:1] isEqualToString:@"de"]); + test([[sso objectAtIndex:2] isEqualToString:@"fghi"]); + test([[sso objectAtIndex:3] isEqualToString:@"xyz"]); + test([rso count] == 3); + test([[rso objectAtIndex:0] isEqualToString:@"fghi"]); + test([[rso objectAtIndex:1] isEqualToString:@"de"]); + test([[rso objectAtIndex:2] isEqualToString:@"abc"]); + [self called]; +} + +-(void) opStringSException:(ICEException*)ex +{ + test(NO); +} + +-(void) opByteSSResponse:(TestOperationsByteSS*)rso p3:(TestOperationsByteSS*)bso +{ + const ICEByte *p; + test([bso count] == 2); + test([[bso objectAtIndex:0] length] / sizeof(ICEByte) == 1); + p = [[bso objectAtIndex:0] bytes]; + test(p[0] == (ICEByte)0x0ff); + test([[bso objectAtIndex:1] length] / sizeof(ICEByte) == 3); + p = [[bso objectAtIndex:1] bytes]; + test(p[0] == (ICEByte)0x01); + test(p[1] == (ICEByte)0x11); + test(p[2] == (ICEByte)0x12); + test([rso count] == 4); + test([[rso objectAtIndex:0] length] / sizeof(ICEByte) == 3); + p = [[rso objectAtIndex:0] bytes]; + test(p[0] == (ICEByte)0x01); + test(p[1] == (ICEByte)0x11); + test(p[2] == (ICEByte)0x12); + test([[rso objectAtIndex:1] length] / sizeof(ICEByte) == 1); + p = [[rso objectAtIndex:1] bytes]; + test(p[0] == (ICEByte)0xff); + test([[rso objectAtIndex:2] length] / sizeof(ICEByte) == 1); + p = [[rso objectAtIndex:2] bytes]; + test(p[0] == (ICEByte)0x0e); + test([[rso objectAtIndex:3] length] / sizeof(ICEByte) == 2); + p = [[rso objectAtIndex:3] bytes]; + test(p[0] == (ICEByte)0xf2); + test(p[1] == (ICEByte)0xf1); + [self called]; +} + +-(void) opByteSSException:(ICEException*)ex +{ + test(NO); +} + +-(void) opBoolSSResponse:(TestOperationsBoolSS*)sso p3:(TestOperationsBoolSS*)bso +{ + [self called]; +} + +-(void) opBoolSSException:(ICEException*)ex +{ + test(NO); +} + +-(void) opShortIntLongSSResponse:(TestOperationsLongSS*)a p4:(TestOperationsShortSS*)p4 p5:(TestOperationsIntSS*)p5 p6:(TestOperationsLongSS*)p6 +{ + [self called]; +} + +-(void) opShortIntLongSSException:(ICEException*)ex +{ + test(NO); +} + +-(void) opFloatDoubleSSResponse:(TestOperationsDoubleSS*)rso p3:(TestOperationsFloatSS*)fso p4:(TestOperationsDoubleSS*)dso +{ + const ICEFloat *fp; + const ICEDouble *dp; + + test([fso count] == 3); + test([[fso objectAtIndex:0] length] / sizeof(ICEFloat) == 1); + fp = [[fso objectAtIndex:0] bytes]; + test(fp[0] == 3.14f); + test([[fso objectAtIndex:1] length] / sizeof(ICEFloat) == 1); + fp = [[fso objectAtIndex:1] bytes]; + test(fp[0] == 1.11f); + test([[fso objectAtIndex:2] length] / sizeof(ICEFloat) == 0); + test([dso count] == 1); + test([[dso objectAtIndex:0] length] / sizeof(ICEDouble) == 3); + dp = [[dso objectAtIndex:0] bytes]; + test(dp[0] == 1.1E10); + test(dp[1] == 1.2E10); + test(dp[2] == 1.3E10); + test([rso count] == 2); + test([[rso objectAtIndex:0] length] / sizeof(ICEDouble) == 3); + dp = [[rso objectAtIndex:0] bytes]; + test(dp[0] == 1.1E10); + test(dp[1] == 1.2E10); + test(dp[2] == 1.3E10); + test([[rso objectAtIndex:1] length] / sizeof(ICEDouble) == 3); + dp = [[rso objectAtIndex:1] bytes]; + test(dp[0] == 1.1E10); + test(dp[1] == 1.2E10); + test(dp[2] == 1.3E10); + [self called]; +} + +-(void) opFloatDoubleSSException:(ICEException*)ex +{ + test(NO); +} + +-(void) opStringSSResponse:(TestOperationsStringSS*)rso p3:(TestOperationsStringSS*)sso +{ + test([sso count] == 5); + test([[sso objectAtIndex:0] count] == 1); + test([[[sso objectAtIndex:0] objectAtIndex:0] isEqualToString:@"abc"]); + test([[sso objectAtIndex:1] count] == 2); + test([[[sso objectAtIndex:1] objectAtIndex:0] isEqualToString:@"de"]); + test([[[sso objectAtIndex:1] objectAtIndex:1] isEqualToString:@"fghi"]); + test([[sso objectAtIndex:2] count] == 0); + test([[sso objectAtIndex:3] count] == 0); + test([[sso objectAtIndex:4] count] == 1); + test([[[sso objectAtIndex:4] objectAtIndex:0] isEqualToString:@"xyz"]); + test([rso count] == 3); + test([[rso objectAtIndex:0] count] == 1); + test([[[rso objectAtIndex:0] objectAtIndex:0] isEqualToString:@"xyz"]); + test([[rso objectAtIndex:1] count] == 0); + test([[rso objectAtIndex:2] count] == 0); + [self called]; +} + +-(void) opStringSSException:(ICEException*)ex +{ + test(NO); +} + +-(void) opStringSSSResponse:(TestOperationsStringSS*)rsso p3:(TestOperationsStringSS*)ssso +{ + test([ssso count] == 5); + test([[ssso objectAtIndex:0] count] == 2); + test([[[ssso objectAtIndex:0] objectAtIndex:0] count] == 2); + test([[[ssso objectAtIndex:0] objectAtIndex:1] count] == 1); + test([[ssso objectAtIndex:1] count] == 1); + test([[[ssso objectAtIndex:1] objectAtIndex:0] count] == 1); + test([[ssso objectAtIndex:2] count] == 2); + test([[[ssso objectAtIndex:2] objectAtIndex:0] count] == 2); + test([[[ssso objectAtIndex:2] objectAtIndex:1] count] == 1); + test([[ssso objectAtIndex:3] count] == 1); + test([[[ssso objectAtIndex:3] objectAtIndex:0] count] == 1); + test([[ssso objectAtIndex:4] count] == 0); + test([[[[ssso objectAtIndex:0] objectAtIndex:0] objectAtIndex:0] isEqualToString:@"abc"]); + test([[[[ssso objectAtIndex:0] objectAtIndex:0] objectAtIndex:1] isEqualToString:@"de"]); + test([[[[ssso objectAtIndex:0] objectAtIndex:1] objectAtIndex:0] isEqualToString:@"xyz"]); + test([[[[ssso objectAtIndex:1] objectAtIndex:0] objectAtIndex:0] isEqualToString:@"hello"]); + test([[[[ssso objectAtIndex:2] objectAtIndex:0] objectAtIndex:0] isEqualToString:@""]); + test([[[[ssso objectAtIndex:2] objectAtIndex:0] objectAtIndex:1] isEqualToString:@""]); + test([[[[ssso objectAtIndex:2] objectAtIndex:1] objectAtIndex:0] isEqualToString:@"abcd"]); + test([[[[ssso objectAtIndex:3] objectAtIndex:0] objectAtIndex:0] isEqualToString:@""]); + + test([rsso count] == 3); + test([[rsso objectAtIndex:0] count] == 0); + test([[rsso objectAtIndex:1] count] == 1); + test([[[rsso objectAtIndex:1] objectAtIndex:0] count] == 1); + test([[rsso objectAtIndex:2] count] == 2); + test([[[rsso objectAtIndex:2] objectAtIndex:0] count] == 2); + test([[[rsso objectAtIndex:2] objectAtIndex:1] count] == 1); + test([[[[rsso objectAtIndex:1] objectAtIndex:0] objectAtIndex:0] isEqualToString:@""]); + test([[[[rsso objectAtIndex:2] objectAtIndex:0] objectAtIndex:0] isEqualToString:@""]); + test([[[[rsso objectAtIndex:2] objectAtIndex:0] objectAtIndex:1] isEqualToString:@""]); + test([[[[rsso objectAtIndex:2] objectAtIndex:1] objectAtIndex:0] isEqualToString:@"abcd"]); + [self called]; +} +-(void) opStringSSSException:(ICEException*)ex +{ + test(NO); +} +-(void) opByteBoolDResponse:(TestOperationsMutableByteBoolD*)ro p3:(TestOperationsMutableByteBoolD*)_do +{ + test([_do count] == 2); + test([[_do objectForKey:[NSNumber numberWithUnsignedChar:10]] boolValue] == YES); + test([[_do objectForKey:[NSNumber numberWithUnsignedChar:100]] boolValue] == NO); + test([ro count] == 4); + test([[ro objectForKey:[NSNumber numberWithUnsignedChar:10]] boolValue] == YES); + test([[ro objectForKey:[NSNumber numberWithUnsignedChar:11]] boolValue] == NO); + test([[ro objectForKey:[NSNumber numberWithUnsignedChar:100]] boolValue] == NO); + test([[ro objectForKey:[NSNumber numberWithUnsignedChar:101]] boolValue] == YES); + [self called]; +} +-(void) opByteBoolDException:(ICEException*)ex +{ + test(NO); +} +-(void) opShortIntDResponse:(TestOperationsShortIntD*)ro p3:(TestOperationsShortIntD*)_do +{ + test([_do count] == 2); + test([[_do objectForKey:[NSNumber numberWithShort:110]] intValue] == -1); + test([[_do objectForKey:[NSNumber numberWithShort:1100]] intValue] == 123123); + test([ro count] == 4); + test([[ro objectForKey:[NSNumber numberWithShort:110]] intValue] == -1); + test([[ro objectForKey:[NSNumber numberWithShort:111]] intValue] == -100); + test([[ro objectForKey:[NSNumber numberWithShort:1100]] intValue] == 123123); + test([[ro objectForKey:[NSNumber numberWithShort:1101]] intValue] == 0); + [self called]; +} +-(void) opShortIntDException:(ICEException*)ex +{ + test(NO); +} +-(void) opLongFloatDResponse:(TestOperationsLongFloatD*)ro p3:(TestOperationsLongFloatD*)_do +{ + test([_do count] == 2); + test((ICEFloat)[[_do objectForKey:[NSNumber numberWithLong:999999110]] floatValue] == -1.1f); + test((ICEFloat)[[_do objectForKey:[NSNumber numberWithLong:999999111]] floatValue] == 123123.2f); + test([ro count] == 4); + test((ICEFloat)[[ro objectForKey:[NSNumber numberWithLong:999999110]] floatValue] == -1.1f); + test((ICEFloat)[[ro objectForKey:[NSNumber numberWithLong:999999120]] floatValue] == -100.4f); + test((ICEFloat)[[ro objectForKey:[NSNumber numberWithLong:999999111]] floatValue] == 123123.2f); + test((ICEFloat)[[ro objectForKey:[NSNumber numberWithLong:999999130]] floatValue] == 0.5f); + [self called]; +} +-(void) opLongFloatDException:(ICEException*)ex +{ + test(NO); +} +-(void) opStringStringDResponse:(TestOperationsStringStringD*)ro p3:(TestOperationsStringStringD*)_do +{ + test([_do count] == 2); + test([[_do objectForKey:@"foo"] isEqualToString:@"abc -1.1"]); + test([[_do objectForKey:@"bar"] isEqualToString:@"abc 123123.2"]); + test([ro count] == 4); + test([[ro objectForKey:@"foo"] isEqualToString:@"abc -1.1"]); + test([[ro objectForKey:@"FOO"] isEqualToString:@"abc -100.4"]); + test([[ro objectForKey:@"bar"] isEqualToString:@"abc 123123.2"]); + test([[ro objectForKey:@"BAR"] isEqualToString:@"abc 0.5"]); + [self called]; +} +-(void) opStringStringDException:(ICEException*)ex +{ + test(NO); +} +-(void) opStringMyEnumDResponse:(TestOperationsStringMyEnumD*)ro p3:(TestOperationsStringMyEnumD*)_do +{ + test([_do count] == 2); + test([[_do objectForKey:@"abc"] intValue] == TestOperationsenum1); + test([[_do objectForKey:@""] intValue] == TestOperationsenum2); + test([ro count] == 4); + test([[ro objectForKey:@"abc"] intValue] == TestOperationsenum1); + test([[ro objectForKey:@"querty"] intValue] == TestOperationsenum3); + test([[ro objectForKey:@""] intValue] == TestOperationsenum2); + test([[ro objectForKey:@"Hello!!"] intValue] == TestOperationsenum2); + [self called]; +} +-(void) opStringMyEnumDException:(ICEException*)ex +{ + test(NO); +} +-(void) opMyEnumStringDResponse:(TestOperationsMyEnumStringD*)ro p3:(TestOperationsMyEnumStringD*)_do +{ + test([_do count] == 1); + test([ro count] == 3); + test([[ro objectForKey:@(TestOperationsenum1)] isEqualToString:@"abc"]); + test([[ro objectForKey:@(TestOperationsenum2)] isEqualToString:@"Hello!!"]); + test([[ro objectForKey:@(TestOperationsenum3)] isEqualToString:@"querty"]); + [self called]; +} +-(void) opMyEnumStringDException:(ICEException*)ex +{ + test(NO); +} +-(void) opMyStructMyEnumDResponse:(TestOperationsMyStructMyEnumD*)ro p3:(TestOperationsMyStructMyEnumD*)_do + s11:(TestOperationsMyStruct*)s11 s12:(TestOperationsMyStruct*)s12 + s22:(TestOperationsMyStruct*)s22 s23:(TestOperationsMyStruct*)s23 +{ + test([_do count] == 2); + test([ro count] == 4); + test([[ro objectForKey:s11] isEqual:@(TestOperationsenum1)]); + test([[ro objectForKey:s12] isEqual:@(TestOperationsenum2)]); + test([[ro objectForKey:s22] isEqual:@(TestOperationsenum3)]); + test([[ro objectForKey:s23] isEqual:@(TestOperationsenum2)]); + [self called]; +} +-(void) opMyStructMyEnumDException:(ICEException*)ex +{ + test(NO); +} +-(void) opByteBoolDSResponse:(TestOperationsByteBoolDS*)ro p3:(TestOperationsByteBoolDS*)_do +{ + test([ro count] == 2); + test([[ro objectAtIndex:0] count] == 3); + test([[[ro objectAtIndex:0] objectForKey:[NSNumber numberWithUnsignedChar:10]] boolValue] == YES); + test([[[ro objectAtIndex:0] objectForKey:[NSNumber numberWithUnsignedChar:11]] boolValue] == NO); + test([[[ro objectAtIndex:0] objectForKey:[NSNumber numberWithUnsignedChar:101]] boolValue] == YES); + test([[ro objectAtIndex:1] count] == 2); + test([[[ro objectAtIndex:1] objectForKey:[NSNumber numberWithUnsignedChar:10]] boolValue] == YES); + test([[[ro objectAtIndex:1] objectForKey:[NSNumber numberWithUnsignedChar:100]] boolValue] == NO); + test([_do count] == 3); + test([[_do objectAtIndex:0] count] == 2); + test([[[_do objectAtIndex:0] objectForKey:[NSNumber numberWithUnsignedChar:100]] boolValue] == NO); + test([[[_do objectAtIndex:0] objectForKey:[NSNumber numberWithUnsignedChar:101]] boolValue] == NO); + test([[_do objectAtIndex:1] count] == 2); + test([[[_do objectAtIndex:1] objectForKey:[NSNumber numberWithUnsignedChar:10]] boolValue] == YES); + test([[[_do objectAtIndex:1] objectForKey:[NSNumber numberWithUnsignedChar:100]] boolValue] == NO); + test([[_do objectAtIndex:2] count] == 3); + test([[[_do objectAtIndex:2] objectForKey:[NSNumber numberWithUnsignedChar:10]] boolValue] == YES); + test([[[_do objectAtIndex:2] objectForKey:[NSNumber numberWithUnsignedChar:11]] boolValue] == NO); + test([[[_do objectAtIndex:2] objectForKey:[NSNumber numberWithUnsignedChar:101]] boolValue] == YES); + [self called]; +} +-(void) opByteBoolDSException:(ICEException*)ex +{ + test(NO); +} +-(void) opShortIntDSResponse:(TestOperationsShortIntDS*)ro p3:(TestOperationsShortIntDS*)_do +{ + test([ro count] == 2); + test([[ro objectAtIndex:0] count] == 3); + test([[[ro objectAtIndex:0] objectForKey:[NSNumber numberWithShort:110]] intValue] == -1); + test([[[ro objectAtIndex:0] objectForKey:[NSNumber numberWithShort:111]] intValue] == -100); + test([[[ro objectAtIndex:0] objectForKey:[NSNumber numberWithShort:1101]] intValue] == 0); + test([[ro objectAtIndex:1] count] == 2); + test([[[ro objectAtIndex:1] objectForKey:[NSNumber numberWithShort:110]] intValue] == -1); + test([[[ro objectAtIndex:1] objectForKey:[NSNumber numberWithShort:1100]] intValue] == 123123); + test([_do count] == 3); + test([[_do objectAtIndex:0] count] == 1); + test([[[_do objectAtIndex:0] objectForKey:[NSNumber numberWithShort:100]] intValue] == -1001); + test([[_do objectAtIndex:1] count] == 2); + test([[[_do objectAtIndex:1] objectForKey:[NSNumber numberWithShort:110]] intValue] == -1); + test([[[_do objectAtIndex:1] objectForKey:[NSNumber numberWithShort:1100]] intValue] == 123123); + test([[_do objectAtIndex:2] count] == 3); + test([[[_do objectAtIndex:2] objectForKey:[NSNumber numberWithShort:110]] intValue] == -1); + test([[[_do objectAtIndex:2] objectForKey:[NSNumber numberWithShort:111]] intValue] == -100); + test([[[_do objectAtIndex:2] objectForKey:[NSNumber numberWithShort:1101]] intValue] == 0); + [self called]; +} +-(void) opShortIntDSException:(ICEException*)ex +{ + test(NO); +} +-(void) opLongFloatDSResponse:(TestOperationsLongFloatDS*)ro p3:(TestOperationsLongFloatDS*)_do +{ + test([ro count] == 2); + test([[ro objectAtIndex:0] count] == 3); + test([[[ro objectAtIndex:0] objectForKey:[NSNumber numberWithLong:999999110]] floatValue] == -1.1f); + test([[[ro objectAtIndex:0] objectForKey:[NSNumber numberWithLong:999999120]] floatValue] == -100.4f); + test([[[ro objectAtIndex:0] objectForKey:[NSNumber numberWithLong:999999130]] floatValue] == 0.5f); + test([[ro objectAtIndex:1] count] == 2); + test([[[ro objectAtIndex:1] objectForKey:[NSNumber numberWithLong:999999110]] floatValue] == -1.1f); + test([[[ro objectAtIndex:1] objectForKey:[NSNumber numberWithLong:999999111]] floatValue] == 123123.2f); + test([_do count] == 3); + test([[_do objectAtIndex:0] count] == 1); + test([[[_do objectAtIndex:0] objectForKey:[NSNumber numberWithLong:999999140]] floatValue] == 3.14f); + test([[_do objectAtIndex:1] count] == 2); + test([[[_do objectAtIndex:1] objectForKey:[NSNumber numberWithLong:999999110]] floatValue] == -1.1f); + test([[[_do objectAtIndex:1] objectForKey:[NSNumber numberWithLong:999999111]] floatValue] == 123123.2f); + test([[_do objectAtIndex:2] count] == 3); + test([[[_do objectAtIndex:2] objectForKey:[NSNumber numberWithLong:999999110]] floatValue] == -1.1f); + test([[[_do objectAtIndex:2] objectForKey:[NSNumber numberWithLong:999999120]] floatValue] == -100.4f); + test([[[_do objectAtIndex:2] objectForKey:[NSNumber numberWithLong:999999130]] floatValue] == 0.5f); + [self called]; +} +-(void) opLongFloatDSException:(ICEException*)ex +{ + test(NO); +} +-(void) opStringStringDSResponse:(TestOperationsStringStringDS*)ro p3:(TestOperationsStringStringDS*)_do +{ + test([ro count] == 2); + test([[ro objectAtIndex:0] count] == 3); + test([[[ro objectAtIndex:0] objectForKey:@"foo"] isEqualToString:@"abc -1.1"]); + test([[[ro objectAtIndex:0] objectForKey:@"FOO"] isEqualToString:@"abc -100.4"]); + test([[[ro objectAtIndex:0] objectForKey:@"BAR"] isEqualToString:@"abc 0.5"]); + test([[ro objectAtIndex:1] count] == 2); + test([[[ro objectAtIndex:1] objectForKey:@"foo"] isEqualToString:@"abc -1.1"]); + test([[[ro objectAtIndex:1] objectForKey:@"bar"] isEqualToString:@"abc 123123.2"]); + test([_do count] == 3); + test([[_do objectAtIndex:0] count] == 1); + test([[[_do objectAtIndex:0] objectForKey:@"f00"] isEqualToString:@"ABC -3.14"]); + test([[_do objectAtIndex:1] count] == 2); + test([[[_do objectAtIndex:1] objectForKey:@"foo"] isEqualToString:@"abc -1.1"]); + test([[[_do objectAtIndex:1] objectForKey:@"bar"] isEqualToString:@"abc 123123.2"]); + test([[_do objectAtIndex:2] count] == 3); + test([[[_do objectAtIndex:2] objectForKey:@"foo"] isEqualToString:@"abc -1.1"]); + test([[[_do objectAtIndex:2] objectForKey:@"FOO"] isEqualToString:@"abc -100.4"]); + test([[[_do objectAtIndex:2] objectForKey:@"BAR"] isEqualToString:@"abc 0.5"]); + [self called]; +} +-(void) opStringStringDSException:(ICEException*)ex +{ + test(NO); +} +-(void) opStringMyEnumDSResponse:(TestOperationsStringStringDS*)ro p3:(TestOperationsStringStringDS*)_do +{ + test([ro count] == 2); + test([[ro objectAtIndex:0] count] == 3); + test([[[ro objectAtIndex:0] objectForKey:@"abc"] intValue] == TestOperationsenum1); + test([[[ro objectAtIndex:0] objectForKey:@"querty"] intValue] == TestOperationsenum3); + test([[[ro objectAtIndex:0] objectForKey:@"Hello!!"] intValue] == TestOperationsenum2); + test([[ro objectAtIndex:1] count] == 2); + test([[[ro objectAtIndex:1] objectForKey:@"abc"] intValue] == TestOperationsenum1); + test([[[ro objectAtIndex:1] objectForKey:@""] intValue] == TestOperationsenum2); + test([_do count] == 3); + test([[_do objectAtIndex:0] count] == 1); + test([[[_do objectAtIndex:0] objectForKey:@"Goodbye"] intValue] == TestOperationsenum1); + test([[_do objectAtIndex:1] count] == 2); + test([[[_do objectAtIndex:1] objectForKey:@"abc"] intValue] == TestOperationsenum1); + test([[[_do objectAtIndex:1] objectForKey:@""] intValue] == TestOperationsenum2); + test([[_do objectAtIndex:2] count] == 3); + test([[[_do objectAtIndex:2] objectForKey:@"abc"] intValue] == TestOperationsenum1); + test([[[_do objectAtIndex:2] objectForKey:@"querty"] intValue] == TestOperationsenum3); + test([[[_do objectAtIndex:2] objectForKey:@"Hello!!"] intValue] == TestOperationsenum2); + [self called]; +} +-(void) opStringMyEnumDSException:(ICEException*)ex +{ + test(NO); +} +-(void) opMyEnumStringDSResponse:(TestOperationsMyEnumStringDS*)ro p3:(TestOperationsMyEnumStringDS*)_do +{ + test([ro count] == 2); + test([[ro objectAtIndex:0] count] == 2); + test([[[ro objectAtIndex:0] objectForKey:@(TestOperationsenum2)] isEqualToString:@"Hello!!"]); + test([[[ro objectAtIndex:0] objectForKey:@(TestOperationsenum3)] isEqualToString:@"querty"]); + test([[ro objectAtIndex:1] count] == 1); + test([[[ro objectAtIndex:1] objectForKey:@(TestOperationsenum1)] isEqualToString:@"abc"]); + test([_do count] == 3); + test([[_do objectAtIndex:0] count] == 1); + test([[[_do objectAtIndex:0] objectForKey:@(TestOperationsenum1)] isEqualToString:@"Goodbye"]); + test([[_do objectAtIndex:1] count] == 1); + test([[[_do objectAtIndex:1] objectForKey:@(TestOperationsenum1)] isEqualToString:@"abc"]); + test([[_do objectAtIndex:2] count] == 2); + test([[[_do objectAtIndex:2] objectForKey:@(TestOperationsenum2)] isEqualToString:@"Hello!!"]); + test([[[_do objectAtIndex:2] objectForKey:@(TestOperationsenum3)] isEqualToString:@"querty"]); + [self called]; +} +-(void) opMyEnumStringDSException:(ICEException*)ex +{ + test(NO); +} +-(void) opMyStructMyEnumDSResponse:(TestOperationsMyStructMyEnumDS*)ro p3:(TestOperationsMyStructMyEnumDS*)_do + s11:(TestOperationsMyStruct*)s11 s12:(TestOperationsMyStruct*)s12 + s22:(TestOperationsMyStruct*)s22 s23:(TestOperationsMyStruct*)s23 +{ + test([ro count] == 2); + test([[ro objectAtIndex:0] count] == 3); + test([[[ro objectAtIndex:0] objectForKey:s11] intValue] == TestOperationsenum1); + test([[[ro objectAtIndex:0] objectForKey:s22] intValue] == TestOperationsenum3); + test([[[ro objectAtIndex:0] objectForKey:s23] intValue] == TestOperationsenum2); + test([[ro objectAtIndex:1] count] == 2); + test([[[ro objectAtIndex:1] objectForKey:s11] intValue] == TestOperationsenum1); + test([[[ro objectAtIndex:1] objectForKey:s12] intValue] == TestOperationsenum2); + test([_do count] == 3); + test([[_do objectAtIndex:0] count] == 1); + test([[[_do objectAtIndex:0] objectForKey:s23] intValue] == TestOperationsenum3); + test([[_do objectAtIndex:1] count] == 2); + test([[[_do objectAtIndex:1] objectForKey:s11] intValue] == TestOperationsenum1); + test([[[_do objectAtIndex:1] objectForKey:s12] intValue] == TestOperationsenum2); + test([[_do objectAtIndex:2] count] == 3); + test([[[_do objectAtIndex:2] objectForKey:s11] intValue] == TestOperationsenum1); + test([[[_do objectAtIndex:2] objectForKey:s22] intValue] == TestOperationsenum3); + test([[[_do objectAtIndex:2] objectForKey:s23] intValue] == TestOperationsenum2); + [self called]; +} +-(void) opMyStructMyEnumDSException:(ICEException*)ex +{ + test(NO); +} +-(void) opByteByteSDResponse:(TestOperationsByteByteSD*)ro p3:(TestOperationsByteByteSD*)_do +{ + const ICEByte *p; + test([_do count] == 1); + test([[_do objectForKey:[NSNumber numberWithUnsignedChar:(ICEByte)0xf1]] length] / sizeof(ICEByte) == 2); + p = [[_do objectForKey:[NSNumber numberWithUnsignedChar:(ICEByte)0xf1]] bytes]; + test(p[0] == 0xf2); + test(p[1] == 0xf3); + test([ro count] == 3); + test([[ro objectForKey:[NSNumber numberWithUnsignedChar:(ICEByte)0x01]] length] / sizeof(ICEByte) == 2); + p = [[ro objectForKey:[NSNumber numberWithUnsignedChar:(ICEByte)0x01]] bytes]; + test(p[0] == 0x01); + test(p[1] == 0x11); + test([[ro objectForKey:[NSNumber numberWithUnsignedChar:(ICEByte)0x22]] length] / sizeof(ICEByte) == 1); + p = [[ro objectForKey:[NSNumber numberWithUnsignedChar:(ICEByte)0x22]] bytes]; + test(p[0] == 0x12); + test([[ro objectForKey:[NSNumber numberWithUnsignedChar:(ICEByte)0xf1]] length] / sizeof(ICEByte) == 2); + p = [[ro objectForKey:[NSNumber numberWithUnsignedChar:(ICEByte)0xf1]] bytes]; + test(p[0] == 0xf2); + test(p[1] == 0xf3); + [self called]; +} +-(void) opByteByteSDException:(ICEException*)ex +{ + test(NO); +} +-(void) opBoolBoolSDResponse:(TestOperationsBoolBoolSD*)ro p3:(TestOperationsBoolBoolSD*)_do +{ + const BOOL *p; + test([_do count] == 1); + test([[_do objectForKey:[NSNumber numberWithBool:NO]] length] / sizeof(BOOL) == 2); + p = [[_do objectForKey:[NSNumber numberWithBool:NO]] bytes]; + test(p[0] == YES); + test(p[1] == NO); + test([ro count] == 2); + test([[ro objectForKey:[NSNumber numberWithBool:NO]] length] / sizeof(BOOL) == 2); + p = [[ro objectForKey:[NSNumber numberWithBool:NO]] bytes]; + test(p[0] == YES); + test(p[1] == NO); + test([[ro objectForKey:[NSNumber numberWithBool:YES]] length] / sizeof(BOOL) == 3); + p = [[ro objectForKey:[NSNumber numberWithBool:YES]] bytes]; + test(p[0] == NO); + test(p[1] == YES); + test(p[2] == YES); + [self called]; +} +-(void) opBoolBoolSDException:(ICEException*)ex +{ + test(NO); +} +-(void) opShortShortSDResponse:(TestOperationsShortShortSD*)ro p3:(TestOperationsShortShortSD*)_do +{ + const ICEShort *p; + test([_do count] == 1); + test([[_do objectForKey:[NSNumber numberWithShort:4]] length] / sizeof(ICEShort) == 2); + p = [[_do objectForKey:[NSNumber numberWithShort:4]] bytes]; + test(p[0] == 6); + test(p[1] == 7); + test([ro count] == 3); + test([[ro objectForKey:[NSNumber numberWithShort:1]] length] / sizeof(ICEShort) == 3); + p = [[ro objectForKey:[NSNumber numberWithShort:1]] bytes]; + test(p[0] == 1); + test(p[1] == 2); + test(p[2] == 3); + test([[ro objectForKey:[NSNumber numberWithShort:2]] length] / sizeof(ICEShort) == 2); + p = [[ro objectForKey:[NSNumber numberWithShort:2]] bytes]; + test(p[0] == 4); + test(p[1] == 5); + test([[ro objectForKey:[NSNumber numberWithShort:4]] length] / sizeof(ICEShort) == 2); + p = [[ro objectForKey:[NSNumber numberWithShort:4]] bytes]; + test(p[0] == 6); + test(p[1] == 7); + [self called]; +} +-(void) opShortShortSDException:(ICEException*)ex +{ + test(NO); +} +-(void) opIntIntSDResponse:(TestOperationsIntIntSD*)ro p3:(TestOperationsIntIntSD*)_do +{ + const ICEInt *p; + test([_do count] == 1); + test([[_do objectForKey:[NSNumber numberWithInt:400]] length] / sizeof(ICEInt) == 2); + p = [[_do objectForKey:[NSNumber numberWithInt:400]] bytes]; + test(p[0] == 600); + test(p[1] == 700); + test([ro count] == 3); + test([[ro objectForKey:[NSNumber numberWithInt:100]] length] / sizeof(ICEInt) == 3); + p = [[ro objectForKey:[NSNumber numberWithInt:100]] bytes]; + test(p[0] == 100); + test(p[1] == 200); + test(p[2] == 300); + test([[ro objectForKey:[NSNumber numberWithInt:200]] length] / sizeof(ICEInt) == 2); + p = [[ro objectForKey:[NSNumber numberWithInt:200]] bytes]; + test(p[0] == 400); + test(p[1] == 500); + test([[ro objectForKey:[NSNumber numberWithInt:400]] length] / sizeof(ICEInt) == 2); + p = [[ro objectForKey:[NSNumber numberWithInt:400]] bytes]; + test(p[0] == 600); + test(p[1] == 700); + [self called]; +} +-(void) opIntIntSDException:(ICEException*)ex +{ + test(NO); +} +-(void) opLongLongSDResponse:(TestOperationsLongLongSD*)ro p3:(TestOperationsLongLongSD*)_do +{ + const ICELong *p; + test([_do count] == 1); + test([[_do objectForKey:[NSNumber numberWithLong:999999992]] length] / sizeof(ICELong) == 2); + p = [[_do objectForKey:[NSNumber numberWithLong:999999992]] bytes]; + test(p[0] == 999999110); + test(p[1] == 999999120); + test([ro count] == 3); + test([[ro objectForKey:[NSNumber numberWithLong:999999990]] length] / sizeof(ICELong) == 3); + p = [[ro objectForKey:[NSNumber numberWithLong:999999990]] bytes]; + test(p[0] == 999999110); + test(p[1] == 999999111); + test(p[2] == 999999110); + test([[ro objectForKey:[NSNumber numberWithLong:999999991]] length] / sizeof(ICELong) == 2); + p = [[ro objectForKey:[NSNumber numberWithLong:999999991]] bytes]; + test(p[0] == 999999120); + test(p[1] == 999999130); + test([[ro objectForKey:[NSNumber numberWithLong:999999992]] length] / sizeof(ICELong) == 2); + p = [[ro objectForKey:[NSNumber numberWithLong:999999992]] bytes]; + test(p[0] == 999999110); + test(p[1] == 999999120); + [self called]; +} +-(void) opLongLongSDException:(ICEException*)ex +{ + test(NO); +} +-(void) opStringFloatSDResponse:(TestOperationsStringFloatSD*)ro p3:(TestOperationsStringFloatSD*)_do +{ + const ICEFloat *p; + test([_do count] == 1); + test([[_do objectForKey:@"aBc"] length] / sizeof(ICEFloat) == 2); + p = [[_do objectForKey:@"aBc"] bytes]; + test(p[0] == -3.14f); + test(p[1] == 3.14f); + test([ro count] == 3); + test([[ro objectForKey:@"abc"] length] / sizeof(ICEFloat) == 3); + p = [[ro objectForKey:@"abc"] bytes]; + test(p[0] == -1.1f); + test(p[1] == 123123.2f); + test(p[2] == 100.0f); + test([[ro objectForKey:@"ABC"] length] / sizeof(ICEFloat) == 2); + p = [[ro objectForKey:@"ABC"] bytes]; + test(p[0] == 42.24f); + test(p[1] == -1.61f); + test([[ro objectForKey:@"aBc"] length] / sizeof(ICEFloat) == 2); + p = [[ro objectForKey:@"aBc"] bytes]; + test(p[0] == -3.14f); + test(p[1] == 3.14f); + [self called]; +} +-(void) opStringFloatSDException:(ICEException*)ex +{ + test(NO); +} +-(void) opStringDoubleSDResponse:(TestOperationsStringDoubleSD*)ro p3:(TestOperationsStringDoubleSD*)_do +{ + const ICEDouble *p; + test([_do count] == 1); + test([[_do objectForKey:@""] length] / sizeof(ICEDouble) == 2); + p = [[_do objectForKey:@""] bytes]; + test(p[0] == 1.6E10); + test(p[1] == 1.7E10); + test([ro count] == 3); + test([[ro objectForKey:@"Hello!!"] length] / sizeof(ICEDouble) == 3); + p = [[ro objectForKey:@"Hello!!"] bytes]; + test(p[0] == 1.1E10); + test(p[1] == 1.2E10); + test(p[2] == 1.3E10); + test([[ro objectForKey:@"Goodbye"] length] / sizeof(ICEDouble) == 2); + p = [[ro objectForKey:@"Goodbye"] bytes]; + test(p[0] == 1.4E10); + test(p[1] == 1.5E10); + test([[ro objectForKey:@""] length] / sizeof(ICEDouble) == 2); + p = [[ro objectForKey:@""] bytes]; + test(p[0] == 1.6E10); + test(p[1] == 1.7E10); + [self called]; +} +-(void) opStringDoubleSDException:(ICEException*)ex +{ + test(NO); +} +-(void) opStringStringSDResponse:(TestOperationsStringStringSD*)ro p3:(TestOperationsStringStringSD*)_do +{ + test([[_do objectForKey:@"ghi"] count] == 2); + test([[[_do objectForKey:@"ghi"] objectAtIndex:0] isEqualToString:@"and"]); + test([[[_do objectForKey:@"ghi"] objectAtIndex:1] isEqualToString:@"xor"]); + test([ro count] == 3); + test([[ro objectForKey:@"abc"] count] == 3); + test([[[ro objectForKey:@"abc"] objectAtIndex:0] isEqualToString:@"abc"]); + test([[[ro objectForKey:@"abc"] objectAtIndex:1] isEqualToString:@"de"]); + test([[[ro objectForKey:@"abc"] objectAtIndex:2] isEqualToString:@"fghi"]); + test([[ro objectForKey:@"def"] count] == 2); + test([[[ro objectForKey:@"def"] objectAtIndex:0] isEqualToString:@"xyz"]); + test([[[ro objectForKey:@"def"] objectAtIndex:1] isEqualToString:@"or"]); + test([[ro objectForKey:@"ghi"] count] == 2); + test([[[ro objectForKey:@"ghi"] objectAtIndex:0] isEqualToString:@"and"]); + test([[[ro objectForKey:@"ghi"] objectAtIndex:1] isEqualToString:@"xor"]); + [self called]; +} +-(void) opStringStringSDException:(ICEException*)ex +{ + test(NO); +} +-(void) opMyEnumMyEnumSDResponse:(TestOperationsMyEnumMyEnumSD*)ro p3:(TestOperationsMyEnumMyEnumSD*)_do +{ + const TestOperationsMyEnum *p; + test([_do count] == 1); + test([[_do objectForKey:@(TestOperationsenum1)] length] / sizeof(TestOperationsMyEnum) == 2); + p = [[_do objectForKey:@(TestOperationsenum1)] bytes]; + test(p[0] == TestOperationsenum3); + test(p[1] == TestOperationsenum3); + test([ro count] == 3); + test([[ro objectForKey:@(TestOperationsenum3)] length] / sizeof(TestOperationsMyEnum) == 3); + p = [[ro objectForKey:@(TestOperationsenum3)] bytes]; + test(p[0] == TestOperationsenum1); + test(p[1] == TestOperationsenum1); + test(p[2] == TestOperationsenum2); + test([[ro objectForKey:@(TestOperationsenum2)] length] / sizeof(TestOperationsMyEnum) == 2); + p = [[ro objectForKey:@(TestOperationsenum2)] bytes]; + test(p[0] == TestOperationsenum1); + test(p[1] == TestOperationsenum2); + test([[ro objectForKey:@(TestOperationsenum1)] length] / sizeof(TestOperationsMyEnum) == 2); + p = [[ro objectForKey:@(TestOperationsenum1)] bytes]; + test(p[0] == TestOperationsenum3); + test(p[1] == TestOperationsenum3); + [self called]; +} +-(void) opMyEnumMyEnumSDException:(ICEException*)ex +{ + test(NO); +} +-(void) opIntSResponse:(TestOperationsIntS*)r +{ + const ICEInt *rp = [r bytes]; + int j; + for(j = 0; j < [r length] / sizeof(ICEInt); ++j) + { + test(rp[j] == -j); + } + [self called]; +} +-(void) opIntSException:(ICEException*)ex +{ + test(NO); +} +-(void) opEmptyContextResponse:(ICEContext*)ctx +{ + test([ctx count] == 0); + [self called]; +} +-(void) opNonEmptyContextResponse:(ICEContext*)ctx +{ + test([ctx count] == 3); + test([[ctx objectForKey:@"one"] isEqualToString:@"ONE"]); + test([[ctx objectForKey:@"two"] isEqualToString:@"TWO"]); + test([[ctx objectForKey:@"three"] isEqualToString:@"THREE"]); + [self called]; +} +-(void) opContextException:(ICEException*)ex +{ + test(NO); +} +-(void) opDoubleMarshalingResponse +{ + [self called]; +} +-(void) opDoubleMarshalingException:(ICEException*)ex +{ + test(NO); +} +@end + +void +twowaysNewAMI(id<ICECommunicator> communicator, id<TestOperationsMyClassPrx> p) +{ + { + TestNewAMIOperationsCallback* cb = [TestNewAMIOperationsCallback create]; + [p begin_opByte:(ICEByte)0xff p2:(ICEByte)0x0f response:^(ICEByte ret, ICEByte p3) { [cb opByteResponse:ret p3:p3]; } exception:^(ICEException* ex) { [cb opByteException:ex]; }]; + test([cb check]); + } + + { + TestNewAMIOperationsCallback* cb = [TestNewAMIOperationsCallback create]; + [p begin_opBool:YES p2:NO response:^(BOOL ret, BOOL p3) { [cb opBoolResponse:ret p3:p3]; } exception:^(ICEException* ex) { [cb opBoolException:ex]; }]; + test([cb check]); + } + + { + TestNewAMIOperationsCallback* cb = [TestNewAMIOperationsCallback create]; + [p begin_opShortIntLong:10 p2:11 p3:12 response:^(ICELong ret, ICEShort p4, ICEInt p5, ICELong p6) { [cb opShortIntLongResponse:ret p4:p4 p5:p5 p6:p6]; } exception:^(ICEException* ex) { [cb opShortIntLongException:ex]; }]; + test([cb check]); + } + + { + TestNewAMIOperationsCallback* cb = [TestNewAMIOperationsCallback create]; + [p begin_opFloatDouble:3.14f p2:1.1E10 response:^(ICEDouble ret, ICEFloat p3, ICEDouble p4) { [cb opFloatDoubleResponse:ret p3:p3 p4:p4]; } exception:^(ICEException* ex) { [cb opFloatDoubleException:ex]; }]; + test([cb check]); + } + + { + TestNewAMIOperationsCallback* cb = [TestNewAMIOperationsCallback create]; + [p begin_opString:@"hello" p2:@"world" response:^(NSMutableString* ret, NSMutableString* p3) { [cb opStringResponse:ret p3:p3]; } exception:^(ICEException* ex) { [cb opStringException:ex]; }]; + test([cb check]); + } + + { + TestNewAMIOperationsCallback* cb = [TestNewAMIOperationsCallback create]; + [p begin_opMyEnum:TestOperationsenum2 response:^(TestOperationsMyEnum ret, TestOperationsMyEnum p2) { [cb opMyEnumResponse:ret p2:p2]; } exception:^(ICEException* ex) { [cb opMyEnumException:ex]; }]; + test([cb check]); + } + + { + TestNewAMIOperationsCallback* cb = [TestNewAMIOperationsCallback create]; + [p begin_opMyClass:p response:^(id<TestOperationsMyClassPrx> ret, id<TestOperationsMyClassPrx>p2, id<TestOperationsMyClassPrx> p3) { [cb opMyClassResponse:ret p2:p2 p3:p3]; } exception:^(ICEException* ex) { [cb opMyClassException:ex]; }]; + test([cb check]); + } + + { + TestOperationsStructure *si1 = [TestOperationsStructure structure]; + si1.p = p; + si1.e = TestOperationsenum3; + si1.s = [TestOperationsAnotherStruct anotherStruct]; + si1.s.s = @"abc"; + TestOperationsStructure *si2 = [TestOperationsStructure structure]; + si2.p = nil; + si2.e = TestOperationsenum2; + si2.s = [TestOperationsAnotherStruct anotherStruct]; + si2.s.s = @"def"; + + TestNewAMIOperationsCallback* cb = [TestNewAMIOperationsCallback create]; + [p begin_opStruct:si1 p2:si2 response:^(TestOperationsStructure* ret, TestOperationsStructure* p3) { [cb opStructResponse:ret p3:p3]; } exception:^(ICEException* ex) { [cb opStructException:ex]; }]; + test([cb check]); + } + + { + ICEByte buf1[] = { 0x01, 0x11, 0x12, 0x22 }; + ICEByte buf2[] = { 0xf1, 0xf2, 0xf3, 0xf4 }; + + TestOperationsMutableByteS *bsi1 = [TestOperationsMutableByteS data]; + TestOperationsMutableByteS *bsi2 = [TestOperationsMutableByteS data]; + + [bsi1 appendBytes:buf1 length:sizeof(buf1)]; + [bsi2 appendBytes:buf2 length:sizeof(buf2)]; + + TestNewAMIOperationsCallback* cb = [TestNewAMIOperationsCallback create]; + [p begin_opByteS:bsi1 p2:bsi2 response:^(TestOperationsMutableByteS* ret, TestOperationsMutableByteS* p3) { [cb opByteSResponse:ret p3:p3]; } exception:^(ICEException* ex) { [cb opByteSException:ex]; }]; + test([cb check]); + } + + { + BOOL buf1[] = { YES, YES, NO }; + BOOL buf2[] = { NO }; + + TestOperationsMutableBoolS *bsi1 = [TestOperationsMutableBoolS data]; + TestOperationsMutableBoolS *bsi2 = [TestOperationsMutableBoolS data]; + + [bsi1 appendBytes:buf1 length:sizeof(buf1)]; + [bsi2 appendBytes:buf2 length:sizeof(buf2)]; + + TestNewAMIOperationsCallback* cb = [TestNewAMIOperationsCallback create]; + [p begin_opBoolS:bsi1 p2:bsi2 response:^(TestOperationsMutableBoolS* ret, TestOperationsMutableBoolS* p3) { [cb opBoolSResponse:ret p3:p3]; } exception:^(ICEException* ex) { [cb opBoolSException:ex]; }]; + test([cb check]); + } + + { + ICEShort buf1[] = { 1, 2, 3 }; + ICEInt buf2[] = { 5, 6, 7, 8 }; + ICELong buf3[] = { 10, 30, 20 }; + + TestOperationsMutableShortS *ssi = [TestOperationsMutableShortS data]; + TestOperationsMutableIntS *isi = [TestOperationsMutableIntS data]; + TestOperationsMutableLongS *lsi = [TestOperationsMutableLongS data]; + + [ssi appendBytes:buf1 length:sizeof(buf1)]; + [isi appendBytes:buf2 length:sizeof(buf2)]; + [lsi appendBytes:buf3 length:sizeof(buf3)]; + + TestNewAMIOperationsCallback* cb = [TestNewAMIOperationsCallback create]; + [p begin_opShortIntLongS:ssi p2:isi p3:lsi response:^(TestOperationsMutableLongS* ret, TestOperationsMutableShortS* p4, TestOperationsMutableIntS* p5, TestOperationsMutableLongS* p6) { [cb opShortIntLongSResponse:ret p4:p4 p5:p5 p6:p6]; } exception:^(ICEException* ex) { [cb opShortIntLongSException:ex]; }]; + test([cb check]); + } + + { + ICEFloat buf1[] = { 3.14f, 1.11f }; + ICEDouble buf2[] = { 1.1E10, 1.2E10, 1.3E10 }; + + TestOperationsMutableFloatS *fsi = [TestOperationsMutableFloatS data]; + TestOperationsMutableDoubleS *dsi = [TestOperationsMutableDoubleS data]; + + [fsi appendBytes:buf1 length:sizeof(buf1)]; + [dsi appendBytes:buf2 length:sizeof(buf2)]; + + TestNewAMIOperationsCallback* cb = [TestNewAMIOperationsCallback create]; + [p begin_opFloatDoubleS:fsi p2:dsi response:^(TestOperationsMutableDoubleS* ret, TestOperationsMutableFloatS* p3, TestOperationsMutableDoubleS* p4) { [cb opFloatDoubleSResponse:ret p3:p3 p4:p4]; } exception:^(ICEException* ex) { [cb opFloatDoubleSException:ex]; }]; + test([cb check]); + } + + { + TestOperationsMutableStringS *ssi1 = [TestOperationsMutableStringS arrayWithCapacity:3]; + TestOperationsMutableStringS *ssi2 = [TestOperationsMutableStringS arrayWithCapacity:1]; + + [ssi1 addObject:@"abc"]; + [ssi1 addObject:@"de"]; + [ssi1 addObject:@"fghi"]; + + [ssi2 addObject:@"xyz"]; + + + TestNewAMIOperationsCallback* cb = [TestNewAMIOperationsCallback create]; + [p begin_opStringS:ssi1 p2:ssi2 response:^(TestOperationsMutableStringS* ret, TestOperationsMutableStringS* p3) { [cb opStringSResponse:ret p3:p3]; } exception:^(ICEException* ex) { [cb opStringSException:ex]; }]; + test([cb check]); + } + + { + TestOperationsMutableByteSS *bsi1 = [TestOperationsMutableByteSS array]; + TestOperationsMutableByteSS *bsi2 = [TestOperationsMutableByteSS array]; + + ICEByte b; + TestOperationsMutableByteS *tmp = [TestOperationsMutableByteS data]; + + b = 0x01; + [tmp appendBytes:&b length:sizeof(b)]; + b = 0x11; + [tmp appendBytes:&b length:sizeof(b)]; + b = 0x12; + [tmp appendBytes:&b length:sizeof(b)]; + [bsi1 addObject:tmp]; + + tmp = [TestOperationsMutableByteS data]; + b = 0xff; + [tmp appendBytes:&b length:sizeof(b)]; + [bsi1 addObject:tmp]; + + tmp = [TestOperationsMutableByteS data]; + b = 0x0e; + [tmp appendBytes:&b length:sizeof(b)]; + [bsi2 addObject:tmp]; + + tmp = [TestOperationsMutableByteS data]; + b = 0xf2; + [tmp appendBytes:&b length:sizeof(b)]; + b = 0xf1; + [tmp appendBytes:&b length:sizeof(b)]; + [bsi2 addObject:tmp]; + + TestNewAMIOperationsCallback* cb = [TestNewAMIOperationsCallback create]; + [p begin_opByteSS:bsi1 p2:bsi2 response:^(TestOperationsMutableByteSS* ret, TestOperationsMutableByteSS* p3) { [cb opByteSSResponse:ret p3:p3]; } exception:^(ICEException* ex) { [cb opByteSSException:ex]; }]; + test([cb check]); + } + + { + TestOperationsMutableFloatSS *fsi = [TestOperationsMutableFloatSS array]; + TestOperationsMutableDoubleSS *dsi = [TestOperationsMutableDoubleSS array]; + + ICEFloat f; + TestOperationsMutableFloatS *ftmp; + + ftmp = [TestOperationsMutableFloatS data]; + f = 3.14f; + [ftmp appendBytes:&f length:sizeof(f)]; + [fsi addObject:ftmp]; + ftmp = [TestOperationsMutableFloatS data]; + f = 1.11f; + [ftmp appendBytes:&f length:sizeof(f)]; + [fsi addObject:ftmp]; + ftmp = [TestOperationsMutableFloatS data]; + [fsi addObject:ftmp]; + + ICEDouble d; + TestOperationsMutableDoubleS *dtmp; + + dtmp = [TestOperationsMutableDoubleS data]; + d = 1.1E10; + [dtmp appendBytes:&d length:sizeof(d)]; + d = 1.2E10; + [dtmp appendBytes:&d length:sizeof(d)]; + d = 1.3E10; + [dtmp appendBytes:&d length:sizeof(d)]; + [dsi addObject:dtmp]; + + TestNewAMIOperationsCallback* cb = [TestNewAMIOperationsCallback create]; + [p begin_opFloatDoubleSS:fsi p2:dsi response:^(TestOperationsMutableDoubleSS* ret, TestOperationsMutableFloatSS* p3, TestOperationsMutableDoubleSS* p4) { [cb opFloatDoubleSSResponse:ret p3:p3 p4:p4]; } exception:^(ICEException* ex) { [cb opFloatDoubleSSException:ex]; }]; + test([cb check]); + } + + { + TestOperationsMutableStringSS * ssi1 = [TestOperationsMutableStringSS array]; + TestOperationsMutableStringSS * ssi2 = [TestOperationsMutableStringSS array]; + + TestOperationsMutableStringS *tmp; + + tmp = [TestOperationsMutableStringS array]; + [tmp addObject:@"abc"]; + [ssi1 addObject:tmp]; + tmp = [TestOperationsMutableStringS array]; + [tmp addObject:@"de"]; + [tmp addObject:@"fghi"]; + [ssi1 addObject:tmp]; + + [ssi2 addObject:[TestOperationsStringS array]]; + [ssi2 addObject:[TestOperationsStringS array]]; + tmp = [TestOperationsMutableStringS array]; + [tmp addObject:@"xyz"]; + [ssi2 addObject:tmp]; + + TestNewAMIOperationsCallback* cb = [TestNewAMIOperationsCallback create]; + [p begin_opStringSS:ssi1 p2:ssi2 response:^(TestOperationsMutableStringSS* ret, TestOperationsMutableStringSS* p3) { [cb opStringSSResponse:ret p3:p3]; } exception:^(ICEException* ex) { [cb opStringSSException:ex]; }]; + test([cb check]); + } + + { + TestOperationsMutableStringSSS *sssi1 = [TestOperationsMutableStringSSS array]; + TestOperationsMutableStringSSS *sssi2 = [TestOperationsMutableStringSSS array]; + + TestOperationsMutableStringSS *tmpss; + TestOperationsMutableStringS *tmps; + + tmps = [TestOperationsMutableStringS array]; + [tmps addObject:@"abc"]; + [tmps addObject:@"de"]; + tmpss = [TestOperationsMutableStringSS array]; + [tmpss addObject:tmps]; + tmps = [TestOperationsMutableStringS array]; + [tmps addObject:@"xyz"]; + [tmpss addObject:tmps]; + [sssi1 addObject:tmpss]; + tmps = [TestOperationsMutableStringS array]; + [tmps addObject:@"hello"]; + tmpss = [TestOperationsMutableStringSS array]; + [tmpss addObject:tmps]; + [sssi1 addObject:tmpss]; + + tmps = [TestOperationsMutableStringS array]; + [tmps addObject:@""]; + [tmps addObject:@""]; + tmpss = [TestOperationsMutableStringSS array]; + [tmpss addObject:tmps]; + tmps = [TestOperationsMutableStringS array]; + [tmps addObject:@"abcd"]; + [tmpss addObject:tmps]; + [sssi2 addObject:tmpss]; + tmps = [TestOperationsMutableStringS array]; + [tmps addObject:@""]; + tmpss = [TestOperationsMutableStringSS array]; + [tmpss addObject:tmps]; + [sssi2 addObject:tmpss]; + tmpss = [TestOperationsMutableStringSS array]; + [sssi2 addObject:tmpss]; + + TestNewAMIOperationsCallback* cb = [TestNewAMIOperationsCallback create]; + [p begin_opStringSSS:sssi1 p2:sssi2 response:^(TestOperationsMutableStringSS* ret, TestOperationsMutableStringSS* p3) { [cb opStringSSSResponse:ret p3:p3]; } exception:^(ICEException* ex) { [cb opStringSSSException:ex]; }]; + test([cb check]); + } + + { + TestOperationsMutableByteBoolD *di1 = [TestOperationsMutableByteBoolD dictionary]; + [di1 setObject:[NSNumber numberWithBool:YES] forKey:[NSNumber numberWithUnsignedChar:10]]; + [di1 setObject:[NSNumber numberWithBool:NO] forKey:[NSNumber numberWithUnsignedChar:100]]; + TestOperationsMutableByteBoolD *di2 = [TestOperationsMutableByteBoolD dictionary]; + [di2 setObject:[NSNumber numberWithBool:YES] forKey:[NSNumber numberWithUnsignedChar:10]]; + [di2 setObject:[NSNumber numberWithBool:NO] forKey:[NSNumber numberWithUnsignedChar:11]]; + [di2 setObject:[NSNumber numberWithBool:TRUE] forKey:[NSNumber numberWithUnsignedChar:101]]; + + TestNewAMIOperationsCallback* cb = [TestNewAMIOperationsCallback create]; + [p begin_opByteBoolD:di1 p2:di2 response:^(TestOperationsMutableByteBoolD* ret, TestOperationsMutableByteBoolD* p3) { [cb opByteBoolDResponse:ret p3:p3]; } exception:^(ICEException* ex) { [cb opByteBoolDException:ex]; }]; + test([cb check]); + } + + { + TestOperationsMutableShortIntD *di1 = [TestOperationsMutableShortIntD dictionary]; + [di1 setObject:[NSNumber numberWithInt:-1] forKey:[NSNumber numberWithShort:110]]; + [di1 setObject:[NSNumber numberWithInt:123123] forKey:[NSNumber numberWithShort:1100]]; + TestOperationsMutableShortIntD *di2 = [TestOperationsMutableShortIntD dictionary]; + [di2 setObject:[NSNumber numberWithInt:-1] forKey:[NSNumber numberWithShort:110]]; + [di2 setObject:[NSNumber numberWithInt:-100] forKey:[NSNumber numberWithShort:111]]; + [di2 setObject:[NSNumber numberWithInt:0] forKey:[NSNumber numberWithShort:1101]]; + + TestNewAMIOperationsCallback* cb = [TestNewAMIOperationsCallback create]; + [p begin_opShortIntD:di1 p2:di2 response:^(TestOperationsMutableShortIntD* ret, TestOperationsMutableShortIntD* p3) { [cb opShortIntDResponse:ret p3:p3]; } exception:^(ICEException* ex) { [cb opShortIntDException:ex]; }]; + test([cb check]); + } + + { + TestOperationsMutableLongFloatD *di1 = [TestOperationsMutableLongFloatD dictionary]; + [di1 setObject:[NSNumber numberWithFloat:-1.1f] forKey:[NSNumber numberWithLong:999999110]]; + [di1 setObject:[NSNumber numberWithFloat:123123.2f] forKey:[NSNumber numberWithLong:999999111]]; + TestOperationsMutableLongFloatD *di2 = [TestOperationsMutableLongFloatD dictionary]; + [di2 setObject:[NSNumber numberWithFloat:-1.1f] forKey:[NSNumber numberWithLong:999999110]]; + [di2 setObject:[NSNumber numberWithFloat:-100.4f] forKey:[NSNumber numberWithLong:999999120]]; + [di2 setObject:[NSNumber numberWithFloat:0.5f] forKey:[NSNumber numberWithLong:999999130]]; + + TestNewAMIOperationsCallback* cb = [TestNewAMIOperationsCallback create]; + [p begin_opLongFloatD:di1 p2:di2 response:^(TestOperationsMutableLongFloatD* ret, TestOperationsMutableLongFloatD* p3) { [cb opLongFloatDResponse:ret p3:p3]; } exception:^(ICEException* ex) { [cb opLongFloatDException:ex]; }]; + test([cb check]); + } + + { + TestOperationsMutableStringStringD *di1 = [TestOperationsMutableStringStringD dictionary]; + [di1 setObject:@"abc -1.1" forKey:@"foo"]; + [di1 setObject:@"abc 123123.2" forKey:@"bar"]; + TestOperationsMutableStringStringD *di2 = [TestOperationsMutableStringStringD dictionary]; + [di2 setObject:@"abc -1.1" forKey:@"foo"]; + [di2 setObject:@"abc -100.4" forKey:@"FOO"]; + [di2 setObject:@"abc 0.5" forKey:@"BAR"]; + + + TestNewAMIOperationsCallback* cb = [TestNewAMIOperationsCallback create]; + [p begin_opStringStringD:di1 p2:di2 response:^(TestOperationsMutableStringStringD* ret, TestOperationsMutableStringStringD* p3) { [cb opStringStringDResponse:ret p3:p3]; } exception:^(ICEException* ex) { [cb opStringStringDException:ex]; }]; + test([cb check]); + } + + { + TestOperationsMutableStringMyEnumD *di1 = [TestOperationsMutableStringMyEnumD dictionary]; + [di1 setObject:[NSNumber numberWithInt:TestOperationsenum1] forKey:@"abc"]; + [di1 setObject:[NSNumber numberWithInt:TestOperationsenum2] forKey:@""]; + TestOperationsMutableStringMyEnumD *di2 = [TestOperationsMutableStringMyEnumD dictionary]; + [di2 setObject:[NSNumber numberWithInt:TestOperationsenum1] forKey:@"abc"]; + [di2 setObject:[NSNumber numberWithInt:TestOperationsenum3] forKey:@"querty"]; + [di2 setObject:[NSNumber numberWithInt:TestOperationsenum2] forKey:@"Hello!!"]; + + TestNewAMIOperationsCallback* cb = [TestNewAMIOperationsCallback create]; + [p begin_opStringMyEnumD:di1 p2:di2 response:^(TestOperationsMutableStringMyEnumD* ret, TestOperationsMutableStringMyEnumD* p3) { [cb opStringMyEnumDResponse:ret p3:p3]; } exception:^(ICEException* ex) { [cb opStringMyEnumDException:ex]; }]; + test([cb check]); + } + + { + TestOperationsMutableMyEnumStringD *di1 = [TestOperationsMutableMyEnumStringD dictionary]; + [di1 setObject:@"abc" forKey:@(TestOperationsenum1)]; + TestOperationsMutableMyEnumStringD *di2 = [TestOperationsMutableMyEnumStringD dictionary]; + [di2 setObject:@"Hello!!" forKey:@(TestOperationsenum2)]; + [di2 setObject:@"querty" forKey:@(TestOperationsenum3)]; + + TestNewAMIOperationsCallback* cb = [TestNewAMIOperationsCallback create]; + [p begin_opMyEnumStringD:di1 + p2:di2 + response:^(TestOperationsMutableMyEnumStringD* ret, + TestOperationsMutableMyEnumStringD* p3) { [cb opMyEnumStringDResponse:ret + p3:p3]; } + exception:^(ICEException* ex) { [cb opMyEnumStringDException:ex]; }]; + [cb check]; + } + + { + TestOperationsMyStruct* s11 = [TestOperationsMyStruct myStruct:1 j:1]; + TestOperationsMyStruct* s12 = [TestOperationsMyStruct myStruct:1 j:2]; + TestOperationsMutableMyStructMyEnumD* di1 = [TestOperationsMutableMyStructMyEnumD dictionary]; + [di1 setObject:@(TestOperationsenum1) forKey:s11]; + [di1 setObject:@(TestOperationsenum2) forKey:s12]; + + TestOperationsMyStruct* s22 = [TestOperationsMyStruct myStruct:2 j:2]; + TestOperationsMyStruct* s23 = [TestOperationsMyStruct myStruct:2 j:3]; + TestOperationsMutableMyStructMyEnumD* di2 = [TestOperationsMutableMyStructMyEnumD dictionary]; + [di2 setObject:@(TestOperationsenum1) forKey:s11]; + [di2 setObject:@(TestOperationsenum3) forKey:s22]; + [di2 setObject:@(TestOperationsenum2) forKey:s23]; + + TestNewAMIOperationsCallback* cb = [TestNewAMIOperationsCallback create]; + [p begin_opMyStructMyEnumD:di1 + p2:di2 + response:^(TestOperationsMutableMyStructMyEnumD* ret, + TestOperationsMutableMyStructMyEnumD* p3) { [cb opMyStructMyEnumDResponse:ret + p3:p3 + s11:s11 + s12:s12 + s22:s22 + s23:s23]; } + exception:^(ICEException* ex) { [cb opMyStructMyEnumDException:ex]; }]; + [cb check]; + } + + { + TestOperationsMutableByteBoolDS* dsi1 = [TestOperationsMutableByteBoolDS array]; + TestOperationsMutableByteBoolDS* dsi2 = [TestOperationsMutableByteBoolDS array]; + + TestOperationsMutableByteBoolD *di1 = [TestOperationsMutableByteBoolD dictionary]; + [di1 setObject:[NSNumber numberWithBool:YES] forKey:[NSNumber numberWithUnsignedChar:10]]; + [di1 setObject:[NSNumber numberWithBool:NO] forKey:[NSNumber numberWithUnsignedChar:100]]; + TestOperationsMutableByteBoolD *di2 = [TestOperationsMutableByteBoolD dictionary]; + [di2 setObject:[NSNumber numberWithBool:YES] forKey:[NSNumber numberWithUnsignedChar:10]]; + [di2 setObject:[NSNumber numberWithBool:NO] forKey:[NSNumber numberWithUnsignedChar:11]]; + [di2 setObject:[NSNumber numberWithBool:TRUE] forKey:[NSNumber numberWithUnsignedChar:101]]; + TestOperationsMutableByteBoolD *di3 = [TestOperationsMutableByteBoolD dictionary]; + [di3 setObject:[NSNumber numberWithBool:NO] forKey:[NSNumber numberWithUnsignedChar:100]]; + [di3 setObject:[NSNumber numberWithBool:NO] forKey:[NSNumber numberWithUnsignedChar:101]]; + + [dsi1 addObject:di1]; + [dsi1 addObject:di2]; + [dsi2 addObject:di3]; + + TestNewAMIOperationsCallback* cb = [TestNewAMIOperationsCallback create]; + [p begin_opByteBoolDS:dsi1 + p2:dsi2 + response:^(TestOperationsMutableByteBoolDS* ret, + TestOperationsMutableByteBoolDS* p3) { [cb opByteBoolDSResponse:ret + p3:p3]; } + exception:^(ICEException* ex) { [cb opByteBoolDSException:ex]; }]; + [cb check]; + } + + { + TestOperationsMutableShortIntDS *dsi1 = [TestOperationsMutableShortIntDS array]; + TestOperationsMutableShortIntDS *dsi2 = [TestOperationsMutableShortIntDS array]; + + TestOperationsMutableShortIntD *di1 = [TestOperationsMutableShortIntD dictionary]; + [di1 setObject:[NSNumber numberWithInt:-1] forKey:[NSNumber numberWithShort:110]]; + [di1 setObject:[NSNumber numberWithInt:123123] forKey:[NSNumber numberWithShort:1100]]; + TestOperationsMutableShortIntD *di2 = [TestOperationsMutableShortIntD dictionary]; + [di2 setObject:[NSNumber numberWithInt:-1] forKey:[NSNumber numberWithShort:110]]; + [di2 setObject:[NSNumber numberWithInt:-100] forKey:[NSNumber numberWithShort:111]]; + [di2 setObject:[NSNumber numberWithInt:0] forKey:[NSNumber numberWithShort:1101]]; + TestOperationsMutableShortIntD *di3 = [TestOperationsMutableShortIntD dictionary]; + [di3 setObject:[NSNumber numberWithInt:-1001] forKey:[NSNumber numberWithShort:100]]; + + [dsi1 addObject:di1]; + [dsi1 addObject:di2]; + [dsi2 addObject:di3]; + + TestNewAMIOperationsCallback* cb = [TestNewAMIOperationsCallback create]; + [p begin_opShortIntDS:dsi1 + p2:dsi2 + response:^(TestOperationsMutableShortIntDS* ret, + TestOperationsMutableShortIntDS* p3) { [cb opShortIntDSResponse:ret + p3:p3]; } + exception:^(ICEException* ex) { [cb opShortIntDSException:ex]; }]; + [cb check]; + } + + { + TestOperationsMutableLongFloatDS *dsi1 = [TestOperationsMutableLongFloatDS array]; + TestOperationsMutableLongFloatDS *dsi2 = [TestOperationsMutableLongFloatDS array]; + + TestOperationsMutableLongFloatD *di1 = [TestOperationsMutableLongFloatD dictionary]; + [di1 setObject:[NSNumber numberWithFloat:-1.1f] forKey:[NSNumber numberWithLong:999999110]]; + [di1 setObject:[NSNumber numberWithFloat:123123.2f] forKey:[NSNumber numberWithLong:999999111]]; + TestOperationsMutableLongFloatD *di2 = [TestOperationsMutableLongFloatD dictionary]; + [di2 setObject:[NSNumber numberWithFloat:-1.1f] forKey:[NSNumber numberWithLong:999999110]]; + [di2 setObject:[NSNumber numberWithFloat:-100.4f] forKey:[NSNumber numberWithLong:999999120]]; + [di2 setObject:[NSNumber numberWithFloat:0.5f] forKey:[NSNumber numberWithLong:999999130]]; + TestOperationsMutableLongFloatD *di3 = [TestOperationsMutableLongFloatD dictionary]; + [di3 setObject:[NSNumber numberWithFloat:3.14f] forKey:[NSNumber numberWithLong:999999140]]; + + [dsi1 addObject:di1]; + [dsi1 addObject:di2]; + [dsi2 addObject:di3]; + + TestNewAMIOperationsCallback* cb = [TestNewAMIOperationsCallback create]; + [p begin_opLongFloatDS:dsi1 + p2:dsi2 + response:^(TestOperationsMutableLongFloatDS* ret, + TestOperationsMutableLongFloatDS* p3) { [cb opLongFloatDSResponse:ret + p3:p3]; } + exception:^(ICEException* ex) { [cb opLongFloatDSException:ex]; }]; + [cb check]; + } + + { + TestOperationsMutableStringStringDS *dsi1 = [TestOperationsMutableStringStringDS array]; + TestOperationsMutableStringStringDS *dsi2 = [TestOperationsMutableStringStringDS array]; + + TestOperationsMutableStringStringD *di1 = [TestOperationsMutableStringStringD dictionary]; + [di1 setObject:@"abc -1.1" forKey:@"foo"]; + [di1 setObject:@"abc 123123.2" forKey:@"bar"]; + TestOperationsMutableStringStringD *di2 = [TestOperationsMutableStringStringD dictionary]; + [di2 setObject:@"abc -1.1" forKey:@"foo"]; + [di2 setObject:@"abc -100.4" forKey:@"FOO"]; + [di2 setObject:@"abc 0.5" forKey:@"BAR"]; + TestOperationsMutableStringStringD *di3 = [TestOperationsMutableStringStringD dictionary]; + [di3 setObject:@"ABC -3.14" forKey:@"f00"]; + + [dsi1 addObject:di1]; + [dsi1 addObject:di2]; + [dsi2 addObject:di3]; + + TestNewAMIOperationsCallback* cb = [TestNewAMIOperationsCallback create]; + [p begin_opStringStringDS:dsi1 + p2:dsi2 + response:^(TestOperationsMutableStringStringDS* ret, + TestOperationsMutableStringStringDS* p3) { [cb opStringStringDSResponse:ret + p3:p3]; } + exception:^(ICEException* ex) { [cb opStringStringDSException:ex]; }]; + [cb check]; + } + + { + TestOperationsMutableStringMyEnumDS *dsi1 = [TestOperationsMutableStringMyEnumDS array]; + TestOperationsMutableStringMyEnumDS *dsi2 = [TestOperationsMutableStringMyEnumDS array]; + + TestOperationsMutableStringMyEnumD *di1 = [TestOperationsMutableStringMyEnumD dictionary]; + [di1 setObject:[NSNumber numberWithInt:TestOperationsenum1] forKey:@"abc"]; + [di1 setObject:[NSNumber numberWithInt:TestOperationsenum2] forKey:@""]; + TestOperationsMutableStringMyEnumD *di2 = [TestOperationsMutableStringMyEnumD dictionary]; + [di2 setObject:[NSNumber numberWithInt:TestOperationsenum1] forKey:@"abc"]; + [di2 setObject:[NSNumber numberWithInt:TestOperationsenum3] forKey:@"querty"]; + [di2 setObject:[NSNumber numberWithInt:TestOperationsenum2] forKey:@"Hello!!"]; + TestOperationsMutableStringMyEnumD *di3 = [TestOperationsMutableStringMyEnumD dictionary]; + [di3 setObject:[NSNumber numberWithInt:TestOperationsenum1] forKey:@"Goodbye"]; + + [dsi1 addObject:di1]; + [dsi1 addObject:di2]; + [dsi2 addObject:di3]; + + TestNewAMIOperationsCallback* cb = [TestNewAMIOperationsCallback create]; + [p begin_opStringMyEnumDS:dsi1 + p2:dsi2 + response:^(TestOperationsMutableStringMyEnumDS* ret, + TestOperationsMutableStringMyEnumDS* p3) { [cb opStringMyEnumDSResponse:ret + p3:p3]; } + exception:^(ICEException* ex) { [cb opStringMyEnumDSException:ex]; }]; + [cb check]; + } + + { + TestOperationsMutableMyEnumStringDS *dsi1 = [TestOperationsMutableMyEnumStringDS array]; + TestOperationsMutableMyEnumStringDS *dsi2 = [TestOperationsMutableMyEnumStringDS array]; + + TestOperationsMutableMyEnumStringD *di1 = [TestOperationsMutableMyEnumStringD dictionary]; + [di1 setObject:@"abc" forKey:@(TestOperationsenum1)]; + TestOperationsMutableMyEnumStringD *di2 = [TestOperationsMutableMyEnumStringD dictionary]; + [di2 setObject:@"Hello!!" forKey:@(TestOperationsenum2)]; + [di2 setObject:@"querty" forKey:@(TestOperationsenum3)]; + TestOperationsMutableMyEnumStringD *di3 = [TestOperationsMutableMyEnumStringD dictionary]; + [di3 setObject:@"Goodbye" forKey:@(TestOperationsenum1)]; + + [dsi1 addObject:di1]; + [dsi1 addObject:di2]; + [dsi2 addObject:di3]; + + TestNewAMIOperationsCallback* cb = [TestNewAMIOperationsCallback create]; + [p begin_opMyEnumStringDS:dsi1 + p2:dsi2 + response:^(TestOperationsMutableMyEnumStringDS* ret, + TestOperationsMutableMyEnumStringDS* p3) { [cb opMyEnumStringDSResponse:ret + p3:p3]; } + exception:^(ICEException* ex) { [cb opMyEnumStringDSException:ex]; }]; + [cb check]; + } + + { + TestOperationsMutableMyStructMyEnumDS *dsi1 = [TestOperationsMutableMyStructMyEnumDS array]; + TestOperationsMutableMyStructMyEnumDS *dsi2 = [TestOperationsMutableMyStructMyEnumDS array]; + + TestOperationsMyStruct* s11 = [TestOperationsMyStruct myStruct:1 j:1]; + TestOperationsMyStruct* s12 = [TestOperationsMyStruct myStruct:1 j:2]; + TestOperationsMutableMyStructMyEnumD* di1 = [TestOperationsMutableMyStructMyEnumD dictionary]; + [di1 setObject:[NSNumber numberWithInt:TestOperationsenum1] forKey:s11]; + [di1 setObject:[NSNumber numberWithInt:TestOperationsenum2] forKey:s12]; + + TestOperationsMyStruct* s22 = [TestOperationsMyStruct myStruct:2 j:2]; + TestOperationsMyStruct* s23 = [TestOperationsMyStruct myStruct:2 j:3]; + TestOperationsMutableMyStructMyEnumD* di2 = [TestOperationsMutableMyStructMyEnumD dictionary]; + [di2 setObject:[NSNumber numberWithInt:TestOperationsenum1] forKey:s11]; + [di2 setObject:[NSNumber numberWithInt:TestOperationsenum3] forKey:s22]; + [di2 setObject:[NSNumber numberWithInt:TestOperationsenum2] forKey:s23]; + + TestOperationsMutableMyStructMyEnumD* di3 = [TestOperationsMutableMyStructMyEnumD dictionary]; + [di3 setObject:[NSNumber numberWithInt:TestOperationsenum3] forKey:s23]; + + [dsi1 addObject:di1]; + [dsi1 addObject:di2]; + [dsi2 addObject:di3]; + + TestNewAMIOperationsCallback* cb = [TestNewAMIOperationsCallback create]; + [p begin_opMyStructMyEnumDS:dsi1 + p2:dsi2 + response:^(TestOperationsMutableMyStructMyEnumDS* ret, + TestOperationsMutableMyStructMyEnumDS* p3) { [cb opMyStructMyEnumDSResponse:ret + p3:p3 + s11:s11 + s12:s12 + s22:s22 + s23:s23]; } + exception:^(ICEException* ex) { [cb opMyStructMyEnumDSException:ex]; }]; + [cb check]; + } + + { + TestOperationsMutableByteByteSD *sdi1 = [TestOperationsMutableByteByteSD dictionary]; + TestOperationsMutableByteByteSD *sdi2 = [TestOperationsMutableByteByteSD dictionary]; + + ICEByte buf1[] = { 0x01, 0x11 }; + ICEByte buf2[] = { 0x12 }; + ICEByte buf3[] = { 0xf2, 0xf3 }; + + TestOperationsMutableByteS *si1 = [TestOperationsMutableBoolS data]; + TestOperationsMutableBoolS *si2 = [TestOperationsMutableBoolS data]; + TestOperationsMutableBoolS *si3 = [TestOperationsMutableBoolS data]; + + [si1 appendBytes:buf1 length:sizeof(buf1)]; + [si2 appendBytes:buf2 length:sizeof(buf2)]; + [si3 appendBytes:buf3 length:sizeof(buf3)]; + + [sdi1 setObject:si1 forKey:[NSNumber numberWithUnsignedChar:(ICEByte)0x01]]; + [sdi1 setObject:si2 forKey:[NSNumber numberWithUnsignedChar:(ICEByte)0x22]]; + [sdi2 setObject:si3 forKey:[NSNumber numberWithUnsignedChar:(ICEByte)0xf1]]; + + TestNewAMIOperationsCallback* cb = [TestNewAMIOperationsCallback create]; + [p begin_opByteByteSD:sdi1 + p2:sdi2 + response:^(TestOperationsMutableByteByteSD* ret, + TestOperationsMutableByteByteSD* p3) { [cb opByteByteSDResponse:ret + p3:p3]; } + exception:^(ICEException* ex) { [cb opByteByteSDException:ex]; }]; + [cb check]; + } + + { + TestOperationsMutableBoolBoolSD *sdi1 = [TestOperationsMutableBoolBoolSD dictionary]; + TestOperationsMutableBoolBoolSD *sdi2 = [TestOperationsMutableBoolBoolSD dictionary]; + + BOOL buf1[] = { YES, NO }; + BOOL buf2[] = { NO, YES, YES }; + + TestOperationsMutableBoolS *si1 = [TestOperationsMutableBoolS data]; + TestOperationsMutableBoolS *si2 = [TestOperationsMutableBoolS data]; + + [si1 appendBytes:buf1 length:sizeof(buf1)]; + [si2 appendBytes:buf2 length:sizeof(buf2)]; + + [sdi1 setObject:si1 forKey:[NSNumber numberWithBool:NO]]; + [sdi1 setObject:si2 forKey:[NSNumber numberWithBool:YES]]; + [sdi2 setObject:si1 forKey:[NSNumber numberWithBool:NO]]; + + TestNewAMIOperationsCallback* cb = [TestNewAMIOperationsCallback create]; + [p begin_opBoolBoolSD:sdi1 + p2:sdi2 + response:^(TestOperationsMutableBoolBoolSD* ret, + TestOperationsMutableBoolBoolSD* p3) { [cb opBoolBoolSDResponse:ret + p3:p3]; } + exception:^(ICEException* ex) { [cb opBoolBoolSDException:ex]; }]; + [cb check]; + } + + { + TestOperationsMutableShortShortSD *sdi1 = [TestOperationsMutableShortShortSD dictionary]; + TestOperationsMutableShortShortSD *sdi2 = [TestOperationsMutableShortShortSD dictionary]; + + ICEShort buf1[] = { 1, 2, 3 }; + ICEShort buf2[] = { 4, 5 }; + ICEShort buf3[] = { 6, 7 }; + + TestOperationsMutableShortS *si1 = [TestOperationsMutableShortS data]; + TestOperationsMutableShortS *si2 = [TestOperationsMutableShortS data]; + TestOperationsMutableShortS *si3 = [TestOperationsMutableShortS data]; + + [si1 appendBytes:buf1 length:sizeof(buf1)]; + [si2 appendBytes:buf2 length:sizeof(buf2)]; + [si3 appendBytes:buf3 length:sizeof(buf3)]; + + [sdi1 setObject:si1 forKey:[NSNumber numberWithShort:1]]; + [sdi1 setObject:si2 forKey:[NSNumber numberWithShort:2]]; + [sdi2 setObject:si3 forKey:[NSNumber numberWithShort:4]]; + + TestNewAMIOperationsCallback* cb = [TestNewAMIOperationsCallback create]; + [p begin_opShortShortSD:sdi1 + p2:sdi2 + response:^(TestOperationsMutableShortShortSD* ret, + TestOperationsMutableShortShortSD* p3) { [cb opShortShortSDResponse:ret + p3:p3]; } + exception:^(ICEException* ex) { [cb opShortShortSDException:ex]; }]; + [cb check]; + } + + { + TestOperationsMutableIntIntSD *sdi1 = [TestOperationsMutableIntIntSD dictionary]; + TestOperationsMutableIntIntSD *sdi2 = [TestOperationsMutableIntIntSD dictionary]; + + ICEInt buf1[] = { 100, 200, 300 }; + ICEInt buf2[] = { 400, 500 }; + ICEInt buf3[] = { 600, 700 }; + + TestOperationsMutableIntS *si1 = [TestOperationsMutableIntS data]; + TestOperationsMutableIntS *si2 = [TestOperationsMutableIntS data]; + TestOperationsMutableIntS *si3 = [TestOperationsMutableIntS data]; + + [si1 appendBytes:buf1 length:sizeof(buf1)]; + [si2 appendBytes:buf2 length:sizeof(buf2)]; + [si3 appendBytes:buf3 length:sizeof(buf3)]; + + [sdi1 setObject:si1 forKey:[NSNumber numberWithInt:100]]; + [sdi1 setObject:si2 forKey:[NSNumber numberWithInt:200]]; + [sdi2 setObject:si3 forKey:[NSNumber numberWithInt:400]]; + + TestNewAMIOperationsCallback* cb = [TestNewAMIOperationsCallback create]; + [p begin_opIntIntSD:sdi1 + p2:sdi2 + response:^(TestOperationsMutableIntIntSD* ret, + TestOperationsMutableIntIntSD* p3) { [cb opIntIntSDResponse:ret + p3:p3]; } + exception:^(ICEException* ex) { [cb opIntIntSDException:ex]; }]; + [cb check]; + } + + { + TestOperationsMutableLongLongSD *sdi1 = [TestOperationsMutableLongLongSD dictionary]; + TestOperationsMutableLongLongSD *sdi2 = [TestOperationsMutableLongLongSD dictionary]; + + ICELong buf1[] = { 999999110, 999999111, 999999110 }; + ICELong buf2[] = { 999999120, 999999130 }; + ICELong buf3[] = { 999999110, 999999120 }; + + TestOperationsMutableLongS *si1 = [TestOperationsMutableLongS data]; + TestOperationsMutableLongS *si2 = [TestOperationsMutableLongS data]; + TestOperationsMutableLongS *si3 = [TestOperationsMutableLongS data]; + + [si1 appendBytes:buf1 length:sizeof(buf1)]; + [si2 appendBytes:buf2 length:sizeof(buf2)]; + [si3 appendBytes:buf3 length:sizeof(buf3)]; + + [sdi1 setObject:si1 forKey:[NSNumber numberWithLong:999999990]]; + [sdi1 setObject:si2 forKey:[NSNumber numberWithLong:999999991]]; + [sdi2 setObject:si3 forKey:[NSNumber numberWithLong:999999992]]; + + TestNewAMIOperationsCallback* cb = [TestNewAMIOperationsCallback create]; + [p begin_opLongLongSD:sdi1 + p2:sdi2 + response:^(TestOperationsMutableLongLongSD* ret, + TestOperationsMutableLongLongSD* p3) { [cb opLongLongSDResponse:ret + p3:p3]; } + exception:^(ICEException* ex) { [cb opLongLongSDException:ex]; }]; + [cb check]; + } + + { + TestOperationsMutableStringFloatSD *sdi1 = [TestOperationsMutableStringFloatSD dictionary]; + TestOperationsMutableStringFloatSD *sdi2 = [TestOperationsMutableStringFloatSD dictionary]; + + ICEFloat buf1[] = { -1.1f, 123123.2f, 100.0f }; + ICEFloat buf2[] = { 42.24f, -1.61f }; + ICEFloat buf3[] = { -3.14, 3.14 }; + + TestOperationsMutableFloatS *si1 = [TestOperationsMutableFloatS data]; + TestOperationsMutableFloatS *si2 = [TestOperationsMutableFloatS data]; + TestOperationsMutableFloatS *si3 = [TestOperationsMutableFloatS data]; + + [si1 appendBytes:buf1 length:sizeof(buf1)]; + [si2 appendBytes:buf2 length:sizeof(buf2)]; + [si3 appendBytes:buf3 length:sizeof(buf3)]; + + [sdi1 setObject:si1 forKey:@"abc"]; + [sdi1 setObject:si2 forKey:@"ABC"]; + [sdi2 setObject:si3 forKey:@"aBc"]; + + TestNewAMIOperationsCallback* cb = [TestNewAMIOperationsCallback create]; + [p begin_opStringFloatSD:sdi1 + p2:sdi2 + response:^(TestOperationsMutableStringFloatSD* ret, + TestOperationsMutableStringFloatSD* p3) { [cb opStringFloatSDResponse:ret + p3:p3]; } + exception:^(ICEException* ex) { [cb opStringFloatSDException:ex]; }]; + [cb check]; + } + + { + TestOperationsMutableStringDoubleSD *sdi1 = [TestOperationsMutableStringDoubleSD dictionary]; + TestOperationsMutableStringDoubleSD *sdi2 = [TestOperationsMutableStringDoubleSD dictionary]; + + ICEDouble buf1[] = { 1.1E10, 1.2E10, 1.3E10 }; + ICEDouble buf2[] = { 1.4E10, 1.5E10 }; + ICEDouble buf3[] = { 1.6E10, 1.7E10 }; + + TestOperationsMutableDoubleS *si1 = [TestOperationsMutableDoubleS data]; + TestOperationsMutableDoubleS *si2 = [TestOperationsMutableDoubleS data]; + TestOperationsMutableDoubleS *si3 = [TestOperationsMutableDoubleS data]; + + [si1 appendBytes:buf1 length:sizeof(buf1)]; + [si2 appendBytes:buf2 length:sizeof(buf2)]; + [si3 appendBytes:buf3 length:sizeof(buf3)]; + + [sdi1 setObject:si1 forKey:@"Hello!!"]; + [sdi1 setObject:si2 forKey:@"Goodbye"]; + [sdi2 setObject:si3 forKey:@""]; + + TestNewAMIOperationsCallback* cb = [TestNewAMIOperationsCallback create]; + [p begin_opStringDoubleSD:sdi1 + p2:sdi2 + response:^(TestOperationsMutableStringDoubleSD* ret, + TestOperationsMutableStringDoubleSD* p3) { [cb opStringDoubleSDResponse:ret + p3:p3]; } + exception:^(ICEException* ex) { [cb opStringDoubleSDException:ex]; }]; + [cb check]; + } + + { + TestOperationsMutableStringStringSD *sdi1 = [TestOperationsMutableStringStringSD dictionary]; + TestOperationsMutableStringStringSD *sdi2 = [TestOperationsMutableStringStringSD dictionary]; + + TestOperationsMutableStringS *si1 = [TestOperationsMutableStringS array]; + TestOperationsMutableStringS *si2 = [TestOperationsMutableStringS array]; + TestOperationsMutableStringS *si3 = [TestOperationsMutableStringS array]; + + [si1 addObject:@"abc"]; + [si1 addObject:@"de"]; + [si1 addObject:@"fghi"]; + [si2 addObject:@"xyz"]; + [si2 addObject:@"or"]; + [si3 addObject:@"and"]; + [si3 addObject:@"xor"]; + + [sdi1 setObject:si1 forKey:@"abc"]; + [sdi1 setObject:si2 forKey:@"def"]; + [sdi2 setObject:si3 forKey:@"ghi"]; + + TestNewAMIOperationsCallback* cb = [TestNewAMIOperationsCallback create]; + [p begin_opStringStringSD:sdi1 + p2:sdi2 + response:^(TestOperationsMutableStringStringSD* ret, + TestOperationsMutableStringStringSD* p3) { [cb opStringStringSDResponse:ret + p3:p3]; } + exception:^(ICEException* ex) { [cb opStringStringSDException:ex]; }]; + [cb check]; + } + + { + TestOperationsMutableMyEnumMyEnumSD *sdi1 = [TestOperationsMutableMyEnumMyEnumSD dictionary]; + TestOperationsMutableMyEnumMyEnumSD *sdi2 = [TestOperationsMutableMyEnumMyEnumSD dictionary]; + + + TestOperationsMyEnum buf1[] = { TestOperationsenum1, TestOperationsenum1, TestOperationsenum2 }; + TestOperationsMyEnum buf2[] = { TestOperationsenum1, TestOperationsenum2 }; + TestOperationsMyEnum buf3[] = { TestOperationsenum3, TestOperationsenum3 }; + + TestOperationsMutableMyEnumS *si1 = [TestOperationsMutableMyEnumS data]; + TestOperationsMutableMyEnumS *si2 = [TestOperationsMutableMyEnumS data]; + TestOperationsMutableMyEnumS *si3 = [TestOperationsMutableMyEnumS data]; + + [si1 appendBytes:buf1 length:sizeof(buf1)]; + [si2 appendBytes:buf2 length:sizeof(buf2)]; + [si3 appendBytes:buf3 length:sizeof(buf3)]; + + [sdi1 setObject:si1 forKey:@(TestOperationsenum3)]; + [sdi1 setObject:si2 forKey:@(TestOperationsenum2)]; + [sdi2 setObject:si3 forKey:@(TestOperationsenum1)]; + + TestNewAMIOperationsCallback* cb = [TestNewAMIOperationsCallback create]; + [p begin_opMyEnumMyEnumSD:sdi1 + p2:sdi2 + response:^(TestOperationsMutableMyEnumMyEnumSD* ret, + TestOperationsMutableMyEnumMyEnumSD* p3) { [cb opMyEnumMyEnumSDResponse:ret + p3:p3]; } + exception:^(ICEException* ex) { [cb opMyEnumMyEnumSDException:ex]; }]; + [cb check]; + } + + { + const int lengths[] = { 0, 1, 2, 126, 127, 128, 129, 253, 254, 255, 256, 257, 1000 }; + + int l; + for(l = 0; l != sizeof(lengths) / sizeof(*lengths); ++l) + { + TestOperationsMutableIntS *s = [TestOperationsMutableIntS dataWithLength:(lengths[l] * sizeof(ICEInt))]; + ICEInt *ip = (ICEInt *)[s bytes]; + int i; + for(i = 0; i < lengths[l]; ++i) + { + *ip++ = i; + } + + TestNewAMIOperationsCallback* cb = [TestNewAMIOperationsCallback create]; + [p begin_opIntS:s response:^(TestOperationsMutableIntS* ret) { [cb opIntSResponse:ret]; } exception:^(ICEException* ex) { [cb opIntSException:ex]; }]; + test([cb check]); + } + } + + { + ICEMutableContext *ctx = [ICEMutableContext dictionary]; + [ctx setObject:@"ONE" forKey:@"one"]; + [ctx setObject:@"TWO" forKey:@"two"]; + [ctx setObject:@"THREE" forKey:@"three"]; + { + TestNewAMIOperationsCallback* cb = [TestNewAMIOperationsCallback create]; + [p begin_opContext:^(ICEMutableContext* ctx) { [cb opEmptyContextResponse:ctx]; } exception:^(ICEException* ex) { [cb opContextException:ex]; }]; + test([cb check]); + } + { + TestNewAMIOperationsCallback* cb = [TestNewAMIOperationsCallback create]; + [p begin_opContext:ctx response:^(ICEMutableContext* ctx) { [cb opNonEmptyContextResponse:ctx]; } exception:^(ICEException* ex) { [cb opContextException:ex]; }]; + test([cb check]); + } + { + id<TestOperationsMyClassPrx> p2 = [TestOperationsMyClassPrx checkedCast:[p ice_context:ctx]]; + test([[p2 ice_getContext] isEqual:ctx]); + TestNewAMIOperationsCallback* cb = [TestNewAMIOperationsCallback create]; + [p2 begin_opContext:^(ICEMutableContext* ctx) { [cb opNonEmptyContextResponse:ctx]; } exception:^(ICEException* ex) { [cb opContextException:ex]; }]; + test([cb check]); + + + cb = [TestNewAMIOperationsCallback create]; + [p2 begin_opContext:ctx response:^(ICEMutableContext* ctx) { [cb opNonEmptyContextResponse:ctx]; } exception:^(ICEException* ex) { [cb opContextException:ex]; }]; + test([cb check]); + } + } + + if([p ice_getConnection]) + { + // + // TestOperations implicit context propagation + // + + NSString *impls[] = {@"Shared", @"PerThread"}; + for(int i = 0; i < 2; i++) + { + ICEInitializationData* initData = [ICEInitializationData initializationData]; + [initData setProperties:[[communicator getProperties] clone]]; + [initData.properties setProperty:@"Ice.ImplicitContext" value:impls[i]]; + + id<ICECommunicator> ic = [ICEUtil createCommunicator:initData]; + + ICEMutableContext *ctx = [ICEMutableContext dictionary]; + [ctx setObject:@"ONE" forKey:@"one" ]; + [ctx setObject:@"TWO" forKey:@"two" ]; + [ctx setObject:@"THREE" forKey:@"three"]; + + id<TestOperationsMyClassPrx> p = [TestOperationsMyClassPrx uncheckedCast: + [ic stringToProxy:@"test:default -p 12010"]]; + + [[ic getImplicitContext] setContext:(ctx)]; + test([[[ic getImplicitContext] getContext] isEqualToDictionary:ctx]); + { + id<ICEAsyncResult> r = [p begin_opContext]; + ICEContext* c = [p end_opContext:r]; + test([c isEqualToDictionary:ctx]); + } + + test([[ic getImplicitContext] get:@"zero"] == nil); + [[ic getImplicitContext] put:@"zero" value:@"ZERO"]; + test([[[ic getImplicitContext] get:@"zero"] isEqualToString:@"ZERO"]); + + ctx = [[ic getImplicitContext] getContext]; + { + id<ICEAsyncResult> r = [p begin_opContext]; + ICEContext* c = [p end_opContext:r]; + test([c isEqualToDictionary:ctx]); + } + + ICEMutableContext *prxContext = [ICEMutableContext dictionary]; + [prxContext setObject:@"UN" forKey:@"one"]; + [prxContext setObject:@"QUATRE" forKey:@"four"]; + + ICEMutableContext *combined = [ICEMutableContext dictionaryWithDictionary:ctx]; + [combined addEntriesFromDictionary:prxContext]; + + p = [TestOperationsMyClassPrx uncheckedCast:[p ice_context:prxContext]]; + + [[ic getImplicitContext] setContext:[ICEMutableContext dictionary]]; + { + id<ICEAsyncResult> r = [p begin_opContext]; + ICEContext* c = [p end_opContext:r]; + test([c isEqualToDictionary:prxContext]); + } + + [[ic getImplicitContext] setContext:ctx]; + { + id<ICEAsyncResult> r = [p begin_opContext]; + ICEContext* c = [p end_opContext:r]; + test([c isEqualToDictionary:combined]); + } + + [[ic getImplicitContext] setContext:[ICEContext dictionary]]; + [ic destroy]; + } + } + + + + { + ICEDouble d = 1278312346.0 / 13.0; + TestOperationsMutableDoubleS *ds = [TestOperationsMutableDoubleS dataWithLength:(5 * sizeof(ICEDouble))]; + ICEDouble *pb = (ICEDouble *)[ds bytes]; + int i = 5; + while(i-- > 0) + { + *pb++ = d; + } + TestNewAMIOperationsCallback* cb = [TestNewAMIOperationsCallback create]; + [p begin_opDoubleMarshaling:d p2:ds response:^() { [cb opDoubleMarshalingResponse]; } exception:^(ICEException* ex) { [cb opDoubleMarshalingException:ex]; }]; + test([cb check]); + } + + // Marshaling tests for NSNull are present only in synchronous test because testing asynchronously + // would only test the same marshaling code that's been tested already. +} + diff --git a/objective-c/test/Ice/operations/run.py b/objective-c/test/Ice/operations/run.py new file mode 100755 index 00000000000..0816938a196 --- /dev/null +++ b/objective-c/test/Ice/operations/run.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python +# ********************************************************************** +# +# Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +# +# This copy of Ice is licensed to you under the terms described in the +# ICE_LICENSE file included in this distribution. +# +# ********************************************************************** + +import os, sys + +path = [ ".", "..", "../..", "../../..", "../../../..", "../../../../.." ] +head = os.path.dirname(sys.argv[0]) +if len(head) > 0: + path = [os.path.join(head, p) for p in path] +path = [os.path.abspath(p) for p in path if os.path.exists(os.path.join(p, "scripts", "TestUtil.py")) ] +if len(path) == 0: + raise RuntimeError("can't find toplevel directory!") +sys.path.append(os.path.join(path[0], "scripts")) +import TestUtil + +print("tests with regular server.") +TestUtil.clientServerTest() +print("tests with collocated server.") +TestUtil.collocatedTest() diff --git a/objective-c/test/Ice/optional/.gitignore b/objective-c/test/Ice/optional/.gitignore new file mode 100644 index 00000000000..7096f056538 --- /dev/null +++ b/objective-c/test/Ice/optional/.gitignore @@ -0,0 +1,8 @@ +// Generated by makegitignore.py + +// IMPORTANT: Do not edit this file -- any edits made here will be lost! +client +server +.depend +OptionalTest.m +OptionalTest.h diff --git a/objective-c/test/Ice/optional/AllTests.m b/objective-c/test/Ice/optional/AllTests.m new file mode 100644 index 00000000000..83fd2ca0bc3 --- /dev/null +++ b/objective-c/test/Ice/optional/AllTests.m @@ -0,0 +1,1681 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <TestCommon.h> +#import <OptionalTest.h> + +#import <Foundation/Foundation.h> + +@interface TestObjectReader : ICEObject +{ +} +@end + +@implementation TestObjectReader +-(void) read__:(id<ICEInputStream>)is +{ + [is startObject]; + [is startSlice]; + [is endSlice]; + [is endObject:NO]; +} +@end + +@interface BObjectReader : ICEObject +{ +} +@end + +@implementation BObjectReader +-(void) read__:(id<ICEInputStream>)is +{ + [is startObject]; + // ::Test::B + [is startSlice]; + [is readInt]; + [is endSlice]; + // ::Test::A + [is startSlice]; + [is readInt]; + [is endSlice]; + [is endObject:NO]; +}; +@end + +@interface CObjectReader : ICEObject +{ +} +@end + +@implementation CObjectReader +-(void) read__:(id<ICEInputStream>)is +{ + [is startObject]; + // ::Test::C + [is startSlice]; + [is skipSlice]; + // ::Test::B + [is startSlice]; + [is readInt]; + [is endSlice]; + // ::Test::A + [is startSlice]; + [is readInt]; + [is endSlice]; + [is endObject:NO]; +}; +@end + +@interface DObjectWriter : ICEObject +{ +} +@end + +@implementation DObjectWriter +-(void) write__:(id<ICEOutputStream>)os +{ + [os startObject:0]; + // ::Test::D + [os startSlice:@"::Test::D" compactId:-1 lastSlice:NO]; + [os writeString:@"test"]; + if([os writeOptional:1 format:ICEOptionalFormatVSize]) + { + ICEMutableStringSeq* o = [ICEMutableStringSeq array]; + [o addObject:@"test1"]; + [o addObject:@"test2"]; + [o addObject:@"test3"]; + [o addObject:@"test4"]; + [ICEStringSeqHelper write:o stream:os]; + } + if([os writeOptional:1000 format:ICEOptionalFormatClass]) + { + TestOptionalA* a = [TestOptionalA a]; + a.mc = 18; + [os writeObject:a]; + } + [os endSlice]; + // ::Test::B + [os startSlice:@"::Test::B" compactId:-1 lastSlice:NO]; + [os writeInt:14]; + [os endSlice]; + // ::Test::A + [os startSlice:@"::Test::A" compactId:-1 lastSlice:YES]; + [os writeInt:14]; + [os endSlice]; + [os endObject]; +} +@end + +@interface DObjectReader : ICEObject +{ + TestOptionalA* a_; +} +@end + +@implementation DObjectReader +#if defined(__clang__) && !__has_feature(objc_arc) +-(void) dealloc +{ + [a_ release]; + [super dealloc]; +} +#endif +-(void) read__:(id<ICEInputStream>)is +{ + [is startObject]; + // ::Test::D + [is startSlice]; + NSString* s = [is readString]; + test([s isEqualToString:@"test"]); + test([is readOptional:1 format:ICEOptionalFormatVSize]); + NSMutableArray* o = [ICEStringSeqHelper read:is]; + test(o != nil && [o count] == 4 && + [[o objectAtIndex:0] isEqualToString:@"test1"] && + [[o objectAtIndex:1] isEqualToString:@"test2"] && + [[o objectAtIndex:2] isEqualToString:@"test3"] && + [[o objectAtIndex:3] isEqualToString:@"test4"]); + test([is readOptional:1000 format:ICEOptionalFormatClass]); + [is newObject:(ICEObject**)&a_ expectedType:[TestOptionalA class]]; + [is endSlice]; + + // ::Test::B + [is startSlice]; + [is readInt]; + [is endSlice]; + // ::Test::A + [is startSlice]; + [is readInt]; + [is endSlice]; + [is endObject:NO]; +} +-(void) check +{ + test(a_.mc == 18); +} +@end + +@interface FObjectReader : ICEObject +{ + TestOptionalF* f_; +} +@end + +@implementation FObjectReader +-(id) init +{ + self = [super init]; + if(self) + { + f_ = nil; + } + return self; +} + +-(void) read__:(id<ICEInputStream>)is +{ + if(f_ != nil) + { + ICE_RELEASE(f_); + } + f_ = [TestOptionalF new]; + [is startObject]; + [is startSlice]; + // Don't read optional af on purpose + //[is_ readObject:(ICEObject**)&self->af expectedType:[TestOptionalA class]]; + [is endSlice]; + [is startSlice]; + TestOptionalA* ICE_AUTORELEASING_QUALIFIER ae; + [is readObject:(ICEObject**)&ae expectedType:[TestOptionalA class]]; + [is endSlice]; + [is endObject:NO]; + f_.ae = ae; +} + +#if defined(__clang__) && !__has_feature(objc_arc) +-(void) dealloc +{ + [f_ release]; + [super dealloc]; +} +#endif + +-(TestOptionalF*) getF +{ + return f_; +} +@end + +@interface FactoryI : NSObject<ICEObjectFactory> +{ + BOOL enabled_; +} ++(FactoryI*) factoryI; +-(void) setEnabled:(BOOL)enabled; +@end + +@implementation FactoryI ++(FactoryI*) factoryI +{ + return ICE_AUTORELEASE([[FactoryI alloc] init]); +} +-(id) init +{ + self = [super init]; + if(self) + { + self->enabled_ = NO; + } + return self; +} +-(ICEObject*) create:(NSString*)typeId +{ + if(!enabled_) + { + return nil; + } + if([typeId isEqualToString:@"::Test::OneOptional"]) + { + return [TestObjectReader new]; + } + else if([typeId isEqualToString:@"::Test::MultiOptional"]) + { + return [TestObjectReader new]; + } + else if([typeId isEqualToString:@"::Test::B"]) + { + return [BObjectReader new]; + } + else if([typeId isEqualToString:@"::Test::C"]) + { + return [CObjectReader new]; + } + else if([typeId isEqualToString:@"::Test::D"]) + { + return [DObjectReader new]; + } + else if([typeId isEqualToString:@"::Test::F"]) + { + return [FObjectReader new]; + } + + return nil; +} +-(void) destroy +{ +} +-(void) setEnabled:(BOOL)enabled +{ + self->enabled_ = enabled; +} +@end + +id<TestOptionalInitialPrx> +optionalAllTests(id<ICECommunicator> communicator) +{ + FactoryI* factory = [FactoryI factoryI]; + [communicator addObjectFactory:factory sliceId:@""]; + + tprintf("testing stringToProxy... "); + NSString* sref = @"initial:default -p 12010"; + id<ICEObjectPrx> base = [communicator stringToProxy:sref]; + test(base); + tprintf("ok\n"); + + tprintf("testing checked cast... "); + id<TestOptionalInitialPrx> initial = [TestOptionalInitialPrx checkedCast:base]; + test(initial != nil); + test([initial isEqual:base]); + tprintf("ok\n"); + + tprintf("testing constructor, copy constructor, and assignment operator... "); + + TestOptionalOneOptional* oo1 = [TestOptionalOneOptional oneOptional]; + test(![oo1 hasA]); + oo1.a = 15; + test([oo1 hasA] && oo1.a == 15); + + TestOptionalOneOptional* oo2 = [TestOptionalOneOptional oneOptional:@16]; + test([oo2 hasA] && oo2.a == 16); + + TestOptionalOneOptional* oon = [TestOptionalOneOptional oneOptional:ICENone]; + test(![oon hasA]); + + TestOptionalMultiOptional* mo1 = [TestOptionalMultiOptional multiOptional]; + mo1.a = 15; + mo1.b = true; + mo1.c = 19; + mo1.d = 78; + mo1.e = 99; + mo1.f = 5.5f; + mo1.g = 1.0; + mo1.h = @"test"; + mo1.i = TestOptionalMyEnumMember; + mo1.j = [TestOptionalMultiOptionalPrx uncheckedCast:[communicator stringToProxy:@"test"]]; + //mo1.k = mo1; + ICEByte bsa[] = { 0x05 }; + mo1.bs = [TestOptionalByteSeq dataWithBytes:bsa length:1]; + mo1.ss = [TestOptionalStringSeq arrayWithObjects:@"test", @"test2", nil]; + mo1.iid = [TestOptionalIntIntDict dictionaryWithObjectsAndKeys:@3, @4, nil]; + mo1.sid = [TestOptionalStringIntDict dictionaryWithObjectsAndKeys:@10, @"test", nil]; + TestOptionalFixedStruct* fs = [TestOptionalFixedStruct fixedStruct]; + fs.m = 78; + mo1.fs = fs; + TestOptionalVarStruct* vs = [TestOptionalVarStruct varStruct]; + vs.m = @"hello"; + mo1.vs = vs; + + ICEShort shs[] = { 1 }; + mo1.shs = [TestOptionalShortSeq dataWithBytes:shs length:sizeof(shs)]; + + TestOptionalMyEnum es[] = { TestOptionalMyEnumMember, TestOptionalMyEnumMember }; + mo1.es = [TestOptionalMyEnumSeq dataWithBytes:es length:sizeof(es)]; + mo1.fss = [TestOptionalFixedStructSeq arrayWithObject:fs]; + mo1.vss = [TestOptionalVarStructSeq arrayWithObject:vs]; + mo1.oos = [TestOptionalOneOptionalSeq arrayWithObject:oo1]; + id<TestOptionalOneOptionalPrx> oneOptionalProxy = + [TestOptionalOneOptionalPrx uncheckedCast:[communicator stringToProxy:@"test"]]; + mo1.oops = [TestOptionalOneOptionalPrxSeq arrayWithObject:oneOptionalProxy]; + mo1.ied = [TestOptionalIntEnumDict dictionaryWithObjectsAndKeys:@(TestOptionalMyEnumMember), @4, nil]; + mo1.ifsd = [TestOptionalIntFixedStructDict dictionaryWithObjectsAndKeys:fs, @4, nil]; + mo1.ivsd = [TestOptionalIntVarStructDict dictionaryWithObjectsAndKeys:vs, @4, nil]; + mo1.iood = [TestOptionalIntOneOptionalDict dictionaryWithObjectsAndKeys:[TestOptionalOneOptional oneOptional:@15], + @5, nil]; + mo1.ioopd = [TestOptionalIntOneOptionalPrxDict dictionaryWithObjectsAndKeys:oneOptionalProxy, @5, nil]; + BOOL bos[] = { NO, YES, NO }; + mo1.bos = [TestOptionalBoolSeq dataWithBytes:bos length:sizeof(bos)]; + + TestOptionalMultiOptional* mo3 = ICE_AUTORELEASE([mo1 copy]); + test(mo3.a == 15); + test(mo3.b == YES); + test(mo3.c == 19); + test(mo3.d == 78); + test(mo3.e == 99); + test(mo3.f == 5.5f); + test(mo3.g == 1.0); + test([mo3.h isEqualToString:@"test"]); + test(mo3.i == TestOptionalMyEnumMember); + test([mo3.j isEqual:[TestOptionalMultiOptionalPrx uncheckedCast:[communicator stringToProxy:@"test"]]]); + //test(mo3.k == mo1); + test(mo3.bs == mo1.bs); + test(mo3.ss == mo1.ss); + test(mo3.iid == mo1.iid); + test(mo3.sid == mo1.sid); + test(mo3.fs == mo1.fs); + test(mo3.vs == mo1.vs); + + test(mo3.shs == mo1.shs); + test(mo3.es == mo1.es); + test(mo3.fss == mo1.fss); + test(mo3.vss == mo1.vss); + test(mo3.oos == mo1.oos); + test(mo3.oops == mo1.oops); + + test(mo3.ied == mo1.ied); + test(mo3.ifsd == mo1.ifsd); + test(mo3.ivsd == mo1.ivsd); + test(mo3.iood == mo1.iood); + test(mo3.ioopd == mo1.ioopd); + + test(mo3.bos == mo1.bos); + + tprintf("ok\n"); + +// tprintf("testing comparison operators... "); + +// test(mo1->a == 15 && 15 == mo1->a && mo1->a != 16 && 16 != mo1->a); +// test(mo1->a < 16 && mo1->a > 14 && mo1->a <= 15 && mo1->a >= 15 && mo1->a <= 16 && mo1->a >= 14); +// test(mo1->a > IceUtil::Optional<int>() && IceUtil::Optional<int>() < mo1->a); +// test(14 > IceUtil::Optional<int>() && IceUtil::Optional<int>() < 14); + +// test(mo1->h == "test" && "test" == mo1->h && mo1->h != "testa" && "testa" != mo1->h); +// test(mo1->h < "test1" && mo1->h > "tesa" && mo1->h <= "test"); +// test(mo1->h >= "test" && mo1->h <= "test1" && mo1->h >= "tesa"); +// test(mo1->h > IceUtil::Optional<string>() && IceUtil::Optional<string>() < mo1->h); +// test("test1" > IceUtil::Optional<string>() && IceUtil::Optional<string>() < "test1"); + +// tprintf("ok\n"); + + tprintf("testing marshalling... "); + TestOptionalOneOptional* oo4 = (TestOptionalOneOptional*)[initial pingPong:[TestOptionalOneOptional oneOptional]]; + test(![oo4 hasA]); + + TestOptionalOneOptional* oo5 = (TestOptionalOneOptional*)[initial pingPong:oo1]; + test(oo1.a == oo5.a); + + TestOptionalMultiOptional* mo4 = (TestOptionalMultiOptional*) + [initial pingPong:[TestOptionalMultiOptional multiOptional]]; + test(![mo4 hasA]); + test(![mo4 hasB]); + test(![mo4 hasC]); + test(![mo4 hasD]); + test(![mo4 hasE]); + test(![mo4 hasF]); + test(![mo4 hasG]); + test(![mo4 hasH]); + test(![mo4 hasI]); + test(![mo4 hasJ]); + test(![mo4 hasK]); + test(![mo4 hasBs]); + test(![mo4 hasSs]); + test(![mo4 hasIid]); + test(![mo4 hasSid]); + test(![mo4 hasFs]); + test(![mo4 hasVs]); + + test(![mo4 hasShs]); + test(![mo4 hasEs]); + test(![mo4 hasFss]); + test(![mo4 hasVss]); + test(![mo4 hasOos]); + test(![mo4 hasOops]); + + test(![mo4 hasIed]); + test(![mo4 hasIfsd]); + test(![mo4 hasIvsd]); + test(![mo4 hasIood]); + test(![mo4 hasIoopd]); + + test(![mo4 hasBos]); + + //mo1.k = mo1; + TestOptionalMultiOptional* mo5 = (TestOptionalMultiOptional*)[initial pingPong:mo1]; + test(mo5.a == mo1.a); + test(mo5.b == mo1.b); + test(mo5.c == mo1.c); + test(mo5.d == mo1.d); + test(mo5.e == mo1.e); + test(mo5.f == mo1.f); + test(mo5.g == mo1.g); + test([mo5.h isEqualToString:mo1.h]); + test(mo5.i == mo1.i); + test([mo5.j isEqual:mo1.j]); + //test(mo5.k == mo5); + test([mo5.bs isEqual:mo1.bs]); + test([mo5.ss isEqual:mo1.ss]); + test([mo5.iid isEqual: mo1.iid]); + test([mo5.sid isEqual:mo1.sid]); + test([mo5.fs isEqual:mo1.fs]); + test([mo5.vs isEqual:mo1.vs]); + + test([mo5.shs isEqual:mo1.shs]); + test([mo5.es isEqual:mo1.es]); + test([mo5.fss isEqual:mo1.fss]); + test([mo5.vss isEqual:mo1.vss]); + test([mo5.oos count] > 0 && ((TestOptionalOneOptional*)[mo5.oos objectAtIndex:0]).a == oo1.a); + test([mo5.oops isEqual:mo1.oops]); + + test([mo5.ied isEqual:mo1.ied]); + test([mo5.ifsd isEqual:mo1.ifsd]); + test([mo5.ivsd isEqual:mo1.ivsd]); + test([mo5.iood count] > 0 && ((TestOptionalOneOptional*)[mo5.iood objectForKey:@5]).a == 15); + test([mo5.ioopd isEqual:mo1.ioopd]); + + test([mo5.bos isEqual:mo1.bos]); + + // Clear the first half of the optional parameters + TestOptionalMultiOptional* mo6 = ICE_AUTORELEASE([mo5 copy]); + [mo6 clearA]; + [mo6 clearC]; + [mo6 clearE]; + [mo6 clearG]; + [mo6 clearI]; + [mo6 clearK]; + [mo6 clearSs]; + [mo6 clearSid]; + [mo6 clearVs]; + + [mo6 clearEs]; + [mo6 clearVss]; + [mo6 clearOops]; + + [mo6 clearIed]; + [mo6 clearIvsd]; + [mo6 clearIoopd]; + + TestOptionalMultiOptional* mo7 = (TestOptionalMultiOptional*)[initial pingPong:mo6]; + test(![mo7 hasA]); + test(mo7.b == mo1.b); + test(![mo7 hasC]); + test(mo7.d == mo1.d); + test(![mo7 hasE]); + test(mo7.f == mo1.f); + test(![mo7 hasG]); + test([mo7.h isEqual:mo1.h]); + test(![mo7 hasI]); + test([mo7.j isEqual:mo1.j]); + test(![mo7 hasK]); + test([mo7.bs isEqual:mo1.bs]); + test(![mo7 hasSs]); + test([mo7.iid isEqual:mo1.iid]); + test(![mo7 hasSid]); + test([mo7.fs isEqual:mo1.fs]); + test(![mo7 hasVs]); + + test([mo7.shs isEqual:mo1.shs]); + test(![mo7 hasEs]); + test([mo7.fss isEqual:mo1.fss]); + test(![mo7 hasVss]); + test([mo7.oos count] > 0 && ((TestOptionalOneOptional*)[mo7.oos objectAtIndex:0]).a == oo1.a); + test(![mo7 hasOops]); + + test(![mo7 hasIed]); + test([mo7.ifsd isEqual:mo1.ifsd]); + test(![mo7 hasIvsd]); + test([mo7.iood count] > 0 && ((TestOptionalOneOptional*)[mo7.iood objectForKey:@5]).a == 15); + test(![mo7 hasIoopd]); + + // Clear the second half of the optional parameters + TestOptionalMultiOptional* mo8 = ICE_AUTORELEASE([mo5 copy]); + [mo8 clearB]; + [mo8 clearD]; + [mo8 clearF]; + [mo8 clearH]; + [mo8 clearJ]; + [mo8 clearBs]; + [mo8 clearIid]; + [mo8 clearFs]; + + [mo8 clearShs]; + [mo8 clearFss]; + [mo8 clearOos]; + + [mo8 clearIfsd]; + [mo8 clearIood]; + + TestOptionalMultiOptional* mo9 = (TestOptionalMultiOptional*)[initial pingPong:mo8]; + test(mo9.a == mo1.a); + test(![mo9 hasB]); + test(mo9.c == mo1.c); + test(![mo9 hasD]); + test(mo9.e == mo1.e); + test(![mo9 hasF]); + test(mo9.g == mo1.g); + test(![mo9 hasH]); + test(mo9.i == mo1.i); + test(![mo9 hasJ]); + //test(mo9.k == mo9.k); + test(![mo9 hasBs]); + test([mo9.ss isEqual:mo1.ss]); + test(![mo9 hasIid]); + test([mo9.sid isEqual:mo1.sid]); + test(![mo9 hasFs]); + test([mo9.vs isEqual:mo1.vs]); + + test(![mo8 hasShs]); + test([mo8.es isEqual:mo1.es]); + test(![mo8 hasFss]); + test([mo8.vss isEqual:mo1.vss]); + test(![mo8 hasOos]); + test([mo8.oops isEqual:mo1.oops]); + + test([mo8.ied isEqual:mo1.ied]); + test(![mo8 hasIfsd]); + test([mo8.ivsd isEqual:mo1.ivsd]); + test(![mo8 hasIood]); + + // + // Send a request using blobjects. Upon receival, we don't read + // any of the optional members. This ensures the optional members + // are skipped even if the receiver knows nothing about them. + // + [factory setEnabled:YES]; + id<ICEOutputStream> os = [ICEUtil createOutputStream:communicator]; + [os startEncapsulation]; + [os writeObject:oo1]; + [os endEncapsulation]; + ICEByteSeq* inEncaps = [os finished]; + ICEMutableByteSeq* outEncaps; + test([initial ice_invoke:@"pingPong" mode:ICENormal inEncaps:inEncaps outEncaps:&outEncaps]); + id<ICEInputStream> is = [ICEUtil createInputStream:communicator data:outEncaps]; + [is startEncapsulation]; + ICEObject* obj; + [is readObject:&obj]; + [is endEncapsulation]; + test(obj != nil && [obj isKindOfClass:[TestObjectReader class]]); + + os = [ICEUtil createOutputStream:communicator]; + [os startEncapsulation]; + [os writeObject:mo1]; + [os endEncapsulation]; + inEncaps = [os finished]; + test([initial ice_invoke:@"pingPong" mode:ICENormal inEncaps:inEncaps outEncaps:&outEncaps]); + is = [ICEUtil createInputStream:communicator data:outEncaps]; + [is startEncapsulation]; + [is readObject:&obj]; + [is endEncapsulation]; + test(obj != nil && [obj isKindOfClass:[TestObjectReader class]]); + [factory setEnabled:false]; + + // + // Use the 1.0 encoding with operations whose only class parameters are optional. + // + id oo = [TestOptionalOneOptional oneOptional:@53]; + [initial sendOptionalClass:YES o:oo]; + [[initial ice_encodingVersion:ICEEncoding_1_0] sendOptionalClass:YES o:oo]; + + [initial returnOptionalClass:YES o:&oo]; + test(oo != nil && oo != ICENone); + [[initial ice_encodingVersion:ICEEncoding_1_0] returnOptionalClass:YES o:&oo]; + test(oo == ICENone); + + tprintf("ok\n"); + + tprintf("testing marshalling of large containers with fixed size elements..."); + TestOptionalMultiOptional* mc = [TestOptionalMultiOptional multiOptional]; + + mc.bs = [TestOptionalMutableByteSeq dataWithLength:1000]; + mc.shs = [TestOptionalMutableShortSeq dataWithLength:300 * sizeof(ICEShort)]; + mc.fss = [TestOptionalMutableFixedStructSeq array]; + for(int i = 0; i < 300; ++i) + { + [(TestOptionalMutableFixedStructSeq*)mc.fss addObject:[TestOptionalFixedStruct fixedStruct]]; + } + + mc.ifsd = [TestOptionalMutableIntFixedStructDict dictionary]; + for(int i = 0; i < 300; ++i) + { + [(TestOptionalMutableIntFixedStructDict*)mc.ifsd setObject:[TestOptionalFixedStruct fixedStruct] forKey:@(i)]; + } + + mc = (TestOptionalMultiOptional*)[initial pingPong:mc]; + test([mc.bs length] == 1000); + test([mc.shs length] == 300 * sizeof(ICEShort)); + test([mc.fss count] == 300); + test([mc.ifsd count] == 300); + + [factory setEnabled:YES]; + os = [ICEUtil createOutputStream:communicator]; + [os startEncapsulation]; + [os writeObject:mc]; + [os endEncapsulation]; + inEncaps = [os finished]; + + test([initial ice_invoke:@"pingPong" mode:ICENormal inEncaps:inEncaps outEncaps:&outEncaps]); + is = [ICEUtil createInputStream:communicator data:outEncaps]; + [is startEncapsulation]; + [is readObject:&obj]; + [is endEncapsulation]; + test(obj != nil && [obj isKindOfClass:[TestObjectReader class]]); + [factory setEnabled:NO]; + + tprintf("ok\n"); + + tprintf("testing tag marshalling... "); + TestOptionalB* b = [TestOptionalB b]; + TestOptionalB* b2 = (TestOptionalB*)[initial pingPong:b]; + test(![b2 hasMa]); + test(![b2 hasMb]); + test(![b2 hasMc]); + + b.ma = 10; + b.mb = 11; + b.mc = 12; + b.md = 13; + + b2 = (TestOptionalB*)[initial pingPong:b]; + test(b2.ma == 10); + test(b2.mb == 11); + test(b2.mc == 12); + test(b2.md == 13); + + [factory setEnabled:YES]; + os = [ICEUtil createOutputStream:communicator]; + [os startEncapsulation]; + [os writeObject:b]; + [os endEncapsulation]; + inEncaps = [os finished]; + test([initial ice_invoke:@"pingPong" mode:ICENormal inEncaps:inEncaps outEncaps:&outEncaps]); + is = [ICEUtil createInputStream:communicator data:outEncaps]; + [is startEncapsulation]; + [is readObject:&obj]; + [is endEncapsulation]; + test(obj != nil); + [factory setEnabled:NO]; + + tprintf("ok\n"); + + tprintf("testing marshalling of objects with optional objects..."); + { + TestOptionalF* f = [TestOptionalF f]; + + f.af = [TestOptionalA a]; + f.ae = f.af; + + TestOptionalF* rf = (TestOptionalF*)[initial pingPong:f]; + test(rf.ae == rf.af); + + [factory setEnabled:YES]; + os = [ICEUtil createOutputStream:communicator]; + [os startEncapsulation]; + [os writeObject:f]; + [os endEncapsulation]; + inEncaps = [os finished]; + is = [ICEUtil createInputStream:communicator data:inEncaps]; + [is startEncapsulation]; + [is readObject:&obj]; + [is endEncapsulation]; + [factory setEnabled:NO]; + + test(obj != nil && [obj isKindOfClass:[FObjectReader class]]); + rf = [(FObjectReader*)obj getF]; + test(rf.ae != nil && ![rf hasAf]); + } + tprintf("ok\n"); + + tprintf("testing optional with default values... "); + TestOptionalWD* wd = (TestOptionalWD*)[initial pingPong:[TestOptionalWD wd]]; + test(wd.a == 5); + test([wd.s isEqualToString:@"test"]); + [wd clearA]; + [wd clearS]; + wd = (TestOptionalWD*)[initial pingPong:wd]; + test(![wd hasA]); + test(![wd hasS]); + tprintf("ok\n"); + + if([[communicator getProperties] getPropertyAsInt:@"Ice.Default.SlicedFormat"] > 0) + { + tprintf("testing marshalling with unknown class slices... "); + { + TestOptionalC* c = [TestOptionalC c]; + c.ss = @"test"; + c.ms = @"testms"; + os = [ICEUtil createOutputStream:communicator]; + [os startEncapsulation]; + [os writeObject:c]; + [os endEncapsulation]; + inEncaps = [os finished]; + [factory setEnabled:YES]; + test([initial ice_invoke:@"pingPong" mode:ICENormal inEncaps:inEncaps outEncaps:&outEncaps]); + is = [ICEUtil createInputStream:communicator data:outEncaps]; + [is startEncapsulation]; + [is readObject:&obj]; + [is endEncapsulation]; + test(obj != nil && [obj isKindOfClass:[CObjectReader class]]); + [factory setEnabled:NO]; + + [factory setEnabled:YES]; + os = [ICEUtil createOutputStream:communicator]; + [os startEncapsulation]; + ICEObject* d = [DObjectWriter new]; + [os writeObject:d]; + ICE_RELEASE(d); + [os endEncapsulation]; + inEncaps = [os finished]; + test([initial ice_invoke:@"pingPong" mode:ICENormal inEncaps:inEncaps outEncaps:&outEncaps]); + is = [ICEUtil createInputStream:communicator data:outEncaps]; + [is startEncapsulation]; + [is readObject:&obj]; + [is endEncapsulation]; + test(obj != nil && [obj isKindOfClass:[DObjectReader class]]); + [(DObjectReader*)obj check]; + [factory setEnabled:NO]; + } + tprintf("ok\n"); + + tprintf("testing optionals with unknown classes..."); + { + TestOptionalA* a = [TestOptionalA a]; + + os = [ICEUtil createOutputStream:communicator]; + [os startEncapsulation]; + [os writeObject:a]; + DObjectWriter* writer = [DObjectWriter new]; + [ICEObjectHelper writeOpt:writer stream:os tag:1]; + ICE_RELEASE(writer); + [os endEncapsulation]; + inEncaps = [os finished]; + test([initial ice_invoke:@"opClassAndUnknownOptional" mode:ICENormal inEncaps:inEncaps + outEncaps:&outEncaps]); + is = [ICEUtil createInputStream:communicator data:outEncaps]; + [is startEncapsulation]; + [is endEncapsulation]; + } + tprintf("ok\n"); + } + + tprintf("testing optional parameters... "); + { + id p1 = ICENone; + id p3 = ICENone; + id p2 = [initial opByte:p1 p3:&p3]; + test(p2 == ICENone && p3 == ICENone); + + p1 = @0x56; + p2 = [initial opByte:p1 p3:&p3]; + test([p2 isEqual:@0x56] && [p3 isEqual:@0x56]); + + os = [ICEUtil createOutputStream:communicator]; + [os startEncapsulation]; + [ICEByteHelper writeOpt:p1 stream:os tag:2]; + [os endEncapsulation]; + inEncaps = [os finished]; + [initial ice_invoke:@"opByte" mode:ICENormal inEncaps:inEncaps outEncaps:&outEncaps]; + is = [ICEUtil createInputStream:communicator data:outEncaps]; + [is startEncapsulation]; + p2 = [ICEByteHelper readOpt:is tag:1]; + p3 = [ICEByteHelper readOpt:is tag:3]; + + id p4 = @0x08; + p4 = [ICEByteHelper readOpt:is tag:89]; + + [is endEncapsulation]; + test([p2 isEqual:@0x56] && [p3 isEqual:@0x56] && [p4 isEqual:ICENone]); + + is = [ICEUtil createInputStream:communicator data:outEncaps]; + [is startEncapsulation]; + [is endEncapsulation]; + } + + { + id p1 = ICENone; + id p3 = ICENone; + id p2 = [initial opBool:p1 p3:&p3]; + test(p2 == ICENone && p3 == ICENone); + + p1 = @YES; + p2 = [initial opBool:p1 p3:&p3]; + test([p2 isEqual:@YES] && [p3 isEqual:@YES]); + + os = [ICEUtil createOutputStream:communicator]; + [os startEncapsulation]; + [ICEBoolHelper writeOpt:p1 stream:os tag:2]; + [os endEncapsulation]; + inEncaps = [os finished]; + [initial ice_invoke:@"opBool" mode:ICENormal inEncaps:inEncaps outEncaps:&outEncaps]; + is = [ICEUtil createInputStream:communicator data:outEncaps]; + [is startEncapsulation]; + p2 = [ICEBoolHelper readOpt:is tag:1]; + p3 = [ICEBoolHelper readOpt:is tag:3]; + [is endEncapsulation]; + test([p2 isEqual:@YES] && [p3 isEqual:@YES]); + + is = [ICEUtil createInputStream:communicator data:outEncaps]; + [is startEncapsulation]; + [is endEncapsulation]; + } + + { + id p1 = ICENone; + id p3 = ICENone; + id p2 = [initial opShort:p1 p3:&p3]; + test(p2 == ICENone && p3 == ICENone); + + p1 = @56; + p2 = [initial opShort:p1 p3:&p3]; + test([p2 isEqual:@56] && [p3 isEqual:@56]); + + os = [ICEUtil createOutputStream:communicator]; + [os startEncapsulation]; + [ICEShortHelper writeOpt:p1 stream:os tag:2]; + [os endEncapsulation]; + inEncaps = [os finished]; + [initial ice_invoke:@"opShort" mode:ICENormal inEncaps:inEncaps outEncaps:&outEncaps]; + is = [ICEUtil createInputStream:communicator data:outEncaps]; + [is startEncapsulation]; + p2 = [ICEShortHelper readOpt:is tag:1]; + p3 = [ICEShortHelper readOpt:is tag:3]; + [is endEncapsulation]; + test([p2 isEqual:@56] && [p3 isEqual:@56]); + + is = [ICEUtil createInputStream:communicator data:outEncaps]; + [is startEncapsulation]; + [is endEncapsulation]; + } + + { + id p1 = ICENone; + id p3 = ICENone; + id p2 = [initial opInt:p1 p3:&p3]; + test(p2 == ICENone && p3 == ICENone); + + p1 = @56; + p2 = [initial opInt:p1 p3:&p3]; + test([p2 isEqual:@56] && [p3 isEqual:@56]); + + os = [ICEUtil createOutputStream:communicator]; + [os startEncapsulation]; + [ICEIntHelper writeOpt:p1 stream:os tag:2]; + [os endEncapsulation]; + inEncaps = [os finished]; + [initial ice_invoke:@"opInt" mode:ICENormal inEncaps:inEncaps outEncaps:&outEncaps]; + is = [ICEUtil createInputStream:communicator data:outEncaps]; + [is startEncapsulation]; + p2 = [ICEIntHelper readOpt:is tag:1]; + p3 = [ICEIntHelper readOpt:is tag:3]; + [is endEncapsulation]; + test([p2 isEqual:@56] && [p3 isEqual:@56]); + + is = [ICEUtil createInputStream:communicator data:outEncaps]; + [is startEncapsulation]; + [is endEncapsulation]; + } + + { + id p1 = ICENone; + id p3 = ICENone; + id p2 = [initial opLong:p1 p3:&p3]; + test(p2 == ICENone && p3 == ICENone); + + p1 = @56; + p2 = [initial opLong:p1 p3:&p3]; + test([p2 isEqual:@56] && [p3 isEqual:@56]); + + os = [ICEUtil createOutputStream:communicator]; + [os startEncapsulation]; + [ICELongHelper writeOpt:p1 stream:os tag:1]; + [os endEncapsulation]; + inEncaps = [os finished]; + [initial ice_invoke:@"opLong" mode:ICENormal inEncaps:inEncaps outEncaps:&outEncaps]; + is = [ICEUtil createInputStream:communicator data:outEncaps]; + [is startEncapsulation]; + p3 = [ICELongHelper readOpt:is tag:2]; + p2 = [ICELongHelper readOpt:is tag:3]; + [is endEncapsulation]; + test([p2 isEqual:@56] && [p3 isEqual:@56]); + + is = [ICEUtil createInputStream:communicator data:outEncaps]; + [is startEncapsulation]; + [is endEncapsulation]; + } + + { + id p1 = ICENone; + id p3 = ICENone; + id p2 = [initial opFloat:p1 p3:&p3]; + test(p2 == ICENone && p3 == ICENone); + + p1 = @1.0f; + p2 = [initial opFloat:p1 p3:&p3]; + test([p2 isEqual:@1.0f] && [p3 isEqual:@1.0f]); + + os = [ICEUtil createOutputStream:communicator]; + [os startEncapsulation]; + [ICEFloatHelper writeOpt:p1 stream:os tag:2]; + [os endEncapsulation]; + inEncaps = [os finished]; + [initial ice_invoke:@"opFloat" mode:ICENormal inEncaps:inEncaps outEncaps:&outEncaps]; + is = [ICEUtil createInputStream:communicator data:outEncaps]; + [is startEncapsulation]; + p3 = [ICEFloatHelper readOpt:is tag:1]; + p2 = [ICEFloatHelper readOpt:is tag:3]; + [is endEncapsulation]; + test([p2 isEqual:@1.0f] && [p3 isEqual:@1.0f]); + + is = [ICEUtil createInputStream:communicator data:outEncaps]; + [is startEncapsulation]; + [is endEncapsulation]; + } + + { + id p1 = ICENone; + id p3 = ICENone; + id p2 = [initial opDouble:p1 p3:&p3]; + test(p2 == ICENone && p3 == ICENone); + + p1 = @1.0; + p2 = [initial opDouble:p1 p3:&p3]; + test([p2 isEqual:@1.0] && [p3 isEqual:@1.0]); + + os = [ICEUtil createOutputStream:communicator]; + [os startEncapsulation]; + [ICEDoubleHelper writeOpt:p1 stream:os tag:2]; + [os endEncapsulation]; + inEncaps = [os finished]; + [initial ice_invoke:@"opDouble" mode:ICENormal inEncaps:inEncaps outEncaps:&outEncaps]; + is = [ICEUtil createInputStream:communicator data:outEncaps]; + [is startEncapsulation]; + p3 = [ICEDoubleHelper readOpt:is tag:1]; + p2 = [ICEDoubleHelper readOpt:is tag:3]; + [is endEncapsulation]; + test([p2 isEqual:@1.0] && [p3 isEqual:@1.0]); + + is = [ICEUtil createInputStream:communicator data:outEncaps]; + [is startEncapsulation]; + [is endEncapsulation]; + } + + { + id p1 = ICENone; + id p3 = ICENone; + id p2 = [initial opString:p1 p3:&p3]; + test(p2 == ICENone && p3 == ICENone); + + p1 = @"test"; + p2 = [initial opString:p1 p3:&p3]; + test([p2 isEqualToString:@"test"] && [p3 isEqualToString:@"test"]); + + os = [ICEUtil createOutputStream:communicator]; + [os startEncapsulation]; + [ICEStringHelper writeOpt:p1 stream:os tag:2]; + [os endEncapsulation]; + inEncaps = [os finished]; + [initial ice_invoke:@"opString" mode:ICENormal inEncaps:inEncaps outEncaps:&outEncaps]; + is = [ICEUtil createInputStream:communicator data:outEncaps]; + [is startEncapsulation]; + p2 = [ICEStringHelper readOpt:is tag:1]; + p3 = [ICEStringHelper readOpt:is tag:3]; + [is endEncapsulation]; + test([p2 isEqualToString:@"test"] && [p3 isEqualToString:@"test"]); + + is = [ICEUtil createInputStream:communicator data:outEncaps]; + [is startEncapsulation]; + [is endEncapsulation]; + } + + { + id p1 = ICENone; + id p3 = ICENone; + id p2 = [initial opMyEnum:p1 p3:&p3]; + test(p2 == ICENone && p3 == ICENone); + + p1 = @(TestOptionalMyEnumMember); + p2 = [initial opMyEnum:p1 p3:&p3]; + test([p2 isEqual:@(TestOptionalMyEnumMember)] && [p3 isEqual:@(TestOptionalMyEnumMember)]); + + os = [ICEUtil createOutputStream:communicator]; + [os startEncapsulation]; + [TestOptionalMyEnumHelper writeOpt:p1 stream:os tag:2]; + [os endEncapsulation]; + inEncaps = [os finished]; + [initial ice_invoke:@"opMyEnum" mode:ICENormal inEncaps:inEncaps outEncaps:&outEncaps]; + is = [ICEUtil createInputStream:communicator data:outEncaps]; + [is startEncapsulation]; + p2 = [TestOptionalMyEnumHelper readOpt:is tag:1]; + p3 = [TestOptionalMyEnumHelper readOpt:is tag:3]; + [is endEncapsulation]; + test([p2 isEqual:@(TestOptionalMyEnumMember)] && [p3 isEqual:@(TestOptionalMyEnumMember)]); + + is = [ICEUtil createInputStream:communicator data:outEncaps]; + [is startEncapsulation]; + [is endEncapsulation]; + } + + { + id p1 = ICENone; + id p3 = ICENone; + id p2 = [initial opSmallStruct:p1 p3:&p3]; + test(p2 == ICENone && p3 == ICENone); + + p1 = [TestOptionalSmallStruct smallStruct:56]; + p2 = [initial opSmallStruct:p1 p3:&p3]; + test(((TestOptionalSmallStruct*)p2).m == 56 && ((TestOptionalSmallStruct*)p3).m== 56); + + os = [ICEUtil createOutputStream:communicator]; + [os startEncapsulation]; + [TestOptionalSmallStructHelper writeOpt:p1 stream:os tag:2]; + [os endEncapsulation]; + inEncaps = [os finished]; + [initial ice_invoke:@"opSmallStruct" mode:ICENormal inEncaps:inEncaps outEncaps:&outEncaps]; + is = [ICEUtil createInputStream:communicator data:outEncaps]; + [is startEncapsulation]; + p2 = [TestOptionalSmallStructHelper readOpt:is tag:1]; + p3 = [TestOptionalSmallStructHelper readOpt:is tag:3]; + [is endEncapsulation]; + test(((TestOptionalSmallStruct*)p2).m == 56 && ((TestOptionalSmallStruct*)p3).m== 56); + + is = [ICEUtil createInputStream:communicator data:outEncaps]; + [is startEncapsulation]; + [is endEncapsulation]; + } + + { + id p1 = ICENone; + id p3 = ICENone; + id p2 = [initial opFixedStruct:p1 p3:&p3]; + test(p2 == ICENone && p3 == ICENone); + + p1 = [TestOptionalFixedStruct fixedStruct:56]; + p2 = [initial opFixedStruct:p1 p3:&p3]; + test(((TestOptionalFixedStruct*)p2).m == 56 && ((TestOptionalFixedStruct*)p3).m== 56); + + os = [ICEUtil createOutputStream:communicator]; + [os startEncapsulation]; + [TestOptionalFixedStructHelper writeOpt:p1 stream:os tag:2]; + [os endEncapsulation]; + inEncaps = [os finished]; + [initial ice_invoke:@"opFixedStruct" mode:ICENormal inEncaps:inEncaps outEncaps:&outEncaps]; + is = [ICEUtil createInputStream:communicator data:outEncaps]; + [is startEncapsulation]; + p2 = [TestOptionalFixedStructHelper readOpt:is tag:1]; + p3 = [TestOptionalFixedStructHelper readOpt:is tag:3]; + [is endEncapsulation]; + test(((TestOptionalFixedStruct*)p2).m == 56 && ((TestOptionalFixedStruct*)p3).m== 56); + + is = [ICEUtil createInputStream:communicator data:outEncaps]; + [is startEncapsulation]; + [is endEncapsulation]; + } + + { + id p1 = ICENone; + id p3 = ICENone; + id p2 = [initial opVarStruct:p1 p3:&p3]; + test(p2 == ICENone && p3 == ICENone); + + p1 = [TestOptionalVarStruct varStruct:@"test"]; + p2 = [initial opVarStruct:p1 p3:&p3]; + test([((TestOptionalVarStruct*)p2).m isEqual:@"test"] && [((TestOptionalVarStruct*)p3).m isEqual:@"test"]); + + os = [ICEUtil createOutputStream:communicator]; + [os startEncapsulation]; + [TestOptionalVarStructHelper writeOpt:p1 stream:os tag:2]; + [os endEncapsulation]; + inEncaps = [os finished]; + [initial ice_invoke:@"opVarStruct" mode:ICENormal inEncaps:inEncaps outEncaps:&outEncaps]; + is = [ICEUtil createInputStream:communicator data:outEncaps]; + [is startEncapsulation]; + p2 = [TestOptionalVarStructHelper readOpt:is tag:1]; + p3 = [TestOptionalVarStructHelper readOpt:is tag:3]; + [is endEncapsulation]; + test([((TestOptionalVarStruct*)p2).m isEqual:@"test"] && [((TestOptionalVarStruct*)p3).m isEqual:@"test"]); + + is = [ICEUtil createInputStream:communicator data:outEncaps]; + [is startEncapsulation]; + [is endEncapsulation]; + } + + { + id p1 = ICENone; + id p3 = ICENone; + id p2 = [initial opOneOptional:p1 p3:&p3]; + test(p2 == ICENone && p3 == ICENone); + + p1 = [TestOptionalOneOptional oneOptional:@58]; + p2 = [initial opOneOptional:p1 p3:&p3]; + test([p2 isKindOfClass:[TestOptionalOneOptional class]] && [p3 isKindOfClass:[TestOptionalOneOptional class]]); + test(((TestOptionalOneOptional*)p2).a == 58 && ((TestOptionalOneOptional*)p3).a == 58); + + os = [ICEUtil createOutputStream:communicator]; + [os startEncapsulation]; + [ICEObjectHelper writeOpt:p1 stream:os tag:2]; + [os endEncapsulation]; + inEncaps = [os finished]; + [initial ice_invoke:@"opOneOptional" mode:ICENormal inEncaps:inEncaps outEncaps:&outEncaps]; + is = [ICEUtil createInputStream:communicator data:outEncaps]; + [is startEncapsulation]; + [ICEObjectHelper readOpt:&p2 stream:is tag:1]; + [ICEObjectHelper readOpt:&p3 stream:is tag:3]; + [is endEncapsulation]; + test([p2 isKindOfClass:[TestOptionalOneOptional class]] && [p3 isKindOfClass:[TestOptionalOneOptional class]]); + test(((TestOptionalOneOptional*)p2).a == 58 && ((TestOptionalOneOptional*)p3).a == 58); + + is = [ICEUtil createInputStream:communicator data:outEncaps]; + [is startEncapsulation]; + [is endEncapsulation]; + } + + { + id p1 = ICENone; + id p3 = ICENone; + id p2 = [initial opOneOptionalProxy:p1 p3:&p3]; + test(p2 == ICENone && p3 == ICENone); + + p1 = [TestOptionalOneOptionalPrx uncheckedCast:[communicator stringToProxy:@"test"]]; + p2 = [initial opOneOptionalProxy:p1 p3:&p3]; + test([p2 isKindOfClass:[TestOptionalOneOptionalPrx class]] && + [p3 isKindOfClass:[TestOptionalOneOptionalPrx class]]); + test([p2 isEqual:p1] && [p3 isEqual:p1]); + + os = [ICEUtil createOutputStream:communicator]; + [os startEncapsulation]; + [ICEProxyHelper writeOpt:p1 stream:os tag:2]; + [os endEncapsulation]; + inEncaps = [os finished]; + [initial ice_invoke:@"opOneOptionalProxy" mode:ICENormal inEncaps:inEncaps outEncaps:&outEncaps]; + is = [ICEUtil createInputStream:communicator data:outEncaps]; + [is startEncapsulation]; + p2 = [TestOptionalOneOptionalPrxHelper readOpt:is tag:1]; + p3 = [TestOptionalOneOptionalPrxHelper readOpt:is tag:3]; + [is endEncapsulation]; + test([p2 isKindOfClass:[TestOptionalOneOptionalPrx class]] && + [p3 isKindOfClass:[TestOptionalOneOptionalPrx class]]); + test([p2 isEqual:p1] && [p3 isEqual:p1]); + + is = [ICEUtil createInputStream:communicator data:outEncaps]; + [is startEncapsulation]; + [is endEncapsulation]; + } + + { + TestOptionalF* f = [TestOptionalF f]; + f.af = [TestOptionalA a]; + f.af.requiredA = 56; + f.ae = f.af; + + os = [ICEUtil createOutputStream:communicator]; + [os startEncapsulation]; + [TestOptionalFHelper writeOpt:f stream:os tag:1]; + [TestOptionalFHelper writeOpt:f.ae stream:os tag:2]; + [os endEncapsulation]; + inEncaps = [os finished]; + + is = [ICEUtil createInputStream:communicator data:inEncaps]; + [is startEncapsulation]; + id a; + [TestOptionalAHelper readOpt:&a stream:is tag:2]; + [is endEncapsulation]; + test(a != nil && [a isKindOfClass:[TestOptionalA class]] && ((TestOptionalA*)a).requiredA == 56); + } + tprintf("ok\n"); + + tprintf("testing optional parameters and sequences... "); + { + id p1 = ICENone; + id p3 = ICENone; + id p2 = [initial opByteSeq:p1 p3:&p3]; + test(p2 == ICENone && p3 == ICENone); + + TestOptionalByteSeq* bs = [TestOptionalMutableByteSeq dataWithLength:100]; + p1 = bs; + p2 = [initial opByteSeq:p1 p3:&p3]; + test([p2 isEqual:bs] && [p3 isEqual:bs]); + + os = [ICEUtil createOutputStream:communicator]; + [os startEncapsulation]; + [TestOptionalByteSeqHelper writeOpt:p1 stream:os tag:2]; + [os endEncapsulation]; + inEncaps = [os finished]; + [initial ice_invoke:@"opByteSeq" mode:ICENormal inEncaps:inEncaps outEncaps:&outEncaps]; + is = [ICEUtil createInputStream:communicator data:outEncaps]; + [is startEncapsulation]; + p2 = [TestOptionalByteSeqHelper readOpt:is tag:1]; + p3 = [TestOptionalByteSeqHelper readOpt:is tag:3]; + [is endEncapsulation]; + test([p2 isEqual:bs] && [p3 isEqual:bs]); + + is = [ICEUtil createInputStream:communicator data:outEncaps]; + [is startEncapsulation]; + [is endEncapsulation]; + } + + { + id p1 = ICENone; + id p3 = ICENone; + id p2 = [initial opBoolSeq:p1 p3:&p3]; + test(p2 == ICENone && p3 == ICENone); + + TestOptionalBoolSeq* bs = [TestOptionalMutableBoolSeq dataWithLength:100]; + p1 = bs; + p2 = [initial opBoolSeq:p1 p3:&p3]; + test([p2 isEqual:bs] && [p3 isEqual:bs]); + + os = [ICEUtil createOutputStream:communicator]; + [os startEncapsulation]; + [TestOptionalBoolSeqHelper writeOpt:p1 stream:os tag:2]; + [os endEncapsulation]; + inEncaps = [os finished]; + [initial ice_invoke:@"opBoolSeq" mode:ICENormal inEncaps:inEncaps outEncaps:&outEncaps]; + is = [ICEUtil createInputStream:communicator data:outEncaps]; + [is startEncapsulation]; + p2 = [TestOptionalBoolSeqHelper readOpt:is tag:1]; + p3 = [TestOptionalBoolSeqHelper readOpt:is tag:3]; + [is endEncapsulation]; + test([p2 isEqual:bs] && [p3 isEqual:bs]); + + is = [ICEUtil createInputStream:communicator data:outEncaps]; + [is startEncapsulation]; + [is endEncapsulation]; + } + + { + id p1 = ICENone; + id p3 = ICENone; + id p2 = [initial opShortSeq:p1 p3:&p3]; + test(p2 == ICENone && p3 == ICENone); + + TestOptionalShortSeq* bs = [TestOptionalMutableShortSeq dataWithLength:100 * sizeof(ICEShort)]; + p1 = bs; + p2 = [initial opShortSeq:p1 p3:&p3]; + test([p2 isEqual:bs] && [p3 isEqual:bs]); + + os = [ICEUtil createOutputStream:communicator]; + [os startEncapsulation]; + [TestOptionalShortSeqHelper writeOpt:p1 stream:os tag:2]; + [os endEncapsulation]; + inEncaps = [os finished]; + [initial ice_invoke:@"opShortSeq" mode:ICENormal inEncaps:inEncaps outEncaps:&outEncaps]; + is = [ICEUtil createInputStream:communicator data:outEncaps]; + [is startEncapsulation]; + p2 = [TestOptionalShortSeqHelper readOpt:is tag:1]; + p3 = [TestOptionalShortSeqHelper readOpt:is tag:3]; + [is endEncapsulation]; + test([p2 isEqual:bs] && [p3 isEqual:bs]); + + is = [ICEUtil createInputStream:communicator data:outEncaps]; + [is startEncapsulation]; + [is endEncapsulation]; + } + + { + id p1 = ICENone; + id p3 = ICENone; + id p2 = [initial opIntSeq:p1 p3:&p3]; + test(p2 == ICENone && p3 == ICENone); + + TestOptionalIntSeq* bs = [TestOptionalMutableIntSeq dataWithLength:100 * sizeof(ICEInt)]; + p1 = bs; + p2 = [initial opIntSeq:p1 p3:&p3]; + test([p2 isEqual:bs] && [p3 isEqual:bs]); + + os = [ICEUtil createOutputStream:communicator]; + [os startEncapsulation]; + [TestOptionalIntSeqHelper writeOpt:p1 stream:os tag:2]; + [os endEncapsulation]; + inEncaps = [os finished]; + [initial ice_invoke:@"opIntSeq" mode:ICENormal inEncaps:inEncaps outEncaps:&outEncaps]; + is = [ICEUtil createInputStream:communicator data:outEncaps]; + [is startEncapsulation]; + p2 = [TestOptionalIntSeqHelper readOpt:is tag:1]; + p3 = [TestOptionalIntSeqHelper readOpt:is tag:3]; + [is endEncapsulation]; + test([p2 isEqual:bs] && [p3 isEqual:bs]); + + is = [ICEUtil createInputStream:communicator data:outEncaps]; + [is startEncapsulation]; + [is endEncapsulation]; + } + + { + id p1 = ICENone; + id p3 = ICENone; + id p2 = [initial opLongSeq:p1 p3:&p3]; + test(p2 == ICENone && p3 == ICENone); + + TestOptionalLongSeq* bs = [TestOptionalMutableLongSeq dataWithLength:100 * sizeof(ICELong)]; + p1 = bs; + p2 = [initial opLongSeq:p1 p3:&p3]; + test([p2 isEqual:bs] && [p3 isEqual:bs]); + + os = [ICEUtil createOutputStream:communicator]; + [os startEncapsulation]; + [TestOptionalLongSeqHelper writeOpt:p1 stream:os tag:2]; + [os endEncapsulation]; + inEncaps = [os finished]; + [initial ice_invoke:@"opLongSeq" mode:ICENormal inEncaps:inEncaps outEncaps:&outEncaps]; + is = [ICEUtil createInputStream:communicator data:outEncaps]; + [is startEncapsulation]; + p2 = [TestOptionalLongSeqHelper readOpt:is tag:1]; + p3 = [TestOptionalLongSeqHelper readOpt:is tag:3]; + [is endEncapsulation]; + test([p2 isEqual:bs] && [p3 isEqual:bs]); + + is = [ICEUtil createInputStream:communicator data:outEncaps]; + [is startEncapsulation]; + [is endEncapsulation]; + } + + { + id p1 = ICENone; + id p3 = ICENone; + id p2 = [initial opFloatSeq:p1 p3:&p3]; + test(p2 == ICENone && p3 == ICENone); + + TestOptionalFloatSeq* bs = [TestOptionalMutableFloatSeq dataWithLength:100 * sizeof(ICEFloat)]; + p1 = bs; + p2 = [initial opFloatSeq:p1 p3:&p3]; + test([p2 isEqual:bs] && [p3 isEqual:bs]); + + os = [ICEUtil createOutputStream:communicator]; + [os startEncapsulation]; + [TestOptionalFloatSeqHelper writeOpt:p1 stream:os tag:2]; + [os endEncapsulation]; + inEncaps = [os finished]; + [initial ice_invoke:@"opFloatSeq" mode:ICENormal inEncaps:inEncaps outEncaps:&outEncaps]; + is = [ICEUtil createInputStream:communicator data:outEncaps]; + [is startEncapsulation]; + p2 = [TestOptionalFloatSeqHelper readOpt:is tag:1]; + p3 = [TestOptionalFloatSeqHelper readOpt:is tag:3]; + [is endEncapsulation]; + test([p2 isEqual:bs] && [p3 isEqual:bs]); + + is = [ICEUtil createInputStream:communicator data:outEncaps]; + [is startEncapsulation]; + [is endEncapsulation]; + } + + { + id p1 = ICENone; + id p3 = ICENone; + id p2 = [initial opDoubleSeq:p1 p3:&p3]; + test(p2 == ICENone && p3 == ICENone); + + TestOptionalDoubleSeq* bs = [TestOptionalMutableDoubleSeq dataWithLength:100 * sizeof(ICEDouble)]; + p1 = bs; + p2 = [initial opDoubleSeq:p1 p3:&p3]; + test([p2 isEqual:bs] && [p3 isEqual:bs]); + + os = [ICEUtil createOutputStream:communicator]; + [os startEncapsulation]; + [TestOptionalDoubleSeqHelper writeOpt:p1 stream:os tag:2]; + [os endEncapsulation]; + inEncaps = [os finished]; + [initial ice_invoke:@"opDoubleSeq" mode:ICENormal inEncaps:inEncaps outEncaps:&outEncaps]; + is = [ICEUtil createInputStream:communicator data:outEncaps]; + [is startEncapsulation]; + p2 = [TestOptionalDoubleSeqHelper readOpt:is tag:1]; + p3 = [TestOptionalDoubleSeqHelper readOpt:is tag:3]; + [is endEncapsulation]; + test([p2 isEqual:bs] && [p3 isEqual:bs]); + + is = [ICEUtil createInputStream:communicator data:outEncaps]; + [is startEncapsulation]; + [is endEncapsulation]; + } + + { + id p1 = ICENone; + id p3 = ICENone; + id p2 = [initial opStringSeq:p1 p3:&p3]; + test(p2 == ICENone && p3 == ICENone); + + TestOptionalMutableStringSeq* ss = [TestOptionalMutableStringSeq array]; + [ss addObject:@"test1"]; + p1 = ss; + p2 = [initial opStringSeq:p1 p3:&p3]; + test([p2 isEqual:ss] && [p3 isEqual:ss]); + + os = [ICEUtil createOutputStream:communicator]; + [os startEncapsulation]; + [TestOptionalStringSeqHelper writeOpt:p1 stream:os tag:2]; + [os endEncapsulation]; + inEncaps = [os finished]; + [initial ice_invoke:@"opStringSeq" mode:ICENormal inEncaps:inEncaps outEncaps:&outEncaps]; + is = [ICEUtil createInputStream:communicator data:outEncaps]; + [is startEncapsulation]; + p2 = [TestOptionalStringSeqHelper readOpt:is tag:1]; + p3 = [TestOptionalStringSeqHelper readOpt:is tag:3]; + [is endEncapsulation]; + test([p2 isEqual:ss] && [p3 isEqual:ss]); + + is = [ICEUtil createInputStream:communicator data:outEncaps]; + [is startEncapsulation]; + [is endEncapsulation]; + } + + { + id p1 = ICENone; + id p3 = ICENone; + id p2 = [initial opFixedStructSeq:p1 p3:&p3]; + test(p2 == ICENone && p3 == ICENone); + + p2 = [initial opFixedStructSeq:[TestOptionalMutableFixedStructSeq array] p3:&p3]; + test(p2 != nil && p3 != nil && [p2 count] == 0 && [p3 count] == 0); + + TestOptionalMutableFixedStructSeq* fss = [TestOptionalMutableFixedStructSeq array]; + [fss addObject:[TestOptionalFixedStruct fixedStruct:1]]; + [fss addObject:[TestOptionalFixedStruct fixedStruct:2]]; + [fss addObject:[TestOptionalFixedStruct fixedStruct:3]]; + [fss addObject:[TestOptionalFixedStruct fixedStruct:4]]; + [fss addObject:[TestOptionalFixedStruct fixedStruct:5]]; + [fss addObject:[TestOptionalFixedStruct fixedStruct:6]]; + [fss addObject:[TestOptionalFixedStruct fixedStruct:7]]; + [fss addObject:[TestOptionalFixedStruct fixedStruct:8]]; + [fss addObject:[TestOptionalFixedStruct fixedStruct:9]]; + [fss addObject:[TestOptionalFixedStruct fixedStruct:10]]; + p1 = fss; + p2 = [initial opFixedStructSeq:p1 p3:&p3]; + test(p2 != nil && p3 != nil); + test([p2 isEqual:fss] && [p3 isEqual:fss]); + + os = [ICEUtil createOutputStream:communicator]; + [os startEncapsulation]; + [TestOptionalFixedStructSeqHelper writeOpt:p1 stream:os tag:2]; + [os endEncapsulation]; + inEncaps = [os finished]; + [initial ice_invoke:@"opFixedStructSeq" mode:ICENormal inEncaps:inEncaps outEncaps:&outEncaps]; + is = [ICEUtil createInputStream:communicator data:outEncaps]; + [is startEncapsulation]; + p2 = [TestOptionalFixedStructSeqHelper readOpt:is tag:1]; + p3 = [TestOptionalFixedStructSeqHelper readOpt:is tag:3]; + [is endEncapsulation]; + test(p2 != nil && p3 != nil); + test([p2 isEqual:fss] && [p3 isEqual:fss]); + + is = [ICEUtil createInputStream:communicator data:outEncaps]; + [is startEncapsulation]; + [is endEncapsulation]; + } + + { + id p1 = ICENone; + id p3 = ICENone; + id p2 = [initial opVarStructSeq:p1 p3:&p3]; + test(p2 == ICENone && p3 == ICENone); + + p2 = [initial opVarStructSeq:[TestOptionalMutableVarStructSeq array] p3:&p3]; + test(p2 != nil && p3 != nil && [p2 count] == 0 && [p3 count] == 0); + + TestOptionalMutableVarStructSeq* fss = [TestOptionalMutableVarStructSeq array]; + [fss addObject:[TestOptionalVarStruct varStruct:@"1"]]; + [fss addObject:[TestOptionalVarStruct varStruct:@"2"]]; + [fss addObject:[TestOptionalVarStruct varStruct:@"3"]]; + [fss addObject:[TestOptionalVarStruct varStruct:@"4"]]; + [fss addObject:[TestOptionalVarStruct varStruct:@"5"]]; + [fss addObject:[TestOptionalVarStruct varStruct:@"6"]]; + [fss addObject:[TestOptionalVarStruct varStruct:@"7"]]; + [fss addObject:[TestOptionalVarStruct varStruct:@"8"]]; + [fss addObject:[TestOptionalVarStruct varStruct:@"9"]]; + [fss addObject:[TestOptionalVarStruct varStruct:@"10"]]; + p1 = fss; + p2 = [initial opVarStructSeq:p1 p3:&p3]; + test(p2 != nil && p3 != nil); + test([p2 isEqual:fss] && [p3 isEqual:fss]); + + os = [ICEUtil createOutputStream:communicator]; + [os startEncapsulation]; + [TestOptionalVarStructSeqHelper writeOpt:p1 stream:os tag:2]; + [os endEncapsulation]; + inEncaps = [os finished]; + [initial ice_invoke:@"opVarStructSeq" mode:ICENormal inEncaps:inEncaps outEncaps:&outEncaps]; + is = [ICEUtil createInputStream:communicator data:outEncaps]; + [is startEncapsulation]; + p2 = [TestOptionalVarStructSeqHelper readOpt:is tag:1]; + p3 = [TestOptionalVarStructSeqHelper readOpt:is tag:3]; + [is endEncapsulation]; + test(p2 != nil && p3 != nil); + test([p2 isEqual:fss] && [p3 isEqual:fss]); + + is = [ICEUtil createInputStream:communicator data:outEncaps]; + [is startEncapsulation]; + [is endEncapsulation]; + } + + tprintf("ok\n"); + + tprintf("testing exception optionals... "); + { + @try + { + [initial opOptionalException:ICENone b:ICENone o:ICENone]; + test(NO); + } + @catch(TestOptionalOptionalException* ex) + { + test(![ex hasA]); + test(![ex hasB]); + test(![ex hasO]); + } + + @try + { + [initial opOptionalException:@30 b:@"test" o:[TestOptionalOneOptional oneOptional:@53]]; + test(NO); + } + @catch(TestOptionalOptionalException* ex) + { + test(ex.a == 30); + test([ex.b isEqualToString:@"test"]); + test(ex.o.a == 53); + } + + @try + { + // + // Use the 1.0 encoding with an exception whose only class members are optional. + // + [[initial ice_encodingVersion:ICEEncoding_1_0] + opOptionalException:@30 b:@"test" o:[TestOptionalOneOptional oneOptional:@53]]; + test(NO); + } + @catch(TestOptionalOptionalException* ex) + { + test(![ex hasA]); + test(![ex hasB]); + test(![ex hasO]); + } + + @try + { + id a = ICENone; + id b = ICENone; + id o = ICENone; + [initial opDerivedException:a b:b o:o]; + test(NO); + } + @catch(TestOptionalDerivedException* ex) + { + test(![ex hasA]); + test(![ex hasB]); + test(![ex hasO]); + test(![ex hasSs]); + test(![ex hasO2]); + } + @catch(TestOptionalOptionalException* ex) + { + test(NO); + } + + @try + { + id a = @30; + id b = @"test2"; + TestOptionalOneOptional* o = [TestOptionalOneOptional oneOptional:@53]; + [initial opDerivedException:a b:b o:o]; + test(NO); + } + @catch(TestOptionalDerivedException* ex) + { + test(ex.a == 30); + test([ex.b isEqualToString:@"test2"]); + test(ex.o.a == 53); + test([ex.ss isEqualToString:@"test2"]); + test(ex.o2.a == 53); + } + @catch(TestOptionalOptionalException* ex) + { + test(NO); + } + + @try + { + id a = ICENone; + id b = ICENone; + id o = ICENone; + [initial opRequiredException:a b:b o:o]; + test(NO); + } + @catch(TestOptionalRequiredException* ex) + { + test(![ex hasA]); + test(![ex hasB]); + test(![ex hasO]); + test([ex.ss isEqualToString:@"test"]); + } + @catch(TestOptionalOptionalException* ex) + { + test(NO); + } + + @try + { + id a = @30; + id b = @"test2"; + id o = [TestOptionalOneOptional oneOptional:@53]; + [initial opRequiredException:a b:b o:o]; + test(NO); + } + @catch(TestOptionalRequiredException* ex) + { + test(ex.a == 30); + test([ex.b isEqualToString:@"test2"]); + test(ex.o.a == 53); + test([ex.ss isEqualToString:@"test2"]); + test(ex.o2.a == 53); + } + @catch(TestOptionalOptionalException* ex) + { + test(NO); + } + } + tprintf("ok\n"); + + return initial; +} diff --git a/objective-c/test/Ice/optional/Client.m b/objective-c/test/Ice/optional/Client.m new file mode 100644 index 00000000000..c78fe1729b9 --- /dev/null +++ b/objective-c/test/Ice/optional/Client.m @@ -0,0 +1,70 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <TestCommon.h> +#import <OptionalTest.h> + +static int +run(id<ICECommunicator> communicator) +{ + id<TestOptionalInitialPrx> optionalAllTests(id<ICECommunicator>); + id<TestOptionalInitialPrx> optional = optionalAllTests(communicator); + [optional shutdown]; + return EXIT_SUCCESS; +} + +#if TARGET_OS_IPHONE +# define main optionalClient +#endif + +int +main(int argc, char* argv[]) +{ + int status; + @autoreleasepool + { + id<ICECommunicator> communicator = nil; + @try + { + ICEInitializationData* initData = [ICEInitializationData initializationData]; + initData.properties = defaultClientProperties(&argc, argv); +#if TARGET_OS_IPHONE + initData.prefixTable__ = [NSDictionary dictionaryWithObjectsAndKeys: + @"TestOptional", @"::Test", + nil]; +#endif + communicator = [ICEUtil createCommunicator:&argc argv:argv initData:initData]; + status = run(communicator); + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + @catch(TestFailedException* ex) + { + status = EXIT_FAILURE; + } + + if(communicator) + { + @try + { + [communicator destroy]; + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + } + } + return status; +} diff --git a/objective-c/test/Ice/optional/Makefile b/objective-c/test/Ice/optional/Makefile new file mode 100644 index 00000000000..0a40f34414b --- /dev/null +++ b/objective-c/test/Ice/optional/Makefile @@ -0,0 +1,37 @@ +# ********************************************************************** +# +# Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +# +# This copy of Ice is licensed to you under the terms described in the +# ICE_LICENSE file included in this distribution. +# +# ********************************************************************** + +top_srcdir = ../../.. + +CLIENT = client +SERVER = server + +TARGETS = $(CLIENT) $(SERVER) + +SLICE_OBJS = OptionalTest.o + +COBJS = Client.o \ + AllTests.o + +SOBJS = TestI.o \ + Server.o + +OBJS = $(COBJS) $(SOBJS) $(SLICE_OBJS) + +include $(top_srcdir)/config/Make.rules + +CPPFLAGS := -I. -I.. -I../../include $(CPPFLAGS) + +$(CLIENT): $(COBJS) $(SLICE_OBJS) + rm -f $@ + $(CXX) $(LDFLAGS) $(LDEXEFLAGS) -o $@ $(COBJS) $(SLICE_OBJS) $(TEST_LIBS) + +$(SERVER): $(SOBJS) $(SLICE_OBJS) + rm -f $@ + $(CXX) $(LDFLAGS) $(LDEXEFLAGS) -o $@ $(SOBJS) $(SLICE_OBJS) $(TEST_LIBS) diff --git a/objective-c/test/Ice/optional/OptionalTest.ice b/objective-c/test/Ice/optional/OptionalTest.ice new file mode 100644 index 00000000000..624b5860673 --- /dev/null +++ b/objective-c/test/Ice/optional/OptionalTest.ice @@ -0,0 +1,288 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#pragma once + +[["cpp:include:list"]] + +["objc:prefix:TestOptional"] +module Test +{ + +class OneOptional +{ + optional(1) int a; +}; + +enum MyEnum +{ + MyEnumMember +}; + +struct SmallStruct +{ + byte m; +}; + +struct FixedStruct +{ + int m; +}; + +struct VarStruct +{ + string m; +}; + +["cpp:class"] struct ClassVarStruct +{ + int a; +}; + +sequence<byte> ByteSeq; +sequence<bool> BoolSeq; +sequence<short> ShortSeq; +sequence<int> IntSeq; +sequence<long> LongSeq; +sequence<float> FloatSeq; +sequence<double> DoubleSeq; +sequence<string> StringSeq; +sequence<MyEnum> MyEnumSeq; +sequence<SmallStruct> SmallStructSeq; +["cpp:type:std::list< ::Test::SmallStruct>"] sequence<SmallStruct> SmallStructList; +sequence<FixedStruct> FixedStructSeq; +["cpp:type:std::list< ::Test::FixedStruct>"] sequence<FixedStruct> FixedStructList; +sequence<VarStruct> VarStructSeq; +sequence<OneOptional> OneOptionalSeq; +sequence<OneOptional*> OneOptionalPrxSeq; + +sequence<byte> Serializable; + +dictionary<int, int> IntIntDict; +dictionary<string, int> StringIntDict; +dictionary<int, MyEnum> IntEnumDict; +dictionary<int, FixedStruct> IntFixedStructDict; +dictionary<int, VarStruct> IntVarStructDict; +dictionary<int, OneOptional> IntOneOptionalDict; +dictionary<int, OneOptional*> IntOneOptionalPrxDict; + +class MultiOptional +{ + optional(1) byte a; + optional(2) bool b; + optional(3) short c; + optional(4) int d; + optional(5) long e; + optional(6) float f; + optional(7) double g; + optional(8) string h; + optional(9) MyEnum i; + optional(10) MultiOptional* j; + optional(11) MultiOptional k; + optional(12) ByteSeq bs; + optional(13) StringSeq ss; + optional(14) IntIntDict iid; + optional(15) StringIntDict sid; + optional(16) FixedStruct fs; + optional(17) VarStruct vs; + + optional(18) ShortSeq shs; + optional(19) MyEnumSeq es; + optional(20) FixedStructSeq fss; + optional(21) VarStructSeq vss; + optional(22) OneOptionalSeq oos; + optional(23) OneOptionalPrxSeq oops; + + optional(24) IntEnumDict ied; + optional(25) IntFixedStructDict ifsd; + optional(26) IntVarStructDict ivsd; + optional(27) IntOneOptionalDict iood; + optional(28) IntOneOptionalPrxDict ioopd; + + optional(29) BoolSeq bos; + + optional(30) Serializable ser; +}; + +class A +{ + int requiredA = 0; + optional(500) int mc; + optional(50) int mb; + optional(1) int ma; +}; + +["preserve-slice"] +class B extends A +{ + int requiredB = 0; + optional(10) int md; +}; + +class C extends B +{ + string ss; + optional(890) string ms; +}; + +class WD +{ + optional(1) int a = 5; + optional(2) string s = "test"; +}; + +exception OptionalException +{ + bool req = false; + optional(1) int a = 5; + optional(2) string b; + optional(50) OneOptional o; +}; + +exception DerivedException extends OptionalException +{ + optional(600) string ss = "test"; + optional(601) OneOptional o2; +}; + +exception RequiredException extends OptionalException +{ + string ss = "test"; + OneOptional o2; +}; + +class OptionalWithCustom +{ + optional(1) SmallStructList l; + ["protected"] optional(2) SmallStructList lp; + optional(3) ClassVarStruct s; +}; + +class E +{ + A ae; +}; + +class F extends E +{ + optional(1) A af; +}; + +class Recursive; +sequence<Recursive> RecursiveSeq; + +class Recursive { + optional(0) RecursiveSeq value; +}; + +class Initial +{ + void shutdown(); + + Object pingPong(Object o); + + void opOptionalException(optional(1) int a, optional(2) string b, optional(3) OneOptional o) + throws OptionalException; + + void opDerivedException(optional(1) int a, optional(2) string b, optional(3) OneOptional o) + throws OptionalException; + + void opRequiredException(optional(1) int a, optional(2) string b, optional(3) OneOptional o) + throws OptionalException; + + optional(1) byte opByte(optional(2) byte p1, out optional(3) byte p3); + + optional(1) bool opBool(optional(2) bool p1, out optional(3) bool p3); + + optional(1) short opShort(optional(2) short p1, out optional(3) short p3); + + optional(1) int opInt(optional(2) int p1, out optional(3) int p3); + + optional(3) long opLong(optional(1) long p1, out optional(2) long p3); + + optional(1) float opFloat(optional(2) float p1, out optional(3) float p3); + + optional(1) double opDouble(optional(2) double p1, out optional(3) double p3); + + optional(1) string opString(optional(2) string p1, out optional(3) string p3); + + optional(1) MyEnum opMyEnum(optional(2) MyEnum p1, out optional(3) MyEnum p3); + + optional(1) SmallStruct opSmallStruct(optional(2) SmallStruct p1, out optional(3) SmallStruct p3); + + optional(1) FixedStruct opFixedStruct(optional(2) FixedStruct p1, out optional(3) FixedStruct p3); + + optional(1) VarStruct opVarStruct(optional(2) VarStruct p1, out optional(3) VarStruct p3); + + optional(1) OneOptional opOneOptional(optional(2) OneOptional p1, out optional(3) OneOptional p3); + + optional(1) OneOptional* opOneOptionalProxy(optional(2) OneOptional* p1, out optional(3) OneOptional* p3); + + // Custom mapping operations + ["cpp:array"] optional(1) ByteSeq opByteSeq(["cpp:array"] optional(2) ByteSeq p1, + out ["cpp:array"] optional(3) ByteSeq p3); + + ["cpp:array"] optional(1) BoolSeq opBoolSeq(["cpp:array"] optional(2) BoolSeq p1, + out ["cpp:array"] optional(3) BoolSeq p3); + + ["cpp:array"] optional(1) ShortSeq opShortSeq(["cpp:array"] optional(2) ShortSeq p1, + out ["cpp:array"] optional(3) ShortSeq p3); + + ["cpp:range:array"] optional(1) IntSeq opIntSeq(["cpp:range:array"] optional(2) IntSeq p1, + out ["cpp:range:array"] optional(3) IntSeq p3); + + ["cpp:range:array"] optional(1) LongSeq opLongSeq(["cpp:range:array"] optional(2) LongSeq p1, + out ["cpp:range:array"] optional(3) LongSeq p3); + + ["cpp:range:array"] optional(1) FloatSeq opFloatSeq(["cpp:range:array"] optional(2) FloatSeq p1, + out ["cpp:range:array"] optional(3) FloatSeq p3); + + ["cpp:range:array"] optional(1) DoubleSeq opDoubleSeq(["cpp:range:array"] optional(2) DoubleSeq p1, + out ["cpp:range:array"] optional(3) DoubleSeq p3); + + ["cpp:range"] optional(1) StringSeq opStringSeq(["cpp:range"] optional(2) StringSeq p1, + out ["cpp:range"] optional(3) StringSeq p3); + + ["cpp:array"] optional(1) SmallStructSeq opSmallStructSeq(["cpp:array"] optional(2) SmallStructSeq p1, + out ["cpp:array"] optional(3) SmallStructSeq p3); + + ["cpp:array"] optional(1) SmallStructList opSmallStructList(["cpp:array"] optional(2) SmallStructList p1, + out ["cpp:array"] optional(3) SmallStructList p3); + + ["cpp:array"] optional(1) FixedStructSeq opFixedStructSeq(["cpp:array"] optional(2) FixedStructSeq p1, + out ["cpp:array"] optional(3) FixedStructSeq p3); + + ["cpp:array"] optional(1) FixedStructList opFixedStructList(["cpp:array"] optional(2) FixedStructList p1, + out ["cpp:array"] optional(3) FixedStructList p3); + + ["cpp:range"] optional(1) VarStructSeq opVarStructSeq(["cpp:range"] optional(2) VarStructSeq p1, + out ["cpp:range"] optional(3) VarStructSeq p3); + + optional(1) Serializable opSerializable(optional(2) Serializable p1, out optional(3) Serializable p3); + + optional(1) IntIntDict opIntIntDict(optional(2) IntIntDict p1, out optional(3) IntIntDict p3); + + optional(1) StringIntDict opStringIntDict(optional(2) StringIntDict p1, out optional(3) StringIntDict p3); + + void opClassAndUnknownOptional(A p); + + void sendOptionalClass(bool req, optional(1) OneOptional o); + + void returnOptionalClass(bool req, out optional(1) OneOptional o); + + bool supportsRequiredParams(); + + bool supportsJavaSerializable(); + + bool supportsCsharpSerializable(); + + bool supportsCppStringView(); +}; + +}; diff --git a/objective-c/test/Ice/optional/Server.m b/objective-c/test/Ice/optional/Server.m new file mode 100644 index 00000000000..c83691ebd83 --- /dev/null +++ b/objective-c/test/Ice/optional/Server.m @@ -0,0 +1,72 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <optional/TestI.h> +#import <TestCommon.h> + +static int +run(id<ICECommunicator> communicator) +{ + [[communicator getProperties] setProperty:@"TestAdapter.Endpoints" value:@"default -p 12010"]; + id<ICEObjectAdapter> adapter = [communicator createObjectAdapter:@"TestAdapter"]; + ICEObject* object = [InitialI initial]; + [adapter add:object identity:[communicator stringToIdentity:@"initial"]]; + [adapter activate]; + + serverReady(communicator); + + [communicator waitForShutdown]; + return EXIT_SUCCESS; +} + +#if TARGET_OS_IPHONE +# define main optionalServer +#endif + +int +main(int argc, char* argv[]) +{ + int status; + @autoreleasepool + { + id<ICECommunicator> communicator = nil; + @try + { + ICEInitializationData* initData = [ICEInitializationData initializationData]; + initData.properties = defaultServerProperties(&argc, argv); +#if TARGET_OS_IPHONE + initData.prefixTable__ = [NSDictionary dictionaryWithObjectsAndKeys: + @"TestOptional", @"::Test", + nil]; +#endif + communicator = [ICEUtil createCommunicator:&argc argv:argv initData:initData]; + status = run(communicator); + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + + if(communicator) + { + @try + { + [communicator destroy]; + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + } + } + return status; +} diff --git a/objective-c/test/Ice/optional/TestI.h b/objective-c/test/Ice/optional/TestI.h new file mode 100644 index 00000000000..1cda632e774 --- /dev/null +++ b/objective-c/test/Ice/optional/TestI.h @@ -0,0 +1,18 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <OptionalTest.h> + +@interface InitialI : TestOptionalInitial<TestOptionalInitial> +-(void) shutdown:(ICECurrent *)current; +-(ICEObject*) pingPong:(ICEObject*)obj current:(ICECurrent*)current; +-(BOOL) supportsRequiredParams:(ICECurrent*)current; +-(BOOL) supportsJavaSerializable:(ICECurrent*)current; +-(BOOL) supportsCsharpSerializable:(ICECurrent*)current; +@end diff --git a/objective-c/test/Ice/optional/TestI.m b/objective-c/test/Ice/optional/TestI.m new file mode 100644 index 00000000000..2139322e270 --- /dev/null +++ b/objective-c/test/Ice/optional/TestI.m @@ -0,0 +1,243 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <optional/TestI.h> +#import <objc/Ice.h> + +#import <Foundation/NSThread.h> + +@implementation InitialI +-(void) shutdown:(ICECurrent*)current +{ + [[current.adapter getCommunicator] shutdown]; +} +-(ICEObject*) pingPong:(ICEObject*)obj current:(ICECurrent*)current +{ + return obj; +} +-(void) opOptionalException:(id)a b:(id)b o:(id)o current:(ICECurrent *)current +{ + @throw [TestOptionalOptionalException optionalException:NO a:a b:b o:o]; +} +-(void) opDerivedException:(id)a b:(id)b o:(id)o current:(ICECurrent *)current +{ + @throw [TestOptionalDerivedException derivedException:NO a:a b:b o:o ss:b o2:o]; +} +-(void) opRequiredException:(id)a b:(id)b o:(id)o current:(ICECurrent *)current +{ + TestOptionalRequiredException* ex = [TestOptionalRequiredException requiredException]; + if(a != ICENone) + { + ex.a = [a intValue]; + } + else + { + [ex clearA]; + } + if(b != ICENone) + { + ex.b = b; + } + else + { + [ex clearB]; + } + if(o != ICENone) + { + ex.o = o; + ex.o2 = o; + } + else + { + [ex clearO]; + } + if(b != ICENone) + { + ex.ss = b; + } + @throw ex; +} +-(id) opByte:(id)p1 p3:(id *)p3 current:(ICECurrent *)current +{ + *p3 = p1; + return p1; +} +-(id) opBool:(id)p1 p3:(id *)p3 current:(ICECurrent *)current +{ + *p3 = p1; + return p1; +} +-(id) opShort:(id)p1 p3:(id *)p3 current:(ICECurrent *)current +{ + *p3 = p1; + return p1; +} +-(id) opInt:(id)p1 p3:(id *)p3 current:(ICECurrent *)current +{ + *p3 = p1; + return p1; +} +-(id) opLong:(id)p1 p3:(id *)p3 current:(ICECurrent *)current +{ + *p3 = p1; + return p1; +} +-(id) opFloat:(id)p1 p3:(id *)p3 current:(ICECurrent *)current +{ + *p3 = p1; + return p1; +} +-(id) opDouble:(id)p1 p3:(id *)p3 current:(ICECurrent *)current +{ + *p3 = p1; + return p1; +} +-(id) opString:(id)p1 p3:(id *)p3 current:(ICECurrent *)current +{ + *p3 = p1; + return p1; +} +-(id) opMyEnum:(id)p1 p3:(id *)p3 current:(ICECurrent *)current +{ + *p3 = p1; + return p1; +} +-(id) opSmallStruct:(id)p1 p3:(id *)p3 current:(ICECurrent *)current +{ + *p3 = p1; + return p1; +} +-(id) opFixedStruct:(id)p1 p3:(id *)p3 current:(ICECurrent *)current +{ + *p3 = p1; + return p1; +} +-(id) opVarStruct:(id)p1 p3:(id *)p3 current:(ICECurrent *)current +{ + *p3 = p1; + return p1; +} +-(id) opOneOptional:(id)p1 p3:(id *)p3 current:(ICECurrent *)current +{ + *p3 = p1; + return p1; +} +-(id) opOneOptionalProxy:(id)p1 p3:(id *)p3 current:(ICECurrent *)current +{ + *p3 = p1; + return p1; +} +-(id) opByteSeq:(id)p1 p3:(id *)p3 current:(ICECurrent *)current +{ + *p3 = p1; + return p1; +} +-(id) opBoolSeq:(id)p1 p3:(id *)p3 current:(ICECurrent *)current +{ + *p3 = p1; + return p1; +} +-(id) opShortSeq:(id)p1 p3:(id *)p3 current:(ICECurrent *)current +{ + *p3 = p1; + return p1; +} +-(id) opIntSeq:(id)p1 p3:(id *)p3 current:(ICECurrent *)current +{ + *p3 = p1; + return p1; +} +-(id) opLongSeq:(id)p1 p3:(id *)p3 current:(ICECurrent *)current +{ + *p3 = p1; + return p1; +} +-(id) opFloatSeq:(id)p1 p3:(id *)p3 current:(ICECurrent *)current +{ + *p3 = p1; + return p1; +} +-(id) opDoubleSeq:(id)p1 p3:(id *)p3 current:(ICECurrent *)current +{ + *p3 = p1; + return p1; +} +-(id) opStringSeq:(id)p1 p3:(id *)p3 current:(ICECurrent *)current +{ + *p3 = p1; + return p1; +} +-(id) opSmallStructSeq:(id)p1 p3:(id *)p3 current:(ICECurrent *)current +{ + *p3 = p1; + return p1; +} +-(id) opSmallStructList:(id)p1 p3:(id *)p3 current:(ICECurrent *)current +{ + *p3 = p1; + return p1; +} +-(id) opFixedStructSeq:(id)p1 p3:(id *)p3 current:(ICECurrent *)current +{ + *p3 = p1; + return p1; +} +-(id) opFixedStructList:(id)p1 p3:(id *)p3 current:(ICECurrent *)current +{ + *p3 = p1; + return p1; +} +-(id) opVarStructSeq:(id)p1 p3:(id *)p3 current:(ICECurrent *)current +{ + *p3 = p1; + return p1; +} +-(id) opSerializable:(id)p1 p3:(id *)p3 current:(ICECurrent *)current +{ + *p3 = p1; + return p1; +} +-(id) opIntIntDict:(id)p1 p3:(id *)p3 current:(ICECurrent *)current +{ + *p3 = p1; + return p1; +} +-(id) opStringIntDict:(id)p1 p3:(id *)p3 current:(ICECurrent *)current +{ + *p3 = p1; + return p1; +} +-(void) opClassAndUnknownOptional:(TestOptionalA *)p current:(ICECurrent *)current +{ +} +-(void) sendOptionalClass:(BOOL)req o:(id)o current:(ICECurrent *)current +{ +} +-(void) returnOptionalClass:(BOOL)req o:(id *)o current:(ICECurrent *)current +{ + *o = [TestOptionalOneOptional oneOptional:@53]; +} +-(BOOL) supportsRequiredParams:(ICECurrent*)current +{ + return NO; +} +-(BOOL) supportsJavaSerializable:(ICECurrent*)current +{ + return NO; +} +-(BOOL) supportsCsharpSerializable:(ICECurrent*)current +{ + return NO; +} +-(BOOL) supportsCppStringView:(ICECurrent*)current +{ + return NO; +} + +@end diff --git a/objective-c/test/Ice/optional/run.py b/objective-c/test/Ice/optional/run.py new file mode 100755 index 00000000000..121ce5fd8b0 --- /dev/null +++ b/objective-c/test/Ice/optional/run.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python +# ********************************************************************** +# +# Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +# +# This copy of Ice is licensed to you under the terms described in the +# ICE_LICENSE file included in this distribution. +# +# ********************************************************************** + +import os, sys + +path = [ ".", "..", "../..", "../../..", "../../../..", "../../../../.." ] +head = os.path.dirname(sys.argv[0]) +if len(head) > 0: + path = [os.path.join(head, p) for p in path] +path = [os.path.abspath(p) for p in path if os.path.exists(os.path.join(p, "scripts", "TestUtil.py")) ] +if len(path) == 0: + raise RuntimeError("can't find toplevel directory!") +sys.path.append(os.path.join(path[0], "scripts")) +import TestUtil + +print("Running test with compact (default) format.") +TestUtil.clientServerTest() +print("Running test with sliced format.") +TestUtil.clientServerTest(additionalClientOptions="--Ice.Default.SlicedFormat", additionalServerOptions="--Ice.Default.SlicedFormat") diff --git a/objective-c/test/Ice/proxy/.gitignore b/objective-c/test/Ice/proxy/.gitignore new file mode 100644 index 00000000000..ced1dc09cab --- /dev/null +++ b/objective-c/test/Ice/proxy/.gitignore @@ -0,0 +1,9 @@ +// Generated by makegitignore.py + +// IMPORTANT: Do not edit this file -- any edits made here will be lost! +client +server +collocated +.depend +ProxyTest.m +ProxyTest.h diff --git a/objective-c/test/Ice/proxy/AllTests.m b/objective-c/test/Ice/proxy/AllTests.m new file mode 100644 index 00000000000..3c2d2a11f1b --- /dev/null +++ b/objective-c/test/Ice/proxy/AllTests.m @@ -0,0 +1,960 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <TestCommon.h> +#import <ProxyTest.h> + + +TestProxyMyClassPrx* +proxyAllTests(id<ICECommunicator> communicator) +{ + tprintf("testing stringToProxy... "); + NSString* ref = @"test:default -p 12010"; + id<ICEObjectPrx> base = [communicator stringToProxy:ref]; + test(base); + + id<ICEObjectPrx> b1 = [communicator stringToProxy:@"test"]; + test([[[b1 ice_getIdentity] name] isEqualToString:@"test"] && + [[[b1 ice_getIdentity] category] length] == 0 && + [[b1 ice_getAdapterId] length] == 0 && [[b1 ice_getFacet] length] == 0); + b1 = [communicator stringToProxy:@"test "]; + test([[[b1 ice_getIdentity] name] isEqualToString:@"test"] && + [[[b1 ice_getIdentity] category] length] == 0 && + [[b1 ice_getFacet] length] == 0); + b1 = [communicator stringToProxy:@" test "]; + test([[[b1 ice_getIdentity] name] isEqualToString:@"test"] && + [[[b1 ice_getIdentity] category] length] == 0 && + [[b1 ice_getFacet] length] == 0); + b1 = [communicator stringToProxy:@" test"]; + test([[[b1 ice_getIdentity] name] isEqualToString:@"test"] && + [[[b1 ice_getIdentity] category] length] == 0 && + [[b1 ice_getFacet] length] == 0); + b1 = [communicator stringToProxy:@"'test -f facet'"]; + test([[[b1 ice_getIdentity] name] isEqualToString:@"test -f facet"] && + [[[b1 ice_getIdentity] category] length] == 0 && + [[b1 ice_getFacet] length] == 0); + @try + { + b1 = [communicator stringToProxy:@"\"test -f facet'"]; + test(NO); + } + @catch(ICEProxyParseException*) + { + } + b1 = [communicator stringToProxy:@"\"test -f facet\""]; + test([[[b1 ice_getIdentity] name] isEqualToString:@"test -f facet"] && + [[[b1 ice_getIdentity] category] length] == 0 && + [[b1 ice_getFacet] length] == 0); + b1 = [communicator stringToProxy:@"\"test -f facet@test\""]; + test([[[b1 ice_getIdentity] name] isEqualToString:@"test -f facet@test"] && + [[[b1 ice_getIdentity] category] length] == 0 && + [[b1 ice_getFacet] length] == 0); + b1 = [communicator stringToProxy:@"\"test -f facet@test @test\""]; + test([[[b1 ice_getIdentity] name] isEqualToString:@"test -f facet@test @test"] && + [[[b1 ice_getIdentity] category] length] == 0 && + [[b1 ice_getFacet] length] == 0); + @try + { + b1 = [communicator stringToProxy:@"test test"]; + test(NO); + } + @catch(ICEProxyParseException*) + { + } + b1 = [communicator stringToProxy:@"test\\040test"]; + test([[[b1 ice_getIdentity] name] isEqualToString:@"test test"] && + [[[b1 ice_getIdentity] category] length] == 0); + @try + { + b1 = [communicator stringToProxy:@"test\\777"]; + test(NO); + } + @catch(ICEIdentityParseException*) + { + } + b1 = [communicator stringToProxy:@"test\\40test"]; + test([[[b1 ice_getIdentity] name] isEqualToString:@"test test"]); + + // TestProxy some octal and hex corner cases. + b1 = [communicator stringToProxy:@"test\\4test"]; + test([[[b1 ice_getIdentity] name] isEqualToString:@"test\4test"]); + b1 = [communicator stringToProxy:@"test\\04test"]; + test([[[b1 ice_getIdentity] name] isEqualToString:@"test\4test"]); + b1 = [communicator stringToProxy:@"test\\004test"]; + test([[[b1 ice_getIdentity] name] isEqualToString:@"test\4test"]); + b1 = [communicator stringToProxy:@"test\\1114test"]; + test([[[b1 ice_getIdentity] name] isEqualToString:@"test\1114test"]); + + b1 = [communicator stringToProxy:@"test\\b\\f\\n\\r\\t\\'\\\"\\\\test"]; + test([[[b1 ice_getIdentity] name] isEqualToString:@"test\b\f\n\r\t\'\"\\test"] && + [[[b1 ice_getIdentity] category] length] == 0); + + b1 = [communicator stringToProxy:@"category/test"]; + test([[[b1 ice_getIdentity] name] isEqualToString:@"test"] && + [[[b1 ice_getIdentity] category] isEqualToString:@"category"] && + [[b1 ice_getAdapterId] length] == 0); + + b1 = [communicator stringToProxy:@"test@adapter"]; + test([[[b1 ice_getIdentity] name] isEqualToString:@"test"] && + [[[b1 ice_getIdentity] category] length] == 0 && + [[b1 ice_getAdapterId] isEqualToString:@"adapter"]); + @try + { + b1 = [communicator stringToProxy:@"id@adapter test"]; + test(NO); + } + @catch(ICEProxyParseException*) + { + } + b1 = [communicator stringToProxy:@"category/test@adapter"]; + test([[[b1 ice_getIdentity] name] isEqualToString:@"test"] && + [[[b1 ice_getIdentity] category] isEqualToString:@"category"] && + [[b1 ice_getAdapterId] isEqualToString:@"adapter"]); + b1 = [communicator stringToProxy:@"category/test@adapter:tcp"]; + test([[[b1 ice_getIdentity] name] isEqualToString:@"test"] && + [[[b1 ice_getIdentity] category] isEqualToString:@"category"] && + [[b1 ice_getAdapterId] isEqualToString:@"adapter:tcp"]); + b1 = [communicator stringToProxy:@"'category 1/test'@adapter"]; + test([[[b1 ice_getIdentity] name] isEqualToString:@"test"] && + [[[b1 ice_getIdentity] category] isEqualToString:@"category 1"] && + [[b1 ice_getAdapterId] isEqualToString:@"adapter"]); + b1 = [communicator stringToProxy:@"'category/test 1'@adapter"]; + test([[[b1 ice_getIdentity] name] isEqualToString:@"test 1"] && + [[[b1 ice_getIdentity] category] isEqualToString:@"category"] && + [[b1 ice_getAdapterId] isEqualToString:@"adapter"]); + b1 = [communicator stringToProxy:@"'category/test'@'adapter 1'"]; + test([[[b1 ice_getIdentity] name] isEqualToString:@"test"] && + [[[b1 ice_getIdentity] category] isEqualToString:@"category"] && + [[b1 ice_getAdapterId] isEqualToString:@"adapter 1"]); + b1 = [communicator stringToProxy:@"\"category \\/test@foo/test\"@adapter"]; + test([[[b1 ice_getIdentity] name] isEqualToString:@"test"] && + [[[b1 ice_getIdentity] category] isEqualToString:@"category /test@foo"] && + [[b1 ice_getAdapterId] isEqualToString:@"adapter"]); + b1 = [communicator stringToProxy:@"\"category \\/test@foo/test\"@\"adapter:tcp\""]; + test([[[b1 ice_getIdentity] name] isEqualToString:@"test"] && + [[[b1 ice_getIdentity] category] isEqualToString:@"category /test@foo"] && + [[b1 ice_getAdapterId] isEqualToString:@"adapter:tcp"]); + + b1 = [communicator stringToProxy:@"id -f facet"]; + test([[[b1 ice_getIdentity] name] isEqualToString:@"id"] && [[[b1 ice_getIdentity] category] length] == 0 && + [[b1 ice_getFacet] isEqualToString:@"facet"]); + b1 = [communicator stringToProxy:@"id -f 'facet x'"]; + test([[[b1 ice_getIdentity] name] isEqualToString:@"id"] && [[[b1 ice_getIdentity] category] length] == 0 && + [[b1 ice_getFacet] isEqualToString:@"facet x"]); + b1 = [communicator stringToProxy:@"id -f \"facet x\""]; + test([[[b1 ice_getIdentity] name] isEqualToString:@"id"] && [[[b1 ice_getIdentity] category] length] == 0 && + [[b1 ice_getFacet] isEqualToString:@"facet x"]); + @try + { + b1 = [communicator stringToProxy:@"id -f \"facet x"]; + test(NO); + } + @catch(ICEProxyParseException*) + { + } + @try + { + b1 = [communicator stringToProxy:@"id -f \'facet x"]; + test(NO); + } + @catch(ICEProxyParseException*) + { + } + b1 = [communicator stringToProxy:@"test -f facet:tcp"]; + test([[[b1 ice_getIdentity] name] isEqualToString:@"test"] && [[[b1 ice_getIdentity] category] length] == 0 && + [[b1 ice_getFacet] isEqualToString:@"facet"] && [[b1 ice_getAdapterId] length] == 0); + b1 = [communicator stringToProxy:@"test -f \"facet:tcp\""]; + test([[[b1 ice_getIdentity] name] isEqualToString:@"test"] && [[[b1 ice_getIdentity] category] length] == 0 && + [[b1 ice_getFacet] isEqualToString:@"facet:tcp"] && [[b1 ice_getAdapterId] length] == 0); + b1 = [communicator stringToProxy:@"test -f facet@test"]; + test([[[b1 ice_getIdentity] name] isEqualToString:@"test"] && [[[b1 ice_getIdentity] category] length] == 0 && + [[b1 ice_getFacet] isEqualToString:@"facet"] && [[b1 ice_getAdapterId] isEqualToString:@"test"]); + b1 = [communicator stringToProxy:@"test -f 'facet@test'"]; + test([[[b1 ice_getIdentity] name] isEqualToString:@"test"] && [[[b1 ice_getIdentity] category] length] == 0 && + [[b1 ice_getFacet] isEqualToString:@"facet@test"] && [[b1 ice_getAdapterId] length] == 0); + b1 = [communicator stringToProxy:@"test -f 'facet@test'@test"]; + test([[[b1 ice_getIdentity] name] isEqualToString:@"test"] && [[[b1 ice_getIdentity] category] length] == 0 && + [[b1 ice_getFacet] isEqualToString:@"facet@test"] && [[b1 ice_getAdapterId] isEqualToString:@"test"]); + @try + { + b1 = [communicator stringToProxy:@"test -f facet@test @test"]; + test(NO); + } + @catch(ICEProxyParseException*) + { + } + b1 = [communicator stringToProxy:@"test"]; + test([b1 ice_isTwoway]); + b1 = [communicator stringToProxy:@"test -t"]; + test([b1 ice_isTwoway]); + b1 = [communicator stringToProxy:@"test -o"]; + test([b1 ice_isOneway]); + b1 = [communicator stringToProxy:@"test -O"]; + test([b1 ice_isBatchOneway]); + b1 = [communicator stringToProxy:@"test -d"]; + test([b1 ice_isDatagram]); + b1 = [communicator stringToProxy:@"test -D"]; + test([b1 ice_isBatchDatagram]); + b1 = [communicator stringToProxy:@"test"]; + test(![b1 ice_isSecure]); + b1 = [communicator stringToProxy:@"test -s"]; + test([b1 ice_isSecure]); + + test([[b1 ice_getEncodingVersion] isEqual:ICECurrentEncoding]); + + b1 = [communicator stringToProxy:@"test -e 1.0"]; + test([b1 ice_getEncodingVersion].major == 1 && [b1 ice_getEncodingVersion].minor == 0); + + b1 = [communicator stringToProxy:@"test -e 6.5"]; + test([b1 ice_getEncodingVersion].major == 6 && [b1 ice_getEncodingVersion].minor == 5); + + b1 = [communicator stringToProxy:@"test -p 1.0 -e 1.0"]; + test([[b1 ice_toString] isEqualToString:@"test -t -e 1.0"]); + + b1 = [communicator stringToProxy:@"test -p 6.5 -e 1.0"]; + test([[b1 ice_toString] isEqualToString:@"test -t -p 6.5 -e 1.0"]); + + @try + { + b1 = [communicator stringToProxy:@"test:tcp@adapterId"]; + test(NO); + } + @catch(ICEEndpointParseException*) + { + } + // This is an unknown endpoint warning, not a parse exception. + // + //try + //{ + // b1 = [communicator stringToProxy:@"test -f the:facet:tcp"]; + // test(NO); + //} + //catch(ICEEndpointParseException*) + //{ + //} + @try + { + b1 = [communicator stringToProxy:@"test::tcp"]; + test(NO); + } + @catch(ICEEndpointParseException*) + { + } + tprintf("ok\n"); + + tprintf("testing propertyToProxy... "); + id<ICEProperties> prop = [communicator getProperties]; + NSString* propertyPrefix = @"Foo.Proxy"; + [prop setProperty:propertyPrefix value:@"test:default -p 12010"]; + b1 = [communicator propertyToProxy:propertyPrefix]; + test([[[b1 ice_getIdentity] name] isEqualToString:@"test"] && [[[b1 ice_getIdentity] category] length] == 0 && + [[b1 ice_getAdapterId] length] == 0 && [[b1 ice_getFacet] length] == 0); + + NSString* property; + + property = [propertyPrefix stringByAppendingString:@".Locator"]; + test(![b1 ice_getLocator]); + [prop setProperty:property value:@"locator:default -p 10000"]; + b1 = [communicator propertyToProxy:propertyPrefix]; + test([b1 ice_getLocator] && [[[[b1 ice_getLocator] ice_getIdentity] name] isEqualToString:@"locator"]); + [prop setProperty:property value:@""]; + + property = [propertyPrefix stringByAppendingString:@".LocatorCacheTimeout"]; + test([b1 ice_getLocatorCacheTimeout] == -1); + [prop setProperty:property value:@"1"]; + b1 = [communicator propertyToProxy:propertyPrefix]; + test([b1 ice_getLocatorCacheTimeout] == 1); + [prop setProperty:property value:@""]; + + // Now retest with an indirect proxy. + [prop setProperty:propertyPrefix value:@"test"]; + property = [propertyPrefix stringByAppendingString:@".Locator"]; + [prop setProperty:property value:@"locator:default -p 10000"]; + b1 = [communicator propertyToProxy:propertyPrefix]; + test([b1 ice_getLocator] && [[[[b1 ice_getLocator] ice_getIdentity] name] isEqualToString:@"locator"]); + [prop setProperty:property value:@""]; + + property = [propertyPrefix stringByAppendingString:@".LocatorCacheTimeout"]; + test([b1 ice_getLocatorCacheTimeout] == -1); + [prop setProperty:property value:@"1"]; + b1 = [communicator propertyToProxy:propertyPrefix]; + test([b1 ice_getLocatorCacheTimeout] == 1); + [prop setProperty:property value:@""]; + + // This cannot be tested so easily because the property is cached + // on communicator initialization. + // + //prop->setProperty:"Ice.Default.LocatorCacheTimeout" :@"60"); + //b1 = [communicator propertyToProxy:propertyPrefix]; + //test([b1 ice_getLocatorCacheTimeout] == 60); + //prop->setProperty("Ice.Default.LocatorCacheTimeout" :@""); + + [prop setProperty:propertyPrefix value:@"test:default -p 12010"]; + + property = [propertyPrefix stringByAppendingString:@".Router"]; + test(![b1 ice_getRouter]); + [prop setProperty:property value:@"router:default -p 10000"]; + b1 = [communicator propertyToProxy:propertyPrefix]; + test([b1 ice_getRouter] && [[[[b1 ice_getRouter] ice_getIdentity] name] isEqualToString:@"router"]); + [prop setProperty:property value:@""]; + + property = [propertyPrefix stringByAppendingString:@".PreferSecure"]; + test(![b1 ice_isPreferSecure]); + [prop setProperty:property value:@"1"]; + b1 = [communicator propertyToProxy:propertyPrefix]; + test([b1 ice_isPreferSecure]); + [prop setProperty:property value:@""]; + + property = [propertyPrefix stringByAppendingString:@".ConnectionCached"]; + test([b1 ice_isConnectionCached]); + [prop setProperty:property value:@"0"]; + b1 = [communicator propertyToProxy:propertyPrefix]; + test(![b1 ice_isConnectionCached]); + [prop setProperty:property value:@""]; + + property = [propertyPrefix stringByAppendingString:@".InvocationTimeout"]; + test([b1 ice_getInvocationTimeout] == -1); + [prop setProperty:property value:@"1000"]; + b1 = [communicator propertyToProxy:propertyPrefix]; + test([b1 ice_getInvocationTimeout] == 1000); + [prop setProperty:property value:@""]; + + property = [propertyPrefix stringByAppendingString:@".EndpointSelection"]; + test([b1 ice_getEndpointSelection] == ICERandom); + [prop setProperty:property value:@"Random"]; + b1 = [communicator propertyToProxy:propertyPrefix]; + test([b1 ice_getEndpointSelection] == ICERandom); + [prop setProperty:property value:@"Ordered"]; + b1 = [communicator propertyToProxy:propertyPrefix]; + test([b1 ice_getEndpointSelection] == ICEOrdered); + [prop setProperty:property value:@""]; + + property = [propertyPrefix stringByAppendingString:@".CollocationOptimized"]; + test([b1 ice_isCollocationOptimized]); + [prop setProperty:property value:@"0"]; + b1 = [communicator propertyToProxy:propertyPrefix]; + test(![b1 ice_isCollocationOptimized]); + [prop setProperty:property value:@""]; + + tprintf("ok\n"); + + tprintf("testing proxyToProperty... "); + + b1 = [communicator stringToProxy:@"test"]; + b1 = [b1 ice_collocationOptimized:YES]; + b1 = [b1 ice_connectionCached:YES]; + b1 = [b1 ice_preferSecure:false]; + b1 = [b1 ice_endpointSelection:ICEOrdered]; + b1 = [b1 ice_locatorCacheTimeout:100]; + b1 = [b1 ice_invocationTimeout:1234]; + ICEEncodingVersion* v = [ICEEncodingVersion encodingVersion:1 minor:0]; + b1 = [b1 ice_encodingVersion:v]; + id<ICEObjectPrx> router = [communicator stringToProxy:@"router"]; + router = [router ice_collocationOptimized:false]; + router = [router ice_connectionCached:YES]; + router = [router ice_preferSecure:YES]; + router = [router ice_endpointSelection:ICERandom]; + router = [router ice_locatorCacheTimeout:200]; + router = [router ice_invocationTimeout:1500]; + + id<ICEObjectPrx> locator = [communicator stringToProxy:@"locator"]; + locator = [locator ice_collocationOptimized:YES]; + locator = [locator ice_connectionCached:false]; + locator = [locator ice_preferSecure:YES]; + locator = [locator ice_endpointSelection:ICERandom]; + locator = [locator ice_locatorCacheTimeout:300]; + locator = [locator ice_invocationTimeout:1500]; + + locator = [locator ice_router:[ICERouterPrx uncheckedCast:router]]; + b1 = [b1 ice_locator:[ICELocatorPrx uncheckedCast:locator]]; + + ICEMutablePropertyDict* proxyProps = [communicator proxyToProperty:b1 property:@"Test"]; + test([proxyProps count] == 21); + + test([[proxyProps objectForKey:@"Test"] isEqualToString:@"test -t -e 1.0"]); + test([[proxyProps objectForKey:@"Test.CollocationOptimized"] isEqualToString:@"1"]); + test([[proxyProps objectForKey:@"Test.ConnectionCached"] isEqualToString:@"1"]); + test([[proxyProps objectForKey:@"Test.PreferSecure"] isEqualToString:@"0"]); + test([[proxyProps objectForKey:@"Test.EndpointSelection"] isEqualToString:@"Ordered"]); + test([[proxyProps objectForKey:@"Test.LocatorCacheTimeout"] isEqualToString:@"100"]); + test([[proxyProps objectForKey:@"Test.InvocationTimeout"] isEqualToString:@"1234"]); + + NSString* sl = [NSString stringWithFormat:@"locator -t -e %@", [ICECurrentEncoding description]]; + test([[proxyProps objectForKey:@"Test.Locator"] isEqualToString:sl]); + test([[proxyProps objectForKey:@"Test.Locator.CollocationOptimized"] isEqualToString:@"1"]); + test([[proxyProps objectForKey:@"Test.Locator.ConnectionCached"] isEqualToString:@"0"]); + test([[proxyProps objectForKey:@"Test.Locator.PreferSecure"] isEqualToString:@"1"]); + test([[proxyProps objectForKey:@"Test.Locator.EndpointSelection"] isEqualToString:@"Random"]); + test([[proxyProps objectForKey:@"Test.Locator.LocatorCacheTimeout"] isEqualToString:@"300"]); + test([[proxyProps objectForKey:@"Test.Locator.InvocationTimeout"] isEqualToString:@"1500"]); + + NSString* sr = [NSString stringWithFormat:@"router -t -e %@", [ICECurrentEncoding description]]; + test([[proxyProps objectForKey:@"Test.Locator.Router"] isEqualToString:sr]); + test([[proxyProps objectForKey:@"Test.Locator.Router.CollocationOptimized"] isEqualToString:@"0"]); + test([[proxyProps objectForKey:@"Test.Locator.Router.ConnectionCached"] isEqualToString:@"1"]); + test([[proxyProps objectForKey:@"Test.Locator.Router.PreferSecure"] isEqualToString:@"1"]); + test([[proxyProps objectForKey:@"Test.Locator.Router.EndpointSelection"] isEqualToString:@"Random"]); + test([[proxyProps objectForKey:@"Test.Locator.Router.LocatorCacheTimeout"] isEqualToString:@"200"]); + test([[proxyProps objectForKey:@"Test.Locator.Router.InvocationTimeout"] isEqualToString:@"1500"]); + + tprintf("ok\n"); + + tprintf("testing ice_getCommunicator... "); + test([base ice_getCommunicator] == communicator); + tprintf("ok\n"); + + tprintf("testing proxy methods... "); + test([[communicator identityToString:[[base ice_identity:[communicator stringToIdentity:@"other"]] ice_getIdentity]] + isEqualToString:@"other"]); + test([[[base ice_facet:@"facet"] ice_getFacet] isEqualToString:@"facet"]); + test([[[base ice_adapterId:@"id"] ice_getAdapterId] isEqualToString:@"id"]); + test([[base ice_twoway] ice_isTwoway]); + test([[base ice_oneway] ice_isOneway]); + test([[base ice_batchOneway] ice_isBatchOneway]); + test([[base ice_datagram] ice_isDatagram]); + test([[base ice_batchDatagram] ice_isBatchDatagram]); + test([[base ice_secure:YES] ice_isSecure]); + test(![[base ice_secure:NO] ice_isSecure]); + test([[base ice_collocationOptimized:YES] ice_isCollocationOptimized]); + test(![[base ice_collocationOptimized:NO] ice_isCollocationOptimized]); + test([[base ice_preferSecure:YES] ice_isPreferSecure]); + test(![[base ice_preferSecure:NO] ice_isPreferSecure]); + + test([[[base ice_encodingVersion:ICEEncoding_1_0] ice_getEncodingVersion] isEqual:ICEEncoding_1_0]); + test([[[base ice_encodingVersion:ICEEncoding_1_1] ice_getEncodingVersion] isEqual:ICEEncoding_1_1]); + test(![[[base ice_encodingVersion:ICEEncoding_1_0] ice_getEncodingVersion] isEqual:ICEEncoding_1_1]); + + @try + { + [base ice_timeout:0]; + test(NO); + } + @catch(NSException* ex) + { + test([ex name] == NSInvalidArgumentException); + } + + @try + { + [base ice_timeout:-1]; + } + @catch(NSException* ex) + { + test(NO); + } + + @try + { + [base ice_timeout:-2]; + test(NO); + } + @catch(NSException* ex) + { + test([ex name] == NSInvalidArgumentException); + } + + @try + { + [base ice_invocationTimeout:0]; + test(NO); + } + @catch(NSException* ex) + { + test([ex name] == NSInvalidArgumentException); + } + + @try + { + [base ice_invocationTimeout:-1]; + [base ice_invocationTimeout:-2]; + } + @catch(NSException* ex) + { + test(NO); + } + + @try + { + [base ice_locatorCacheTimeout:0]; + } + @catch(NSException* ex) + { + test(NO); + } + + @try + { + [base ice_locatorCacheTimeout:-1]; + } + @catch(NSException* ex) + { + test(NO); + } + + @try + { + [base ice_locatorCacheTimeout:-2]; + test(NO); + } + @catch(NSException* ex) + { + test([ex name] == NSInvalidArgumentException); + } + + tprintf("ok\n"); + + tprintf("testing proxy comparison... "); + + test([[communicator stringToProxy:@"foo"] isEqual:[communicator stringToProxy:@"foo"]]); + test(![[communicator stringToProxy:@"foo"] isEqual:[communicator stringToProxy:@"foo2"]]); +// test([communicator stringToProxy:@"foo"]] < [communicator stringToProxy:@"foo2"]); +// test(!([communicator stringToProxy:@"foo2"]] < [communicator stringToProxy:@"foo"]); + + id<ICEObjectPrx> compObj = [communicator stringToProxy:@"foo"]; + + test([[compObj ice_facet:@"facet"] isEqual:[compObj ice_facet:@"facet"]]); + test(![[compObj ice_facet:@"facet"] isEqual:[compObj ice_facet:@"facet1"]]); +// test([compObj ice_facet:@"facet"] < [compObj ice_facet:"facet1"]); +// test(!([compObj ice_facet:@"facet"] < [compObj ice_facet:"facet"])); + + test([[compObj ice_oneway] isEqual:[compObj ice_oneway]]); + test(![[compObj ice_oneway] isEqual:[compObj ice_twoway]]); +// test([compObj ice_twoway] < [compObj ice_oneway]); +// test(!([compObj ice_oneway] < [compObj ice_twoway])); + + test([[compObj ice_secure:YES] isEqual:[compObj ice_secure:YES]]); + test(![[compObj ice_secure:NO] isEqual:[compObj ice_secure:YES]]); +// test([compObj ice_secure:NO] < [compObj ice_secure:YES]); +// test(!([compObj ice_secure:YES] < [compObj ice_secure:NO])); + + test([[compObj ice_collocationOptimized:YES] isEqual:[compObj ice_collocationOptimized:YES]]); + test(![[compObj ice_collocationOptimized:NO] isEqual:[compObj ice_collocationOptimized:YES]]); +// test([compObj ice_collocationOptimized:NO] < [compObj ice_collocationOptimized:YES]); +// test(!([compObj ice_collocationOptimized:YES] < [compObj ice_collocationOptimized:NO])); + + test([[compObj ice_connectionCached:YES] isEqual:[compObj ice_connectionCached:YES]]); + test(![[compObj ice_connectionCached:NO] isEqual:[compObj ice_connectionCached:YES]]); +// test([compObj ice_connectionCached:NO] < [compObj ice_connectionCached:YES]); +// test(!([compObj ice_connectionCached:YES] < [compObj ice_connectionCached:NO])); + + test([[compObj ice_endpointSelection:ICERandom] isEqual:[compObj ice_endpointSelection:ICERandom]]); + test(![[compObj ice_endpointSelection:ICERandom] isEqual:[compObj ice_endpointSelection:ICEOrdered]]); +// test([compObj ice_endpointSelection:ICERandom] < [compObj ice_endpointSelection:ICEOrdered]); +// test(!([compObj ice_endpointSelection:ICEOrdered] < [compObj ice_endpointSelection:ICERandom])); + +// test([[compObj ice_connectionId:@"id2"] isEqual:[compObj ice_connectionId:@"id2"]]); +// test(![[compObj ice_connectionId:@"id1"] isEqual:[compObj ice_connectionId:@"id2"]]); +// test([compObj ice_connectionId:@"id1"] < [compObj ice_connectionId:"id2"]); +// test(!([compObj ice_connectionId:@"id2"] < [compObj ice_connectionId:"id1"])); + + test([[compObj ice_compress:YES] isEqual:[compObj ice_compress:YES]]); + test(![[compObj ice_compress:NO] isEqual:[compObj ice_compress:YES]]); +// test([compObj ice_compress:NO] < [compObj ice_compress:YES]); +// test(!([compObj ice_compress:YES] < [compObj ice_compress:NO])); + + test([[compObj ice_timeout:20] isEqual:[compObj ice_timeout:20]]); + test(![[compObj ice_timeout:10] isEqual:[compObj ice_timeout:20]]); +// test([compObj ice_timeout:10] < [compObj ice_timeout:20]); +// test(!([compObj ice_timeout:20] < [compObj ice_timeout:10])); + + id<ICELocatorPrx> loc1 = [ICELocatorPrx uncheckedCast:[communicator stringToProxy:@"loc1:default -p 10000"]]; + id<ICELocatorPrx> loc2 = [ICELocatorPrx uncheckedCast:[communicator stringToProxy:@"loc2:default -p 10000"]]; + test([[compObj ice_locator:0] isEqual:[compObj ice_locator:0]]); + test([[compObj ice_locator:loc1] isEqual:[compObj ice_locator:loc1]]); + test(![[compObj ice_locator:loc1] isEqual:[compObj ice_locator:0]]); + test(![[compObj ice_locator:0] isEqual:[compObj ice_locator:loc2]]); + test(![[compObj ice_locator:loc1] isEqual:[compObj ice_locator:loc2]]); +// test([compObj ice_locator:0] < [compObj ice_locator:loc1]); +// test(!([compObj ice_locator:loc1] < [compObj ice_locator:0])); +// test([compObj ice_locator:loc1] < [compObj ice_locator:loc2]); +// test(!([compObj ice_locator:loc2] < [compObj ice_locator:loc1])); + + id<ICERouterPrx> rtr1 = [ICERouterPrx uncheckedCast:[communicator stringToProxy:@"rtr1:default -p 10000"]]; + id<ICERouterPrx> rtr2 = [ICERouterPrx uncheckedCast:[communicator stringToProxy:@"rtr2:default -p 10000"]]; + test([[compObj ice_router:0] isEqual:[compObj ice_router:0]]); + test([[compObj ice_router:rtr1] isEqual:[compObj ice_router:rtr1]]); + test(![[compObj ice_router:rtr1] isEqual:[compObj ice_router:0]]); + test(![[compObj ice_router:0] isEqual:[compObj ice_router:rtr2]]); + test(![[compObj ice_router:rtr1] isEqual:[compObj ice_router:rtr2]]); +// test([compObj ice_router:0] < [compObj ice_router:rtr1]); +// test(!([compObj ice_router:rtr1] < [compObj ice_router:0])); +// test([compObj ice_router:rtr1] < [compObj ice_router:rtr2]); +// test(!([compObj ice_router:rtr2] < [compObj ice_router:rtr1])); + + ICEMutableContext* ctx1 = [ICEMutableContext dictionary]; + [ctx1 setObject:@"v1" forKey:@"ctx1"]; + ICEMutableContext* ctx2 = [ICEMutableContext dictionary]; + [ctx2 setObject:@"v2" forKey:@"ctx2"]; + test([[compObj ice_context:nil] isEqual:[compObj ice_context:nil]]); + test([[compObj ice_context:ctx1] isEqual:[compObj ice_context:ctx1]]); + test(![[compObj ice_context:ctx1] isEqual:[compObj ice_context:nil]]); + test(![[compObj ice_context:nil] isEqual:[compObj ice_context:ctx2]]); + test(![[compObj ice_context:ctx1] isEqual:[compObj ice_context:ctx2]]); +// test([compObj ice_context:ctx1] < [compObj ice_context:ctx2]); +// test(!([compObj ice_context:ctx2] < [compObj ice_context:ctx1])); + + test([[compObj ice_preferSecure:YES] isEqual:[compObj ice_preferSecure:YES]]); + test(![[compObj ice_preferSecure:YES] isEqual:[compObj ice_preferSecure:NO]]); +// test([compObj ice_preferSecure:NO] < [compObj ice_preferSecure:YES]); +// test(!([compObj ice_preferSecure:YES] < [compObj ice_preferSecure:NO])); + + id<ICEObjectPrx> compObj1 = [communicator stringToProxy:@"foo:tcp -h 127.0.0.1 -p 10000"]; + id<ICEObjectPrx> compObj2 = [communicator stringToProxy:@"foo:tcp -h 127.0.0.1 -p 10001"]; + test(![compObj isEqual:compObj2]); +// test(compObj1 < compObj2); +// test(!(compObj2 < compObj1)); + + compObj1 = [communicator stringToProxy:@"foo@MyAdapter1"]; + compObj2 = [communicator stringToProxy:@"foo@MyAdapter2"]; + test(![compObj isEqual:compObj2]); +// test(compObj1 < compObj2); +// test(!(compObj2 < compObj1)); + + test([[compObj1 ice_locatorCacheTimeout:20] isEqual:[compObj1 ice_locatorCacheTimeout:20]]); + test(![[compObj1 ice_locatorCacheTimeout:10] isEqual:[compObj1 ice_locatorCacheTimeout:20]]); +// test([compObj1 ice_locatorCacheTimeout:10] < [compObj1 ice_locatorCacheTimeout:20]); +// test(!([compObj1 ice_locatorCacheTimeout:20] < [compObj1 ice_locatorCacheTimeout:10])); + + compObj1 = [communicator stringToProxy:@"foo:tcp -h 127.0.0.1 -p 1000"]; + compObj2 = [communicator stringToProxy:@"foo@MyAdapter1"]; + test(![compObj isEqual:compObj2]); +// test(compObj1 < compObj2); +// test(!(compObj2 < compObj1)); + + test([[compObj1 ice_encodingVersion:ICEEncoding_1_0] isEqual:[compObj1 ice_encodingVersion:ICEEncoding_1_0]]); + test(![[compObj1 ice_encodingVersion:ICEEncoding_1_0] isEqual:[compObj1 ice_encodingVersion:ICEEncoding_1_1]]); + +// test(compObj ice_encodingVersion:Ice::Encoding_1_0] < compObj->ice_encodingVersion(Ice::Encoding_1_1)); +// test(!(compObj->ice_encodingVersion(Ice::Encoding_1_1) < compObj->ice_encodingVersion(Ice::Encoding_1_0))); + // + // TODO: Ideally we should also test comparison of fixed proxies. + // + + tprintf("ok\n"); + + tprintf("testing checked cast... "); + id<TestProxyMyClassPrx> cl = [TestProxyMyClassPrx checkedCast:base]; + test(cl); + + id<TestProxyMyDerivedClassPrx> derived = [TestProxyMyDerivedClassPrx checkedCast:cl]; + test(derived); + test([cl isEqual:base]); + test([derived isEqual:base]); + test([cl isEqual:derived]); + + id<ICELocatorPrx> loc = [ICELocatorPrx checkedCast:base]; + test(loc == nil); + + // + // Upcasting + // + id<TestProxyMyClassPrx> cl2 = [TestProxyMyClassPrx checkedCast:derived]; + id<ICEObjectPrx> obj = [ICEObjectPrx checkedCast:derived]; + test(cl2); + test(obj); + test([cl2 isEqual:obj]); + test([cl2 isEqual:derived]); + + tprintf("ok\n"); + + tprintf("testing checked cast with context... "); + ICEMutableContext* c = [cl getContext]; + test([c count] == 0); + + [c setObject:@"hello" forKey:@"one"]; + [c setObject:@"world" forKey:@"two"]; + cl = [TestProxyMyClassPrx checkedCast:base context:c]; + ICEContext* c2 = [cl getContext]; + test([c isEqual:c2]); + + tprintf("ok\n"); + + tprintf("testing encoding versioning... "); + TestProxyMyClassPrx* cl20 = [TestProxyMyClassPrx uncheckedCast: + [communicator stringToProxy:@"test -e 2.0:default -p 12010"]]; + @try + { + [cl20 ice_ping]; + test(NO); + } + @catch(ICEUnsupportedEncodingException*) + { + // Server 2.0 endpoint doesn't support 1.1 version. + } + + TestProxyMyClassPrx* cl10 = [TestProxyMyClassPrx uncheckedCast: + [communicator stringToProxy:@"test -e 1.0:default -p 12010"]]; + [cl10 ice_ping]; + [[cl10 ice_encodingVersion:ICEEncoding_1_0] ice_ping]; + //cl->ice_collocationOptimized(false)->ice_encodingVersion(Ice::Encoding_1_0)->ice_ping(); + + // 1.3 isn't supported but since a 1.3 proxy supports 1.1, the + // call will use the 1.1 encoding + TestProxyMyClassPrx* cl13 = [TestProxyMyClassPrx uncheckedCast: + [communicator stringToProxy:@"test -e 1.3:default -p 12010"]]; + [cl13 ice_ping]; + [cl13 end_ice_ping:[cl13 begin_ice_ping]]; + + @try + { + // Send request with bogus 1.2 encoding. + ICEEncodingVersion* version = [ICEEncodingVersion encodingVersion:1 minor:2]; + id<ICEOutputStream> out = [ICEUtil createOutputStream:communicator]; + [out startEncapsulation]; + [out endEncapsulation]; + NSMutableData* inEncaps = [out finished]; + ((ICEByte*)[inEncaps mutableBytes])[4] = version.major; + ((ICEByte*)[inEncaps mutableBytes])[5] = version.minor; + NSMutableData* outEncaps; + [cl ice_invoke:@"ice_ping" mode:ICENormal inEncaps:inEncaps outEncaps:&outEncaps]; + test(NO); + } + @catch(ICEUnknownLocalException* ex) + { + // The server threw an UnsupportedEncodingException + test([ex.unknown rangeOfString:@"UnsupportedEncodingException"].location != NSNotFound); + } + + @try + { + // Send request with bogus 2.0 encoding. + ICEEncodingVersion* version = [ICEEncodingVersion encodingVersion:2 minor:0]; + id<ICEOutputStream> out = [ICEUtil createOutputStream:communicator]; + [out startEncapsulation]; + [out endEncapsulation]; + NSMutableData* inEncaps = [out finished]; + ((ICEByte*)[inEncaps mutableBytes])[4] = version.major; + ((ICEByte*)[inEncaps mutableBytes])[5] = version.minor; + NSMutableData* outEncaps; + [cl ice_invoke:@"ice_ping" mode:ICENormal inEncaps:inEncaps outEncaps:&outEncaps]; + test(NO); + } + @catch(ICEUnknownLocalException* ex) + { + // The server thrown an UnsupportedEncodingException + test([ex.unknown rangeOfString:@"UnsupportedEncodingException"].location != NSNotFound); + } + + tprintf("ok\n"); + + tprintf("testing protocol versioning... "); + + cl20 = [TestProxyMyClassPrx uncheckedCast:[communicator stringToProxy:@"test -p 2.0:default -p 12010"]]; + @try + { + [cl20 ice_ping]; + test(NO); + } + @catch(ICEUnsupportedProtocolException*) + { + // Server 2.0 proxy doesn't support 1.0 version. + } + + cl10 = [TestProxyMyClassPrx uncheckedCast:[communicator stringToProxy:@"test -p 1.0:default -p 12010"]]; + [cl10 ice_ping]; + + // 1.3 isn't supported but since a 1.3 proxy supports 1.0, the + // call will use the 1.0 encoding + cl13 = [TestProxyMyClassPrx uncheckedCast:[communicator stringToProxy:@"test -p 1.3:default -p 12010"]]; + [cl13 ice_ping]; + [cl13 end_ice_ping:[cl13 begin_ice_ping]]; + + tprintf("ok\n"); + + tprintf("testing opaque endpoints... "); + + @try + { + // Invalid -x option + [communicator stringToProxy:@"id:opaque -t 99 -v abc -x abc"]; + test(NO); + } + @catch(ICEEndpointParseException*) + { + } + + @try + { + // Missing -t and -v + [communicator stringToProxy:@"id:opaque"]; + test(NO); + } + @catch(ICEEndpointParseException*) + { + } + + @try + { + // Repeated -t + [communicator stringToProxy:@"id:opaque -t 1 -t 1 -v abc"]; + test(NO); + } + @catch(ICEEndpointParseException*) + { + } + + @try + { + // Repeated -v + [communicator stringToProxy:@"id:opaque -t 1 -v abc -v abc"]; + test(NO); + } + @catch(ICEEndpointParseException*) + { + } + + @try + { + // Missing -t + [communicator stringToProxy:@"id:opaque -v abc"]; + test(NO); + } + @catch(ICEEndpointParseException*) + { + } + + @try + { + // Missing -v + [communicator stringToProxy:@"id:opaque -t 1"]; + test(NO); + } + @catch(ICEEndpointParseException*) + { + } + + @try + { + // Missing arg for -t + [communicator stringToProxy:@"id:opaque -t -v abc"]; + test(NO); + } + @catch(ICEEndpointParseException*) + { + } + + @try + { + // Missing arg for -v + [communicator stringToProxy:@"id:opaque -t 1 -v"]; + test(NO); + } + @catch(ICEEndpointParseException*) + { + } + + @try + { + // Not a number for -t + [communicator stringToProxy:@"id:opaque -t x -v abc"]; + test(NO); + } + @catch(ICEEndpointParseException*) + { + } + + @try + { + // < 0 for -t + [communicator stringToProxy:@"id:opaque -t -1 -v abc"]; + test(NO); + } + @catch(ICEEndpointParseException*) + { + } + + @try + { + // Invalid char for -v + [communicator stringToProxy:@"id:opaque -t 99 -v x?c"]; + test(NO); + } + @catch(ICEEndpointParseException*) + { + } + + // Legal TCP endpoint expressed as opaque endpoint + id<ICEObjectPrx> p1 = [communicator stringToProxy:@"test -e 1.1:opaque -t 1 -v CTEyNy4wLjAuMeouAAAQJwAAAA=="]; + NSString* pstr = [communicator proxyToString:p1]; + test([pstr isEqualToString:@"test -t -e 1.1:tcp -h 127.0.0.1 -p 12010 -t 10000"]); + + if([[communicator getProperties] getPropertyAsInt:@"Ice.IPv6"] == 0) + { + // Working? + //BOOL ssl = [[[communicator getProperties] getProperty:@"Ice.Default.Protocol"] isEqualToString:@"ssl"]; + BOOL tcp = [[[communicator getProperties] getProperty:@"Ice.Default.Protocol"] isEqualToString:@"tcp"]; + if(tcp) + { + [[p1 ice_encodingVersion:ICEEncoding_1_0] ice_ping]; + } + + // Two legal TCP endpoints expressed as opaque endpoints + p1 = [communicator stringToProxy:@"test -e 1.0:opaque -t 1 -v CTEyNy4wLjAuMeouAAAQJwAAAA==:opaque -e 1.0 -t 1 -v CTEyNy4wLjAuMusuAAAQJwAAAA=="]; + pstr = [communicator proxyToString:p1]; + test([pstr isEqualToString:@"test -t -e 1.0:tcp -h 127.0.0.1 -p 12010 -t 10000:tcp -h 127.0.0.2 -p 12011 -t 10000"]); + +#if 0 // SSL is always enabled + // + // TestProxy that an SSL endpoint and a nonsense endpoint get written + // back out as an opaque endpoint. + // + p1 = [communicator stringToProxy:@"test:opaque -t 2 -v CTEyNy4wLjAuMREnAAD/////AA==:opaque -t 99 -v abch"]; + pstr = [communicator proxyToString:p1]; + if(!ssl) + { + test([pstr isEqualToString:@"test -t:opaque -t 2 -v CTEyNy4wLjAuMREnAAD/////AA==:opaque -t 99 -v abch"]); + } + else + { + test([pstr isEqualToString:@"test -t:ssl -h 127.0.0.1 -p 10001:opaque -t 99 -v abch"]); + } + + // + // Try to invoke on the SSL endpoint to verify that we get a + // NoEndpointException (or ConnectionRefusedException when + // running with SSL). + // + @try + { + [p1 ice_ping]; + test(NO); + } + @catch(ICENoEndpointException*) + { + test(!ssl); + } + @catch(ICEConnectionRefusedException*) + { + test(ssl); + } + + // + // TestProxy that the proxy with an SSL endpoint and a nonsense + // endpoint (which the server doesn't understand either) can be + // sent over the wire and returned by the server without losing + // the opaque endpoints. + // + id<ICEObjectPrx> p2 = [derived echo:p1]; + pstr = [communicator proxyToString:p2]; + if(!ssl) + { + test([pstr isEqualToString:@"test -t:opaque -t 2 -v CTEyNy4wLjAuMREnAAD/////AA==:opaque -t 99 -v abch"]); + } + else + { + test([pstr isEqualToString:@"test -t:ssl -h 127.0.0.1 -p 10001:opaque -t 99 -v abch"]); + } +#endif + } + + tprintf("ok\n"); + + return cl; +} diff --git a/objective-c/test/Ice/proxy/Client.m b/objective-c/test/Ice/proxy/Client.m new file mode 100644 index 00000000000..ad4491304e3 --- /dev/null +++ b/objective-c/test/Ice/proxy/Client.m @@ -0,0 +1,73 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <TestCommon.h> +#import <ProxyTest.h> + +static int +run(id<ICECommunicator> communicator) +{ + TestProxyMyClassPrx* proxyAllTests(id<ICECommunicator>); + TestProxyMyClassPrx* myClass = proxyAllTests(communicator); + + [myClass shutdown]; + + return EXIT_SUCCESS; +} + +#if TARGET_OS_IPHONE +# define main proxyClient +#endif + +int +main(int argc, char* argv[]) +{ + int status; + @autoreleasepool + { + id<ICECommunicator> communicator = nil; + + @try + { + ICEInitializationData* initData = [ICEInitializationData initializationData]; + initData.properties = defaultClientProperties(&argc, argv); +#if TARGET_OS_IPHONE + initData.prefixTable__ = [NSDictionary dictionaryWithObjectsAndKeys: + @"TestProxy", @"::Test", + nil]; +#endif + communicator = [ICEUtil createCommunicator:&argc argv:argv initData:initData]; + status = run(communicator); + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + @catch(TestFailedException* ex) + { + status = EXIT_FAILURE; + } + + if(communicator) + { + @try + { + [communicator destroy]; + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + } + } + return status; +} diff --git a/objective-c/test/Ice/proxy/Collocated.m b/objective-c/test/Ice/proxy/Collocated.m new file mode 100644 index 00000000000..c3dd73ba5ef --- /dev/null +++ b/objective-c/test/Ice/proxy/Collocated.m @@ -0,0 +1,74 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <proxy/TestI.h> +#import <TestCommon.h> + +static int +run(id<ICECommunicator> communicator) +{ + [[communicator getProperties] setProperty:@"TestAdapter.Endpoints" value:@"default -p 12010"]; + id<ICEObjectAdapter> adapter = [communicator createObjectAdapter:@"TestAdapter"]; + [adapter add:[TestProxyMyDerivedClassI myDerivedClass] + identity:[communicator stringToIdentity:@"test"]]; + //[adapter activate]; //adapter->activate(); // Don't activate OA to ensure collocation is used. + + TestProxyMyClassPrx* proxyAllTests(id<ICECommunicator>); + proxyAllTests(communicator); + + return EXIT_SUCCESS; +} + +#if TARGET_OS_IPHONE +# define main proxyCollocated +#endif + +int +main(int argc, char* argv[]) +{ + int status; + @autoreleasepool + { + id<ICECommunicator> communicator = nil; + + @try + { + ICEInitializationData* initData = [ICEInitializationData initializationData]; + initData.properties = defaultServerProperties(&argc, argv); + [initData.properties setProperty:@"Ice.Warn.Dispatch" value:@"0"]; +#if TARGET_OS_IPHONE + initData.prefixTable__ = [NSDictionary dictionaryWithObjectsAndKeys: + @"TestProxy", @"::Test", + nil]; +#endif + communicator = [ICEUtil createCommunicator:&argc argv:argv initData:initData]; + status = run(communicator); + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + + if(communicator) + { + @try + { + [communicator destroy]; + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + } + } + return status; +} diff --git a/objective-c/test/Ice/proxy/Makefile b/objective-c/test/Ice/proxy/Makefile new file mode 100644 index 00000000000..1ecb047ee9e --- /dev/null +++ b/objective-c/test/Ice/proxy/Makefile @@ -0,0 +1,46 @@ +# ********************************************************************** +# +# Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +# +# This copy of Ice is licensed to you under the terms described in the +# ICE_LICENSE file included in this distribution. +# +# ********************************************************************** + +top_srcdir = ../../.. + +CLIENT = client +SERVER = server +COLLOCATED = collocated + +TARGETS = $(CLIENT) $(SERVER) $(COLLOCATED) + +SLICE_OBJS = ProxyTest.o + +COBJS = Client.o \ + AllTests.o + +SOBJS = TestI.o \ + Server.o + +COLOBJS = Collocated.o \ + TestI.o \ + AllTests.o + +OBJS = $(COBJS) $(SOBJS) $(COLOBJS) $(SLICE_OBJS) + +include $(top_srcdir)/config/Make.rules + +CPPFLAGS := -I. -I.. -I../../include $(CPPFLAGS) + +$(CLIENT): $(COBJS) $(SLICE_OBJS) + rm -f $@ + $(CXX) $(LDFLAGS) $(LDEXEFLAGS) -o $@ $(COBJS) $(SLICE_OBJS) $(TEST_LIBS) + +$(SERVER): $(SOBJS) $(SLICE_OBJS) + rm -f $@ + $(CXX) $(LDFLAGS) $(LDEXEFLAGS) -o $@ $(SOBJS) $(SLICE_OBJS) $(TEST_LIBS) + +$(COLLOCATED): $(COLOBJS) $(SLICE_OBJS) + rm -f $@ + $(CXX) $(LDFLAGS) $(LDEXEFLAGS) -o $@ $(COLOBJS) $(SLICE_OBJS) $(TEST_LIBS) diff --git a/objective-c/test/Ice/proxy/ProxyTest.ice b/objective-c/test/Ice/proxy/ProxyTest.ice new file mode 100644 index 00000000000..8c8037a2beb --- /dev/null +++ b/objective-c/test/Ice/proxy/ProxyTest.ice @@ -0,0 +1,30 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#pragma once + +#include <Ice/Current.ice> + +["objc:prefix:TestProxy"] +module Test +{ + +class MyClass +{ + void shutdown(); + + Ice::Context getContext(); +}; + +class MyDerivedClass extends MyClass +{ + Object* echo(Object* obj); +}; + +}; diff --git a/objective-c/test/Ice/proxy/Server.m b/objective-c/test/Ice/proxy/Server.m new file mode 100644 index 00000000000..8a59cf702ef --- /dev/null +++ b/objective-c/test/Ice/proxy/Server.m @@ -0,0 +1,74 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <proxy/TestI.h> +#import <TestCommon.h> + +static int +run(id<ICECommunicator> communicator) +{ + [[communicator getProperties] setProperty:@"TestAdapter.Endpoints" value:@"default -p 12010:udp"]; + id<ICEObjectAdapter> adapter = [communicator createObjectAdapter:@"TestAdapter"]; + [adapter add:[TestProxyMyDerivedClassI myDerivedClass] + identity:[communicator stringToIdentity:@"test"]]; + [adapter activate]; + + serverReady(communicator); + + [communicator waitForShutdown]; + return EXIT_SUCCESS; +} + +#if TARGET_OS_IPHONE +# define main proxyServer +#endif + +int +main(int argc, char* argv[]) +{ + int status; + @autoreleasepool + { + id<ICECommunicator> communicator = nil; + + @try + { + ICEInitializationData* initData = [ICEInitializationData initializationData]; + initData.properties = defaultServerProperties(&argc, argv); + [initData.properties setProperty:@"Ice.Warn.Dispatch" value:@"0"]; +#if TARGET_OS_IPHONE + initData.prefixTable__ = [NSDictionary dictionaryWithObjectsAndKeys: + @"TestProxy", @"::Test", + nil]; +#endif + communicator = [ICEUtil createCommunicator:&argc argv:argv initData:initData]; + status = run(communicator); + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + + if(communicator) + { + @try + { + [communicator destroy]; + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + } + } + return status; +} diff --git a/objective-c/test/Ice/proxy/TestI.h b/objective-c/test/Ice/proxy/TestI.h new file mode 100644 index 00000000000..c7acd9f63f9 --- /dev/null +++ b/objective-c/test/Ice/proxy/TestI.h @@ -0,0 +1,21 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <ProxyTest.h> + +@interface TestProxyMyDerivedClassI : TestProxyMyDerivedClass<TestProxyMyDerivedClass> +{ +@private + ICEContext *_ctx; +} +-(id<ICEObjectPrx>) echo:(id<ICEObjectPrx>)proxy current:(ICECurrent*)current; +-(void) shutdown:(ICECurrent*)current; +-(ICEContext*) getContext:(ICECurrent*)current; +-(BOOL) ice_isA:(NSString*)typeId current:(ICECurrent*)current; +@end diff --git a/objective-c/test/Ice/proxy/TestI.m b/objective-c/test/Ice/proxy/TestI.m new file mode 100644 index 00000000000..b7eee6797b7 --- /dev/null +++ b/objective-c/test/Ice/proxy/TestI.m @@ -0,0 +1,45 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <proxy/TestI.h> +#import <TestCommon.h> + +@implementation TestProxyMyDerivedClassI +#if defined(__clang__) && !__has_feature(objc_arc) +-(void) dealloc +{ + [_ctx release]; + [super dealloc]; +} +#endif + +-(id<ICEObjectPrx>) echo:(id<ICEObjectPrx>)obj current:(ICECurrent*)current +{ + return obj; +} + +-(void) shutdown:(ICECurrent*)c +{ + [[[c adapter] getCommunicator] shutdown]; +} + +-(ICEContext*) getContext:(ICECurrent*)c +{ + return ICE_AUTORELEASE(ICE_RETAIN(_ctx)); +} + +-(BOOL) ice_isA:(NSString*)s current:(ICECurrent*)current +{ + ICE_RELEASE(_ctx); + _ctx = ICE_RETAIN([current ctx]); + return [super ice_isA:s current:current]; +} + +@end diff --git a/objective-c/test/Ice/proxy/run.py b/objective-c/test/Ice/proxy/run.py new file mode 100755 index 00000000000..0816938a196 --- /dev/null +++ b/objective-c/test/Ice/proxy/run.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python +# ********************************************************************** +# +# Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +# +# This copy of Ice is licensed to you under the terms described in the +# ICE_LICENSE file included in this distribution. +# +# ********************************************************************** + +import os, sys + +path = [ ".", "..", "../..", "../../..", "../../../..", "../../../../.." ] +head = os.path.dirname(sys.argv[0]) +if len(head) > 0: + path = [os.path.join(head, p) for p in path] +path = [os.path.abspath(p) for p in path if os.path.exists(os.path.join(p, "scripts", "TestUtil.py")) ] +if len(path) == 0: + raise RuntimeError("can't find toplevel directory!") +sys.path.append(os.path.join(path[0], "scripts")) +import TestUtil + +print("tests with regular server.") +TestUtil.clientServerTest() +print("tests with collocated server.") +TestUtil.collocatedTest() diff --git a/objective-c/test/Ice/retry/.gitignore b/objective-c/test/Ice/retry/.gitignore new file mode 100644 index 00000000000..5559f16dfd5 --- /dev/null +++ b/objective-c/test/Ice/retry/.gitignore @@ -0,0 +1,9 @@ +// Generated by makegitignore.py + +// IMPORTANT: Do not edit this file -- any edits made here will be lost! +client +server +collocated +.depend +RetryTest.m +RetryTest.h diff --git a/objective-c/test/Ice/retry/AllTests.m b/objective-c/test/Ice/retry/AllTests.m new file mode 100644 index 00000000000..9b70b3e6899 --- /dev/null +++ b/objective-c/test/Ice/retry/AllTests.m @@ -0,0 +1,148 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <TestCommon.h> +#import <RetryTest.h> + +#import <Foundation/Foundation.h> + +@interface TestRetryCallback : NSObject +{ + BOOL called; + NSCondition* cond; +} +-(void) check; +-(void) called; +@end + +@implementation TestRetryCallback +-(id) init +{ + self = [super init]; + if(!self) + { + return nil; + } + cond = [[NSCondition alloc] init]; + return self; +} + +#if defined(__clang__) && !__has_feature(objc_arc) +-(void) dealloc +{ + [cond release]; + [super dealloc]; +} +#endif + +-(void) check +{ + [cond lock]; + while(!called) + { + [cond wait]; + } + called = NO; + [cond unlock]; +} +-(void) called +{ + [cond lock]; + called = YES; + [cond signal]; + [cond unlock]; +} +-(void) retryOpResponse +{ + [self called]; +} +-(void) retryOpException:(ICEException*)ex +{ + test(NO); +} +-(void) killRetryOpResponse +{ + test(NO); +} + +-(void) killRetryOpException:(ICEException*)ex +{ + test([ex isKindOfClass:[ICEConnectionLostException class]] || + [ex isKindOfClass:[ICEUnknownLocalException class]]); + [self called]; +}; +@end + +id<TestRetryRetryPrx> +retryAllTests(id<ICECommunicator> communicator) +{ + tprintf("testing stringToProxy... "); + NSString* ref = @"retry:default -p 12010"; + id<ICEObjectPrx> base1 = [communicator stringToProxy:ref]; + test(base1); + id<ICEObjectPrx> base2 = [communicator stringToProxy:ref]; + test(base2); + tprintf("ok\n"); + + tprintf("testing checked cast... "); + id<TestRetryRetryPrx> retry1 = [TestRetryRetryPrx checkedCast:base1]; + test(retry1); + test([retry1 isEqual:base1]); + id<TestRetryRetryPrx> retry2 = [TestRetryRetryPrx checkedCast:base2]; + test(retry2); + test([retry2 isEqual:base2]); + tprintf("ok\n"); + + tprintf("calling regular operation with first proxy... "); + [retry1 op:NO]; + tprintf("ok\n"); + + tprintf("calling operation to kill connection with second proxy... "); + @try + { + [retry2 op:YES]; + test(NO); + } + @catch(ICEUnknownLocalException*) + { + // Expected with collocation + } + @catch(ICEConnectionLostException*) + { + } + tprintf("ok\n"); + + tprintf("calling regular operation with first proxy again... "); + [retry1 op:NO]; + tprintf("ok\n"); + + TestRetryCallback* cb1 = ICE_AUTORELEASE([[TestRetryCallback alloc] init]); + TestRetryCallback* cb2 = ICE_AUTORELEASE([[TestRetryCallback alloc] init]); + + tprintf("calling regular AMI operation with first proxy... "); + [retry1 begin_op:NO response:^{ [cb1 retryOpResponse]; } + exception:^(ICEException* ex) { [cb1 retryOpException:ex]; }]; + [cb1 check]; + tprintf("ok\n"); + + tprintf("calling AMI operation to kill connection with second proxy... "); + [retry2 begin_op:YES response:^{ [cb2 killRetryOpResponse]; } + exception:^(ICEException* ex) { [cb2 killRetryOpException:ex]; }]; + [cb2 check]; + tprintf("ok\n"); + + tprintf("calling regular AMI operation with first proxy again... "); + [retry1 begin_op:NO response:^{ [cb1 retryOpResponse]; } + exception:^(ICEException* ex) { [cb1 retryOpException:ex]; }]; + [cb1 check]; + tprintf("ok\n"); + + return retry1; +} diff --git a/objective-c/test/Ice/retry/Client.m b/objective-c/test/Ice/retry/Client.m new file mode 100644 index 00000000000..ac73829d61e --- /dev/null +++ b/objective-c/test/Ice/retry/Client.m @@ -0,0 +1,80 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <TestCommon.h> +#import <RetryTest.h> + +static int +run(id<ICECommunicator> communicator) +{ + TestRetryRetryPrx* retryAllTests(id<ICECommunicator>); + TestRetryRetryPrx* retry = retryAllTests(communicator); + [retry shutdown]; + return EXIT_SUCCESS; +} + +#if TARGET_OS_IPHONE +# define main retryClient +#endif + +int +main(int argc, char* argv[]) +{ + int status; + @autoreleasepool + { + id<ICECommunicator> communicator = nil; + + @try + { + ICEInitializationData* initData = [ICEInitializationData initializationData]; + initData.properties = defaultClientProperties(&argc, argv); + + // + // This test kills connections, so we don't want warnings. + // + [initData.properties setProperty:@"Ice.Warn.Connections" value:@"0"]; + + [initData.properties setProperty:@"Ice.RetryIntervals" value:@"0 1 10 1"]; + +#if TARGET_OS_IPHONE + initData.prefixTable__ = [NSDictionary dictionaryWithObjectsAndKeys: + @"TestRetry", @"::Test", + nil]; +#endif + + communicator = [ICEUtil createCommunicator:&argc argv:argv initData:initData]; + status = run(communicator); + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + @catch(TestFailedException* ex) + { + status = EXIT_FAILURE; + } + + if(communicator) + { + @try + { + [communicator destroy]; + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + } + } + return status; +} diff --git a/objective-c/test/Ice/retry/Collocated.m b/objective-c/test/Ice/retry/Collocated.m new file mode 100644 index 00000000000..7789017e457 --- /dev/null +++ b/objective-c/test/Ice/retry/Collocated.m @@ -0,0 +1,76 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <retry/TestI.h> +#import <TestCommon.h> + +static int +run(id<ICECommunicator> communicator) +{ + [[communicator getProperties] setProperty:@"TestAdapter.Endpoints" value:@"default -p 12010"]; + id<ICEObjectAdapter> adapter = [communicator createObjectAdapter:@"TestAdapter"]; + ICEObject* object = [TestRetryRetryI retry]; + [adapter add:object identity:[communicator stringToIdentity:@"retry"]]; + //[adapter activate]; // Don't activate OA to ensure collocation is used. + + TestRetryRetryPrx* retryAllTests(id<ICECommunicator>); + TestRetryRetryPrx* retry = retryAllTests(communicator); + [retry shutdown]; + + return EXIT_SUCCESS; +} + +#if TARGET_OS_IPHONE +# define main retryCollocated +#endif + +int +main(int argc, char* argv[]) +{ + int status; + @autoreleasepool + { + id<ICECommunicator> communicator = nil; + + @try + { + ICEInitializationData* initData = [ICEInitializationData initializationData]; + initData.properties = defaultServerProperties(&argc, argv); + [initData.properties setProperty:@"Ice.Warn.Dispatch" value:@"0"]; + [initData.properties setProperty:@"Ice.RetryIntervals" value:@"0 1 10 1"]; +#if TARGET_OS_IPHONE + initData.prefixTable__ = [NSDictionary dictionaryWithObjectsAndKeys: + @"TestRetry", @"::Test", + nil]; +#endif + communicator = [ICEUtil createCommunicator:&argc argv:argv initData:initData]; + status = run(communicator); + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + + if(communicator) + { + @try + { + [communicator destroy]; + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + } + } + return status; +} diff --git a/objective-c/test/Ice/retry/Makefile b/objective-c/test/Ice/retry/Makefile new file mode 100644 index 00000000000..f96056146bc --- /dev/null +++ b/objective-c/test/Ice/retry/Makefile @@ -0,0 +1,46 @@ +# ********************************************************************** +# +# Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +# +# This copy of Ice is licensed to you under the terms described in the +# ICE_LICENSE file included in this distribution. +# +# ********************************************************************** + +top_srcdir = ../../.. + +CLIENT = client +SERVER = server +COLLOCATED = collocated + +TARGETS = $(CLIENT) $(SERVER) $(COLLOCATED) + +SLICE_OBJS = RetryTest.o + +COBJS = Client.o \ + AllTests.o + +SOBJS = TestI.o \ + Server.o + +COLOBJS = Collocated.o \ + TestI.o \ + AllTests.o + +OBJS = $(COBJS) $(SOBJS) $(COLOBJS) $(SLICE_OBJS) + +include $(top_srcdir)/config/Make.rules + +CPPFLAGS := -I. -I.. -I../../include $(CPPFLAGS) + +$(CLIENT): $(COBJS) $(SLICE_OBJS) + rm -f $@ + $(CXX) $(LDFLAGS) $(LDEXEFLAGS) -o $@ $(COBJS) $(SLICE_OBJS) $(TEST_LIBS) + +$(SERVER): $(SOBJS) $(SLICE_OBJS) + rm -f $@ + $(CXX) $(LDFLAGS) $(LDEXEFLAGS) -o $@ $(SOBJS) $(SLICE_OBJS) $(TEST_LIBS) + +$(COLLOCATED): $(COLOBJS) $(SLICE_OBJS) + rm -f $@ + $(CXX) $(LDFLAGS) $(LDEXEFLAGS) -o $@ $(COLOBJS) $(SLICE_OBJS) $(TEST_LIBS) diff --git a/objective-c/test/Ice/retry/RetryTest.ice b/objective-c/test/Ice/retry/RetryTest.ice new file mode 100644 index 00000000000..a5f64fe05e6 --- /dev/null +++ b/objective-c/test/Ice/retry/RetryTest.ice @@ -0,0 +1,27 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#pragma once + +["objc:prefix:TestRetry"] +module Test +{ + +interface Retry +{ + void op(bool kill); + + idempotent int opIdempotent(int c); + void opNotIdempotent(); + void opSystemException(); + + idempotent void shutdown(); +}; + +}; diff --git a/objective-c/test/Ice/retry/Server.m b/objective-c/test/Ice/retry/Server.m new file mode 100644 index 00000000000..5de72255761 --- /dev/null +++ b/objective-c/test/Ice/retry/Server.m @@ -0,0 +1,74 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <retry/TestI.h> +#import <TestCommon.h> + +static int +run(id<ICECommunicator> communicator) +{ + [[communicator getProperties] setProperty:@"TestAdapter.Endpoints" value:@"default -p 12010:udp"]; + id<ICEObjectAdapter> adapter = [communicator createObjectAdapter:@"TestAdapter"]; + ICEObject* object = [TestRetryRetryI retry]; + [adapter add:object identity:[communicator stringToIdentity:@"retry"]]; + [adapter activate]; + + serverReady(communicator); + + [communicator waitForShutdown]; + return EXIT_SUCCESS; +} + +#if TARGET_OS_IPHONE +# define main retryServer +#endif + +int +main(int argc, char* argv[]) +{ + int status; + @autoreleasepool + { + id<ICECommunicator> communicator = nil; + + @try + { + ICEInitializationData* initData = [ICEInitializationData initializationData]; + initData.properties = defaultServerProperties(&argc, argv); + [initData.properties setProperty:@"Ice.Warn.Dispatch" value:@"0"]; +#if TARGET_OS_IPHONE + initData.prefixTable__ = [NSDictionary dictionaryWithObjectsAndKeys: + @"TestRetry", @"::Test", + nil]; +#endif + communicator = [ICEUtil createCommunicator:&argc argv:argv initData:initData]; + status = run(communicator); + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + + if(communicator) + { + @try + { + [communicator destroy]; + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + } + } + return status; +} diff --git a/objective-c/test/Ice/retry/TestI.h b/objective-c/test/Ice/retry/TestI.h new file mode 100644 index 00000000000..5b691a745b9 --- /dev/null +++ b/objective-c/test/Ice/retry/TestI.h @@ -0,0 +1,18 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <RetryTest.h> + +@interface TestRetryRetryI : TestRetryRetry +{ + int _counter; +} +-(void) op:(BOOL)kill current:(ICECurrent *)current; +-(void) shutdown:(ICECurrent *)current; +@end diff --git a/objective-c/test/Ice/retry/TestI.m b/objective-c/test/Ice/retry/TestI.m new file mode 100644 index 00000000000..4523c31d3eb --- /dev/null +++ b/objective-c/test/Ice/retry/TestI.m @@ -0,0 +1,67 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <retry/TestI.h> + +@implementation TestRetryRetryI +-(id) init +{ + self = [super init]; + if(!self) + { + return nil; + } + _counter = 0; + return self; +} + +-(void) op:(BOOL)kill current:(ICECurrent*)current +{ + if(kill) + { + if([current con]) + { + [[current con] close:YES]; + } + else + { + @throw [ICEConnectionLostException connectionLostException:__FILE__ line:__LINE__]; + } + } +} + +-(ICEInt) opIdempotent:(ICEInt)nRetry current:(ICECurrent*)current +{ + if(nRetry < 0) + { + _counter = 0; + return 0; + } + + if(nRetry > _counter) + { + ++_counter; + @throw [ICEConnectionLostException connectionLostException:__FILE__ line:__LINE__]; + } + int counter = _counter; + _counter = 0; + return counter; +} + +-(void) opNotIdempotent:(ICECurrent*)current +{ + @throw [ICEConnectionLostException connectionLostException:__FILE__ line:__LINE__]; +} + +-(void) shutdown:(ICECurrent*)current +{ + [[current.adapter getCommunicator] shutdown]; +} +@end diff --git a/objective-c/test/Ice/retry/run.py b/objective-c/test/Ice/retry/run.py new file mode 100755 index 00000000000..0816938a196 --- /dev/null +++ b/objective-c/test/Ice/retry/run.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python +# ********************************************************************** +# +# Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +# +# This copy of Ice is licensed to you under the terms described in the +# ICE_LICENSE file included in this distribution. +# +# ********************************************************************** + +import os, sys + +path = [ ".", "..", "../..", "../../..", "../../../..", "../../../../.." ] +head = os.path.dirname(sys.argv[0]) +if len(head) > 0: + path = [os.path.join(head, p) for p in path] +path = [os.path.abspath(p) for p in path if os.path.exists(os.path.join(p, "scripts", "TestUtil.py")) ] +if len(path) == 0: + raise RuntimeError("can't find toplevel directory!") +sys.path.append(os.path.join(path[0], "scripts")) +import TestUtil + +print("tests with regular server.") +TestUtil.clientServerTest() +print("tests with collocated server.") +TestUtil.collocatedTest() diff --git a/objective-c/test/Ice/servantLocator/.gitignore b/objective-c/test/Ice/servantLocator/.gitignore new file mode 100644 index 00000000000..1dedfd23f4d --- /dev/null +++ b/objective-c/test/Ice/servantLocator/.gitignore @@ -0,0 +1,9 @@ +// Generated by makegitignore.py + +// IMPORTANT: Do not edit this file -- any edits made here will be lost! +client +collocated +server +.depend +ServantLocatorTest.m +ServantLocatorTest.h diff --git a/objective-c/test/Ice/servantLocator/AllTests.m b/objective-c/test/Ice/servantLocator/AllTests.m new file mode 100644 index 00000000000..3cc3fca14c2 --- /dev/null +++ b/objective-c/test/Ice/servantLocator/AllTests.m @@ -0,0 +1,328 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <TestCommon.h> +#import <servantLocator/ServantLocatorTest.h> + +void +testExceptions(id<TestServantLocatorTestIntfPrx> obj) +{ + @try + { + [obj requestFailedException]; + test(NO); + } + @catch(ICEObjectNotExistException* ex) + { + test([ex.id_ isEqual:[obj ice_getIdentity]]); + test([ex.facet isEqual:[obj ice_getFacet]]); + test([ex.operation isEqual:@"requestFailedException"]); + } + @catch(id) + { + test(NO); + } + + @try + { + [obj unknownUserException]; + test(NO); + } + @catch(ICEUnknownUserException* ex) + { + test([ex.unknown isEqual:@"reason"]); + } + @catch(id) + { + test(NO); + } + + @try + { + [obj unknownLocalException]; + test(NO); + } + @catch(ICEUnknownLocalException* ex) + { + test([ex.unknown isEqual:@"reason"]); + } + @catch(id) + { + test(NO); + } + + @try + { + [obj unknownException]; + test(NO); + } + @catch(ICEUnknownException* ex) + { + test([ex.unknown isEqual:@"reason"]); + } + @catch(id) + { + test(NO); + } + + @try + { + [obj userException]; + test(NO); + } + @catch(ICEUnknownUserException* ex) + { + test([ex.unknown isEqual:@"Test::TestIntfUserException"]); + } + @catch(ICEOperationNotExistException*) + { + } + @catch(id) + { + test(NO); + } + + @try + { + [obj localException]; + test(NO); + } + @catch(ICEUnknownLocalException* ex) + { + test([ex.unknown rangeOfString:@"Ice::SocketException"].location != NSNotFound); + } + @catch(id) + { + test(NO); + } + + @try + { + [obj unknownExceptionWithServantException]; + test(NO); + } + @catch(ICEUnknownException* ex) + { + test([ex.unknown isEqual:@"reason"]); + } + @catch(id) + { + test(NO); + } + + @try + { + [obj impossibleException:NO]; + test(NO); + } + @catch(ICEUnknownUserException*) + { + // Operation doesn't throw, but locate() and finished() throw TestIntfUserException. + } + @catch(id) + { + test(NO); + } + + @try + { + [obj impossibleException:YES]; + test(NO); + } + @catch(ICEUnknownUserException*) + { + // Operation doesn't throw, but locate() and finished() throw TestIntfUserException. + } + @catch(id) + { + test(NO); + } + + @try + { + [obj intfUserException:NO]; + test(NO); + } + @catch(TestServantLocatorTestImpossibleException*) + { + // Operation doesn't throw, but locate() and finished() throw TestImpossibleException. + } + @catch(id) + { + test(NO); + } + + @try + { + [obj intfUserException:YES]; + test(NO); + } + @catch(TestServantLocatorTestImpossibleException*) + { + // Operation throws TestIntfUserException, but locate() and finished() throw TestImpossibleException. + } + @catch(id) + { + test(NO); + } +} + +TestServantLocatorTestIntfPrx* +servantLocatorAllTests(id<ICECommunicator> communicator) +{ + tprintf("testing stringToProxy... "); + NSString* sref = @"asm:default -p 12010"; + id<ICEObjectPrx> base = [communicator stringToProxy:sref]; + test(base); + tprintf("ok\n"); + + tprintf("testing checked cast... "); + id<TestServantLocatorTestIntfPrx> obj = [TestServantLocatorTestIntfPrx uncheckedCast:base]; + test(obj); + tprintf("ok\n"); + + tprintf("testing ice_ids... "); + @try + { + id<ICEObjectPrx> o = [communicator stringToProxy:@"category/locate:default -p 12010"]; + [o ice_ids]; + test(NO); + } + @catch(ICEUnknownUserException* ex) + { + test([ex.unknown isEqual:@"Test::TestIntfUserException"]); + } + @catch(id) + { + test(NO); + } + + @try + { + id<ICEObjectPrx> o = [communicator stringToProxy:@"category/finished:default -p 12010"]; + [o ice_ids]; + test(NO); + } + @catch(ICEUnknownUserException* ex) + { + test([ex.unknown isEqual:@"Test::TestIntfUserException"]); + } + @catch(id) + { + test(NO); + } + tprintf("ok\n"); + + tprintf("testing servant locator... "); + base = [communicator stringToProxy:@"category/locate:default -p 12010"]; + obj = [TestServantLocatorTestIntfPrx checkedCast:base]; + @try + { + [TestServantLocatorTestIntfPrx checkedCast:[communicator stringToProxy:@"category/unknown:default -p 12010"]]; + } + @catch(ICEObjectNotExistException*) + { + } + tprintf("ok\n"); + + tprintf("testing default servant locator... "); + base = [communicator stringToProxy:@"anothercategory/locate:default -p 12010"]; + obj = [TestServantLocatorTestIntfPrx checkedCast:base]; + base = [communicator stringToProxy:@"locate:default -p 12010"]; + obj = [TestServantLocatorTestIntfPrx checkedCast:base]; + @try + { + [TestServantLocatorTestIntfPrx checkedCast:[communicator stringToProxy:@"anothercategory/unknown:default -p 12010"]]; + } + @catch(ICEObjectNotExistException*) + { + } + @try + { + [TestServantLocatorTestIntfPrx checkedCast:[communicator stringToProxy:@"unknown:default -p 12010"]]; + } + @catch(ICEObjectNotExistException*) + { + } + tprintf("ok\n"); + + tprintf("testing locate exceptions... "); + base = [communicator stringToProxy:@"category/locate:default -p 12010"]; + obj = [TestServantLocatorTestIntfPrx checkedCast:base]; + testExceptions(obj); + tprintf("ok\n"); + + tprintf("testing finished exceptions... "); + base = [communicator stringToProxy:@"category/finished:default -p 12010"]; + obj = [TestServantLocatorTestIntfPrx checkedCast:base]; + testExceptions(obj); + + // + // Only call these for category/finished. + // + @try + { + [obj asyncResponse]; + } + @catch(TestServantLocatorTestIntfUserException*) + { + test(NO); + } + @catch(TestServantLocatorTestImpossibleException*) + { + // + // Called by finished(). + // + } + + @try + { + [obj asyncException]; + } + @catch(TestServantLocatorTestIntfUserException*) + { + test(NO); + } + @catch(TestServantLocatorTestImpossibleException*) + { + // + // Called by finished(). + // + } + tprintf("ok\n"); + + tprintf("testing servant locator removal... "); + base = [communicator stringToProxy:@"test/activation:default -p 12010"]; + id<TestServantLocatorTestActivationPrx> activation = [TestServantLocatorTestActivationPrx checkedCast:base]; + [activation activateServantLocator:NO]; + @try + { + [obj ice_ping]; + test(NO); + } + @catch(ICEObjectNotExistException*) + { + tprintf("ok\n"); + } + + tprintf("testing servant locator addition... "); + [activation activateServantLocator:YES]; + @try + { + [obj ice_ping]; + tprintf("ok\n"); + } + @catch(id) + { + test(NO); + } + + return obj; +} diff --git a/objective-c/test/Ice/servantLocator/Client.m b/objective-c/test/Ice/servantLocator/Client.m new file mode 100644 index 00000000000..fcc65bd470b --- /dev/null +++ b/objective-c/test/Ice/servantLocator/Client.m @@ -0,0 +1,70 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <TestCommon.h> +#import <ServantLocatorTest.h> + +static int +run(id<ICECommunicator> communicator) +{ + TestServantLocatorTestIntfPrx* servantLocatorAllTests(id<ICECommunicator>); + TestServantLocatorTestIntfPrx* intf = servantLocatorAllTests(communicator); + [intf shutdown]; + return EXIT_SUCCESS; +} + +#if TARGET_OS_IPHONE +# define main adminClient +#endif + +int +main(int argc, char* argv[]) +{ + int status; + @autoreleasepool + { + id<ICECommunicator> communicator = nil; + @try + { + ICEInitializationData* initData = [ICEInitializationData initializationData]; + initData.properties = defaultClientProperties(&argc, argv); +#if TARGET_OS_IPHONE + initData.prefixTable__ = [NSDictionary dictionaryWithObjectsAndKeys: + @"TestServantLocator", @"::Test", + nil]; +#endif + communicator = [ICEUtil createCommunicator:&argc argv:argv initData:initData]; + status = run(communicator); + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + @catch(TestFailedException* ex) + { + status = EXIT_FAILURE; + } + + if(communicator) + { + @try + { + [communicator destroy]; + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + } + } + return status; +} diff --git a/objective-c/test/Ice/servantLocator/Collocated.m b/objective-c/test/Ice/servantLocator/Collocated.m new file mode 100644 index 00000000000..1a3fc1d513f --- /dev/null +++ b/objective-c/test/Ice/servantLocator/Collocated.m @@ -0,0 +1,122 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <servantLocator/TestI.h> +#import <servantLocator/ServantLocatorI.h> +#import <TestCommon.h> + +@interface ServantLocatorI : TestServantLocatorI +@end + +@implementation ServantLocatorI +-(ICEObject*) newServantAndCookie:(id*)cookie +{ + *cookie = ICE_AUTORELEASE([[TestServantLocatorCookieI alloc] init]); + return [TestServantLocatorTestIntfI testIntf]; +} +-(void) checkCookie:(id)cookie +{ + test(cookie != nil); + id<TestServantLocatorCookie> co = cookie; + test([[co message] isEqual:@"blahblah"]); + +} +-(void) throwTestIntfUserException; +{ + @throw [TestServantLocatorTestIntfUserException testIntfUserException]; +} +@end + +@interface TestActivationI : TestServantLocatorTestActivation<TestServantLocatorTestActivation> +@end + +@implementation TestActivationI +-(void) activateServantLocator:(BOOL)activate current:(ICECurrent *)current +{ + if(activate) + { + [current.adapter addServantLocator:ICE_AUTORELEASE([[ServantLocatorI alloc] init:@""]) category:@""]; + [current.adapter addServantLocator:ICE_AUTORELEASE([[ServantLocatorI alloc] init:@"category"]) + category:@"category"]; + } + else + { + id<ICEServantLocator> locator = [current.adapter removeServantLocator:@""]; + [locator deactivate:@""]; + locator = [current.adapter removeServantLocator:@"category"]; + [locator deactivate:@"category"]; + } +} +@end + +static int +run(id<ICECommunicator> communicator) +{ + [[communicator getProperties] setProperty:@"TestAdapter.Endpoints" value:@"default -p 12010"]; + [[communicator getProperties] setProperty:@"Ice.Warn.Dispatch" value:@"0"]; + + id<ICEObjectAdapter> adapter = [communicator createObjectAdapter:@"TestAdapter"]; + + [adapter addServantLocator:ICE_AUTORELEASE([[ServantLocatorI alloc] init:@""]) category:@""]; + [adapter addServantLocator:ICE_AUTORELEASE([[ServantLocatorI alloc] init:@"category"]) category:@"category"]; + [adapter add:[TestServantLocatorTestIntfI testIntf] identity:[communicator stringToIdentity:@"asm"]]; + [adapter add:[TestActivationI testActivation] identity:[communicator stringToIdentity:@"test/activation"]]; + + TestServantLocatorTestIntfPrx* servantLocatorAllTests(id<ICECommunicator>); + servantLocatorAllTests(communicator); + + return EXIT_SUCCESS; +} + +#if TARGET_OS_IPHONE +# define main servantLocatorCollocated +#endif + +int +main(int argc, char* argv[]) +{ + @autoreleasepool + { + int status; + id<ICECommunicator> communicator = nil; + + @try + { + ICEInitializationData* initData = [ICEInitializationData initializationData]; + initData.properties = defaultServerProperties(&argc, argv); +#if TARGET_OS_IPHONE + initData.prefixTable__ = [NSDictionary dictionaryWithObjectsAndKeys: + @"TestServantLocator", @"::Test", + nil]; +#endif + communicator = [ICEUtil createCommunicator:&argc argv:argv initData:initData]; + status = run(communicator); + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + + if(communicator) + { + @try + { + [communicator destroy]; + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + } + return status; + } +} diff --git a/objective-c/test/Ice/servantLocator/Makefile b/objective-c/test/Ice/servantLocator/Makefile new file mode 100644 index 00000000000..0a0fdea6eed --- /dev/null +++ b/objective-c/test/Ice/servantLocator/Makefile @@ -0,0 +1,48 @@ +# ********************************************************************** +# +# Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +# +# This copy of Ice is licensed to you under the terms described in the +# ICE_LICENSE file included in this distribution. +# +# ********************************************************************** + +top_srcdir = ../../.. + +CLIENT = client +SERVER = server +COLLOCATED = collocated + +TARGETS = $(CLIENT) $(SERVER) $(COLLOCATED) + +SLICE_OBJS = ServantLocatorTest.o + +COBJS = Client.o \ + AllTests.o + +SOBJS = TestI.o \ + ServantLocatorI.o \ + Server.o + +COLOBJS = TestI.o \ + ServantLocatorI.o \ + AllTests.o \ + Collocated.o + +OBJS = $(COBJS) $(SOBJS) $(SLICE_OBJS) + +include $(top_srcdir)/config/Make.rules + +CPPFLAGS := -I. -I.. -I../../include $(CPPFLAGS) + +$(CLIENT): $(COBJS) $(SLICE_OBJS) + rm -f $@ + $(CXX) $(LDFLAGS) $(LDEXEFLAGS) -o $@ $(COBJS) $(SLICE_OBJS) $(TEST_LIBS) + +$(SERVER): $(SOBJS) $(SLICE_OBJS) + rm -f $@ + $(CXX) $(LDFLAGS) $(LDEXEFLAGS) -o $@ $(SOBJS) $(SLICE_OBJS) $(TEST_LIBS) + +$(COLLOCATED): $(COLOBJS) $(SLICE_OBJS) + rm -f $@ + $(CXX) $(LDFLAGS) $(LDEXEFLAGS) -o $@ $(COLOBJS) $(SLICE_OBJS) $(TEST_LIBS) diff --git a/objective-c/test/Ice/servantLocator/ServantLocatorI.h b/objective-c/test/Ice/servantLocator/ServantLocatorI.h new file mode 100644 index 00000000000..243d8383200 --- /dev/null +++ b/objective-c/test/Ice/servantLocator/ServantLocatorI.h @@ -0,0 +1,25 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> + +#import <Foundation/Foundation.h> + +@interface TestServantLocatorI : NSObject<ICEServantLocator> +{ + NSString* _category; + BOOL _deactivated; + int _requestId; +} +-(id) init:(NSString*)category; +-(ICEObject*) newServantAndCookie:(id*)cookie; +-(void) checkCookie:(id)cookie; +-(void) throwTestIntfUserException; +-(void) exception:(ICECurrent*)current; +@end diff --git a/objective-c/test/Ice/servantLocator/ServantLocatorI.m b/objective-c/test/Ice/servantLocator/ServantLocatorI.m new file mode 100644 index 00000000000..9835ff42626 --- /dev/null +++ b/objective-c/test/Ice/servantLocator/ServantLocatorI.m @@ -0,0 +1,148 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <servantLocator/ServantLocatorTest.h> +#import <servantLocator/ServantLocatorI.h> +#import <TestCommon.h> + +@implementation TestServantLocatorI +-(id) init:(NSString*)category +{ + self = [super init]; + if(!self) + { + return nil; + } + _category = ICE_RETAIN(category); + _deactivated = NO; + _requestId = -1; + return self; +} +#if defined(__clang__) && !__has_feature(objc_arc) +-(void) dealloc +{ + [_category release]; + [super dealloc]; +} +#endif +-(ICEObject*) locate:(ICECurrent*)current cookie:(id*)cookie +{ + test(!_deactivated); + test([current.id_.category isEqual:_category] || [_category length] == 0); + + if([current.id_.name isEqual:@"unknown"]) + { + return 0; + } + + test([current.id_.name isEqual:@"locate"] || [current.id_.name isEqual:@"finished"]); + if([current.id_.name isEqual:@"locate"]) + { + [self exception:current]; + } + + // + // Ensure locate() is only called once per request. + // + test(_requestId == -1); + _requestId = current.requestId; + + return [self newServantAndCookie:cookie]; +} +-(void) finished:(ICECurrent*)current servant:(ICEObject*)servant cookie:(id)cookie +{ + test(!_deactivated); + + // + // Ensure finished() is only called once per request. + // + test(_requestId == current.requestId); + _requestId = -1; + + test([current.id_.category isEqual:_category] || [_category length] == 0); + test([current.id_.name isEqual:@"locate"] || [current.id_.name isEqual:@"finished"]); + + if([current.id_.name isEqual:@"finished"]) + { + [self exception:current]; + } + + [self checkCookie:cookie]; +} +-(void) deactivate:(NSString*)category +{ + test(!_deactivated); + + _deactivated = YES; +} +-(ICEObject*) newServantAndCookie:(id*)cookie +{ + NSAssert(NO, @"Subclasses need to overwrite this method"); + return nil; // To keep compiler happy +} +-(void) checkCookie:(id)cookie +{ + NSAssert(NO, @"Subclasses need to overwrite this method"); +} +-(void) throwTestIntfUserException +{ + NSAssert(NO, @"Subclasses need to overwrite this method"); +} +-(void) exception:(ICECurrent*)current +{ + if([current.operation isEqual:@"ice_ids"]) + { + @throw [TestServantLocatorTestIntfUserException testIntfUserException]; + } + else if([current.operation isEqual:@"requestFailedException"]) + { + @throw [ICEObjectNotExistException objectNotExistException:__FILE__ line:__LINE__]; + } + else if([current.operation isEqual:@"unknownUserException"]) + { + @throw [ICEUnknownUserException unknownUserException:__FILE__ line:__LINE__ unknown:@"reason"]; + } + else if([current.operation isEqual:@"unknownLocalException"]) + { + @throw [ICEUnknownLocalException unknownLocalException:__FILE__ line:__LINE__ unknown:@"reason"]; + } + else if([current.operation isEqual:@"unknownException"]) + { + @throw [ICEUnknownException unknownException:__FILE__ line:__LINE__ unknown:@"reason"]; + } + else if([current.operation isEqual:@"userException"]) + { + [self throwTestIntfUserException]; + } + else if([current.operation isEqual:@"localException"]) + { + @throw [ICESocketException socketException:__FILE__ line:__LINE__ error:0]; + } + else if([current.operation isEqual:@"unknownExceptionWithServantException"]) + { + @throw [ICEUnknownException unknownException:__FILE__ line:__LINE__ unknown:@"reason"]; + } + else if([current.operation isEqual:@"impossibleException"]) + { + @throw [TestServantLocatorTestIntfUserException testIntfUserException]; // Yes, it really is meant to be TestIntfUserException. + } + else if([current.operation isEqual:@"intfUserException"]) + { + @throw [TestServantLocatorTestImpossibleException testImpossibleException]; // Yes, it really is meant to be TestImpossibleException. + } + else if([current.operation isEqual:@"asyncResponse"]) + { + @throw [TestServantLocatorTestImpossibleException testImpossibleException]; + } + else if([current.operation isEqual:@"asyncException"]) + { + @throw [TestServantLocatorTestImpossibleException testImpossibleException]; + } +} +@end diff --git a/objective-c/test/Ice/servantLocator/ServantLocatorTest.ice b/objective-c/test/Ice/servantLocator/ServantLocatorTest.ice new file mode 100644 index 00000000000..7ecd72e2dfa --- /dev/null +++ b/objective-c/test/Ice/servantLocator/ServantLocatorTest.ice @@ -0,0 +1,55 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#pragma once + +["objc:prefix:TestServantLocator"] +module Test +{ + +exception TestIntfUserException +{ +}; + +exception TestImpossibleException +{ +}; + +interface TestIntf +{ + void requestFailedException(); + void unknownUserException(); + void unknownLocalException(); + void unknownException(); + void localException(); + void userException(); + void csException(); + + void unknownExceptionWithServantException(); + + string impossibleException(bool throw) throws TestImpossibleException; + string intfUserException(bool throw) throws TestIntfUserException, TestImpossibleException; + + void asyncResponse() throws TestIntfUserException, TestImpossibleException; + void asyncException() throws TestIntfUserException, TestImpossibleException; + + void shutdown(); +}; + +local class Cookie +{ + ["cpp:const"] string message(); +}; + +interface TestActivation +{ + void activateServantLocator(bool activate); +}; + +}; diff --git a/objective-c/test/Ice/servantLocator/Server.m b/objective-c/test/Ice/servantLocator/Server.m new file mode 100644 index 00000000000..4e43663893e --- /dev/null +++ b/objective-c/test/Ice/servantLocator/Server.m @@ -0,0 +1,123 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <servantLocator/TestI.h> +#import <servantLocator/ServantLocatorI.h> +#import <TestCommon.h> + +@interface ServantLocatorI : TestServantLocatorI +@end + +@implementation ServantLocatorI +-(ICEObject*) newServantAndCookie:(id*)cookie +{ + *cookie = ICE_AUTORELEASE([[TestServantLocatorCookieI alloc] init]); + return [TestServantLocatorTestIntfI testIntf]; +} +-(void) checkCookie:(id)cookie +{ + test(cookie != nil); + id<TestServantLocatorCookie> co = cookie; + test([[co message] isEqual:@"blahblah"]); + +} +-(void) throwTestIntfUserException; +{ + @throw [TestServantLocatorTestIntfUserException testIntfUserException]; +} +@end + +@interface TestActivationI : TestServantLocatorTestActivation<TestServantLocatorTestActivation> +@end + +@implementation TestActivationI +-(void) activateServantLocator:(BOOL)activate current:(ICECurrent *)current +{ + if(activate) + { + [current.adapter addServantLocator:ICE_AUTORELEASE([[ServantLocatorI alloc] init:@""]) category:@""]; + [current.adapter addServantLocator:ICE_AUTORELEASE([[ServantLocatorI alloc] init:@"category"]) + category:@"category"]; + } + else + { + id<ICEServantLocator> locator = [current.adapter removeServantLocator:@""]; + [locator deactivate:@""]; + locator = [current.adapter removeServantLocator:@"category"]; + [locator deactivate:@"category"]; + } +} +@end + +static int +run(id<ICECommunicator> communicator) +{ + [[communicator getProperties] setProperty:@"TestAdapter.Endpoints" value:@"default -p 12010:udp"]; + [[communicator getProperties] setProperty:@"Ice.Warn.Dispatch" value:@"0"]; + + id<ICEObjectAdapter> adapter = [communicator createObjectAdapter:@"TestAdapter"]; + + [adapter addServantLocator:ICE_AUTORELEASE([[ServantLocatorI alloc] init:@""]) category:@""]; + [adapter addServantLocator:ICE_AUTORELEASE([[ServantLocatorI alloc] init:@"category"]) category:@"category"]; + [adapter add:[TestServantLocatorTestIntfI testIntf] identity:[communicator stringToIdentity:@"asm"]]; + [adapter add:[TestActivationI testActivation] identity:[communicator stringToIdentity:@"test/activation"]]; + [adapter activate]; + + serverReady(communicator); + + [adapter waitForDeactivate]; + return EXIT_SUCCESS; +} + +#if TARGET_OS_IPHONE +# define main servantLocatorServer +#endif + +int +main(int argc, char* argv[]) +{ + @autoreleasepool + { + int status; + id<ICECommunicator> communicator = nil; + + @try + { + ICEInitializationData* initData = [ICEInitializationData initializationData]; + initData.properties = defaultServerProperties(&argc, argv); +#if TARGET_OS_IPHONE + initData.prefixTable__ = [NSDictionary dictionaryWithObjectsAndKeys: + @"TestServantLocator", @"::Test", + nil]; +#endif + communicator = [ICEUtil createCommunicator:&argc argv:argv initData:initData]; + status = run(communicator); + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + + if(communicator) + { + @try + { + [communicator destroy]; + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + } + return status; + } +} diff --git a/objective-c/test/Ice/servantLocator/TestI.h b/objective-c/test/Ice/servantLocator/TestI.h new file mode 100644 index 00000000000..3253e97b5cd --- /dev/null +++ b/objective-c/test/Ice/servantLocator/TestI.h @@ -0,0 +1,18 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <ServantLocatorTest.h> + + +@interface TestServantLocatorTestIntfI : TestServantLocatorTestIntf<TestServantLocatorTestIntf> +@end + +@interface TestServantLocatorCookieI : TestServantLocatorCookie<TestServantLocatorCookie> +@end diff --git a/objective-c/test/Ice/servantLocator/TestI.m b/objective-c/test/Ice/servantLocator/TestI.m new file mode 100644 index 00000000000..db2b2081bad --- /dev/null +++ b/objective-c/test/Ice/servantLocator/TestI.m @@ -0,0 +1,84 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <servantLocator/TestI.h> + +@implementation TestServantLocatorTestIntfI +-(void) requestFailedException:(ICECurrent*)current +{ +} +-(void) unknownUserException:(ICECurrent*)current +{ +} +-(void) unknownLocalException:(ICECurrent*)current +{ +} +-(void) unknownException:(ICECurrent*)current +{ +} +-(void) userException:(ICECurrent*)current +{ +} +-(void) localException:(ICECurrent*)current +{ +} +-(void) stdException:(ICECurrent*)current +{ +} +-(void) cppException:(ICECurrent*)current +{ +} +-(void) csException:(ICECurrent*)current +{ +} +-(void) unknownExceptionWithServantException:(ICECurrent*)current +{ +} +-(NSString*) impossibleException:(BOOL)throw current:(ICECurrent*)current +{ + if(throw) + { + @throw [TestServantLocatorTestImpossibleException testImpossibleException]; + } + // + // Return a value so we can be sure that the stream position + // is reset correctly if finished() throws. + // + return @"Hello"; +} +-(NSString*) intfUserException:(BOOL)throw current:(ICECurrent*)current +{ + if(throw) + { + @throw [TestServantLocatorTestIntfUserException testIntfUserException]; + } + // + // Return a value so we can be sure that the stream position + // is reset correctly if finished() throws. + // + return @"Hello"; +} +-(void) asyncResponse:(ICECurrent*)current +{ +} +-(void) asyncException:(ICECurrent*)current +{ +} +-(void) shutdown:(ICECurrent*)current +{ + [current.adapter deactivate]; +} +@end + +@implementation TestServantLocatorCookieI +-(NSString*) message +{ + return @"blahblah"; +} +@end diff --git a/objective-c/test/Ice/servantLocator/run.py b/objective-c/test/Ice/servantLocator/run.py new file mode 100755 index 00000000000..0816938a196 --- /dev/null +++ b/objective-c/test/Ice/servantLocator/run.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python +# ********************************************************************** +# +# Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +# +# This copy of Ice is licensed to you under the terms described in the +# ICE_LICENSE file included in this distribution. +# +# ********************************************************************** + +import os, sys + +path = [ ".", "..", "../..", "../../..", "../../../..", "../../../../.." ] +head = os.path.dirname(sys.argv[0]) +if len(head) > 0: + path = [os.path.join(head, p) for p in path] +path = [os.path.abspath(p) for p in path if os.path.exists(os.path.join(p, "scripts", "TestUtil.py")) ] +if len(path) == 0: + raise RuntimeError("can't find toplevel directory!") +sys.path.append(os.path.join(path[0], "scripts")) +import TestUtil + +print("tests with regular server.") +TestUtil.clientServerTest() +print("tests with collocated server.") +TestUtil.collocatedTest() diff --git a/objective-c/test/Ice/services/.gitignore b/objective-c/test/Ice/services/.gitignore new file mode 100644 index 00000000000..67ac8b78837 --- /dev/null +++ b/objective-c/test/Ice/services/.gitignore @@ -0,0 +1,7 @@ +// Generated by makegitignore.py + +// IMPORTANT: Do not edit this file -- any edits made here will be lost! +client +.depend +ServicesTest.m +ServicesTest.h diff --git a/objective-c/test/Ice/services/AllTests.m b/objective-c/test/Ice/services/AllTests.m new file mode 100644 index 00000000000..3f895a300eb --- /dev/null +++ b/objective-c/test/Ice/services/AllTests.m @@ -0,0 +1,106 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <objc/Glacier2.h> +#import <objc/IceStorm.h> +#import <objc/IceGrid.h> +#import <TestCommon.h> +#import <ServicesTest.h> + +#import <Foundation/Foundation.h> + +@interface ClockI : TestServicesClock<TestServicesClock> +-(id) init; +-(void)tick:(NSString*)time current:(ICECurrent*)current; +@end + +@implementation ClockI +-(id) init +{ + self = [super init]; + return self; +} +-(void)tick:(NSString*)time current:(ICECurrent*)current +{ + NSLog(@"%@", time); +} +@end + +void +servicesAllTests(id<ICECommunicator> communicator) +{ + { + tprintf("testing Glacier2 stub... "); + @try + { + id<GLACIER2RouterPrx> router = [GLACIER2RouterPrx checkedCast:[communicator getDefaultRouter]]; + [router createSession:@"" password:@""]; + } + @catch(ICEException* ex) + { + test(NO); + } + tprintf("ok\n"); + } + + { + tprintf("testing IceStorm stub... "); + ICESTORMTopicManagerPrx* manager = + [ICESTORMTopicManagerPrx uncheckedCast:[communicator stringToProxy:@"test:default -p 12010"]]; + + ICESTORMQoS* qos; + ICESTORMTopicPrx* topic; + NSString* topicName = @"time"; + + id<ICEObjectAdapter> adapter = [communicator createObjectAdapterWithEndpoints:@"subscriber" endpoints:@"tcp"]; + ICEObjectPrx* subscriber = [adapter addWithUUID:[ClockI clock]]; + [adapter activate]; + + @try + { + topic = [manager retrieve:topicName]; + [topic subscribeAndGetPublisher:qos subscriber:subscriber]; + } + @catch(ICESTORMNoSuchTopic*) + { + test(NO); + } + @catch(ICESTORMAlreadySubscribed*) + { + test(NO); + } + @catch(ICELocalException*) + { + } + tprintf("ok\n"); + } + + { + tprintf("testing IceGrid stub... "); + ICEObjectPrx* base = [communicator stringToProxy:@"test:default -p 12010"]; + ICEGRIDRegistryPrx* registry = [ICEGRIDRegistryPrx uncheckedCast:base]; + ICEGRIDAdminSessionPrx* session; + ICEGRIDAdminPrx* admin; + @try + { + session = [registry createAdminSession:@"username" password:@"password"]; + test(NO); + admin = [session getAdmin]; + } + @catch(ICEGRIDPermissionDeniedException*) + { + test(NO); + } + @catch(ICELocalException*) + { + } + tprintf("ok\n"); + } +} diff --git a/objective-c/test/Ice/services/Client.m b/objective-c/test/Ice/services/Client.m new file mode 100644 index 00000000000..bff0fd9089a --- /dev/null +++ b/objective-c/test/Ice/services/Client.m @@ -0,0 +1,70 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <TestCommon.h> +#import <ServicesTest.h> + +static int +run(id<ICECommunicator> communicator) +{ + void servicesAllTests(id<ICECommunicator>); + servicesAllTests(communicator); + return EXIT_SUCCESS; +} + +#if TARGET_OS_IPHONE +# define main servicesClient +#endif + +int +main(int argc, char* argv[]) +{ + int status; + @autoreleasepool + { + id<ICECommunicator> communicator = nil; + + @try + { + ICEInitializationData* initData = [ICEInitializationData initializationData]; + initData.properties = defaultClientProperties(&argc, argv); +#if TARGET_OS_IPHONE + initData.prefixTable__ = [NSDictionary dictionaryWithObjectsAndKeys: + @"TestServices", @"::Test", + nil]; +#endif + communicator = [ICEUtil createCommunicator:&argc argv:argv initData:initData]; + status = run(communicator); + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + @catch(TestFailedException* ex) + { + status = EXIT_FAILURE; + } + + if(communicator) + { + @try + { + [communicator destroy]; + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + } + } + return status; +} diff --git a/objective-c/test/Ice/services/Makefile b/objective-c/test/Ice/services/Makefile new file mode 100644 index 00000000000..ced9094f279 --- /dev/null +++ b/objective-c/test/Ice/services/Makefile @@ -0,0 +1,30 @@ +# ********************************************************************** +# +# Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +# +# This copy of Ice is licensed to you under the terms described in the +# ICE_LICENSE file included in this distribution. +# +# ********************************************************************** + +top_srcdir = ../../.. + +CLIENT = client + +TARGETS = $(CLIENT) + +SLICE_OBJS = ServicesTest.o + +COBJS = Client.o \ + AllTests.o + +OBJS = $(COBJS) $(SLICE_OBJS) + +include $(top_srcdir)/config/Make.rules + +CPPFLAGS := -I. -I../../include $(CPPFLAGS) +LIBS := -lGlacier2ObjC$(libsuffix) -lIceStormObjC$(libsuffix) -lIceGridObjC$(libsuffix) $(TEST_LIBS) + +$(CLIENT): $(COBJS) $(SLICE_OBJS) + rm -f $@ + $(CXX) $(LDFLAGS) $(LDEXEFLAGS) -o $@ $(COBJS) $(SLICE_OBJS) $(TEST_LIBS) diff --git a/objective-c/test/Ice/services/ServicesTest.ice b/objective-c/test/Ice/services/ServicesTest.ice new file mode 100644 index 00000000000..d9b21684d59 --- /dev/null +++ b/objective-c/test/Ice/services/ServicesTest.ice @@ -0,0 +1,21 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#pragma once + +["objc:prefix:TestServices"] +module Test +{ + +interface Clock +{ + void tick(string time); +}; + +}; diff --git a/objective-c/test/Ice/services/run.py b/objective-c/test/Ice/services/run.py new file mode 100755 index 00000000000..e925f3c7010 --- /dev/null +++ b/objective-c/test/Ice/services/run.py @@ -0,0 +1,24 @@ +#!/usr/bin/env python +# ********************************************************************** +# +# Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +# +# This copy of Ice is licensed to you under the terms described in the +# ICE_LICENSE file included in this distribution. +# +# ********************************************************************** + +import os, sys + +path = [ ".", "..", "../..", "../../..", "../../../..", "../../../../.." ] +head = os.path.dirname(sys.argv[0]) +if len(head) > 0: + path = [os.path.join(head, p) for p in path] +path = [os.path.abspath(p) for p in path if os.path.exists(os.path.join(p, "scripts", "TestUtil.py")) ] +if len(path) == 0: + raise RuntimeError("can't find toplevel directory!") +sys.path.append(os.path.join(path[0], "scripts")) +import TestUtil + +client = os.path.join(os.getcwd(), "client") +TestUtil.simpleTest(client) diff --git a/objective-c/test/Ice/slicing/Makefile b/objective-c/test/Ice/slicing/Makefile new file mode 100644 index 00000000000..87f0aaf069b --- /dev/null +++ b/objective-c/test/Ice/slicing/Makefile @@ -0,0 +1,21 @@ +# ********************************************************************** +# +# Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +# +# This copy of Ice is licensed to you under the terms described in the +# ICE_LICENSE file included in this distribution. +# +# ********************************************************************** + +top_srcdir = ../../.. + +include $(top_srcdir)/config/Make.rules + +SUBDIRS = exceptions objects + +$(EVERYTHING):: + @for subdir in $(SUBDIRS); \ + do \ + echo "making $@ in $$subdir"; \ + ( cd $$subdir && $(MAKE) $@ ) || exit 1; \ + done diff --git a/objective-c/test/Ice/slicing/exceptions/.gitignore b/objective-c/test/Ice/slicing/exceptions/.gitignore new file mode 100644 index 00000000000..0962671d892 --- /dev/null +++ b/objective-c/test/Ice/slicing/exceptions/.gitignore @@ -0,0 +1,10 @@ +// Generated by makegitignore.py + +// IMPORTANT: Do not edit this file -- any edits made here will be lost! +client +server +.depend +SlicingExceptionsTestClient.m +SlicingExceptionsTestServer.m +SlicingExceptionsTestClient.h +SlicingExceptionsTestServer.h diff --git a/objective-c/test/Ice/slicing/exceptions/AllTests.m b/objective-c/test/Ice/slicing/exceptions/AllTests.m new file mode 100644 index 00000000000..84d5d1f12fa --- /dev/null +++ b/objective-c/test/Ice/slicing/exceptions/AllTests.m @@ -0,0 +1,806 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <TestCommon.h> +#import <SlicingExceptionsTestClient.h> + +#import <Foundation/Foundation.h> + +@interface RelayI : TestSlicingExceptionsClientRelay<TestSlicingExceptionsClientRelay> +@end + +@implementation RelayI + +-(void) knownPreservedAsBase:(ICECurrent*)current +{ + @throw [TestSlicingExceptionsClientKnownPreservedDerived knownPreservedDerived:@"base" + kp:@"preserved" + kpd:@"derived"]; +} + +-(void) knownPreservedAsKnownPreserved:(ICECurrent*)current +{ + @throw [TestSlicingExceptionsClientKnownPreservedDerived knownPreservedDerived:@"base" + kp:@"preserved" + kpd:@"derived"]; +} + +-(void) unknownPreservedAsBase:(ICECurrent*)current +{ + TestSlicingExceptionsClientPreserved2* ex = ICE_AUTORELEASE([TestSlicingExceptionsClientPreserved2 alloc]); + ex.b = @"base"; + ex.kp = @"preserved"; + ex.kpd = @"derived"; + ex.p1 = [TestSlicingExceptionsClientPreservedClass preservedClass:@"bc" pc:@"pc"]; + ex.p2 = ex.p1; + @throw ex; +} + +-(void) unknownPreservedAsKnownPreserved:(ICECurrent*)current +{ + TestSlicingExceptionsClientPreserved2* ex = ICE_AUTORELEASE([TestSlicingExceptionsClientPreserved2 alloc]); + ex.b = @"base"; + ex.kp = @"preserved"; + ex.kpd = @"derived"; + ex.p1 = [TestSlicingExceptionsClientPreservedClass preservedClass:@"bc" pc:@"pc"]; + ex.p2 = ex.p1; + @throw ex; +} + +@end + +@interface TestSlicingExceptionsClientCallback : NSObject +{ + BOOL called; + NSCondition* cond; +} +-(void) check; +-(void) called; +@end + +@implementation TestSlicingExceptionsClientCallback +-(id) init +{ + self = [super init]; + if(!self) + { + return nil; + } + cond = [[NSCondition alloc] init]; + return self; +} + +#if defined(__clang__) && !__has_feature(objc_arc) +-(void) dealloc +{ + [cond release]; + [super dealloc]; +} +#endif + ++(id) create +{ + return ICE_AUTORELEASE([[TestSlicingExceptionsClientCallback alloc] init]); +} + +-(void) check +{ + [cond lock]; + while(!called) + { + [cond wait]; + } + called = NO; + [cond unlock]; +} + +-(void) called +{ + [cond lock]; + called = YES; + [cond signal]; + [cond unlock]; +} + +-(void) response +{ + test(NO); +} + +-(void) baseAsBaseException:(ICEException*)exc +{ + @try + { + @throw exc; + } + @catch(TestSlicingExceptionsClientBase* b) + { + test([b.b isEqualToString:@"Base.b"]); + test([[b ice_name] isEqualToString:@"Test::Base"]); + } + @catch(...) + { + test(NO); + } + [self called]; +} + +-(void) unknownDerivedAsBaseException:(ICEException*)exc +{ + @try + { + @throw exc; + } + @catch(TestSlicingExceptionsClientBase* b) + { + test([b.b isEqualToString:@"UnknownDerived.b"]); + test([[b ice_name] isEqualToString:@"Test::Base"]); + } + @catch(...) + { + test(NO); + } + [self called]; +} + +-(void) knownDerivedException:(ICEException*)exc +{ + @try + { + @throw exc; + } + @catch(TestSlicingExceptionsClientKnownDerived* k) + { + test([k.b isEqualToString:@"KnownDerived.b"]); + test([k.kd isEqualToString:@"KnownDerived.kd"]); + test([[k ice_name] isEqualToString:@"Test::KnownDerived"]); + } + @catch(...) + { + test(NO); + } + [self called]; +} + +-(void) unknownIntermediateAsBaseException:(ICEException*)exc +{ + @try + { + @throw exc; + } + @catch(TestSlicingExceptionsClientBase* b) + { + test([b.b isEqualToString:@"UnknownIntermediate.b"]); + test([[b ice_name] isEqualToString:@"Test::Base"]); + } + @catch(...) + { + test(NO); + } + [self called]; +} + +-(void) knownIntermediateAsBaseException:(ICEException*)exc +{ + @try + { + @throw exc; + } + @catch(TestSlicingExceptionsClientKnownIntermediate* ki) + { + test([ki.b isEqualToString:@"KnownIntermediate.b"]); + test([ki.ki isEqualToString:@"KnownIntermediate.ki"]); + test([[ki ice_name] isEqualToString:@"Test::KnownIntermediate"]); + } + @catch(...) + { + test(NO); + } + [self called]; +} + +-(void) knownMostDerivedException:(ICEException*)exc +{ + @try + { + @throw exc; + } + @catch(TestSlicingExceptionsClientKnownMostDerived* kmd) + { + test([kmd.b isEqualToString:@"KnownMostDerived.b"]); + test([kmd.ki isEqualToString:@"KnownMostDerived.ki"]); + test([kmd.kmd isEqualToString:@"KnownMostDerived.kmd"]); + test([[kmd ice_name] isEqualToString:@"Test::KnownMostDerived"]); + } + @catch(...) + { + test(NO); + } + [self called]; +} + +-(void) knownIntermediateAsKnownIntermediateException:(ICEException*)exc +{ + @try + { + @throw exc; + } + @catch(TestSlicingExceptionsClientKnownIntermediate* ki) + { + test([ki.b isEqualToString:@"KnownIntermediate.b"]); + test([ki.ki isEqualToString:@"KnownIntermediate.ki"]); + test([[ki ice_name] isEqualToString:@"Test::KnownIntermediate"]); + } + @catch(...) + { + test(NO); + } + [self called]; +} + +-(void) unknownMostDerived1Exception:(ICEException*)exc +{ + @try + { + @throw exc; + } + @catch(TestSlicingExceptionsClientKnownIntermediate* ki) + { + test([ki.b isEqualToString:@"UnknownMostDerived1.b"]); + test([ki.ki isEqualToString:@"UnknownMostDerived1.ki"]); + test([[ki ice_name] isEqualToString:@"Test::KnownIntermediate"]); + } + @catch(...) + { + test(NO); + } + [self called]; +} + +-(void) unknownMostDerived2Exception:(ICEException*)exc +{ + @try + { + @throw exc; + } + @catch(TestSlicingExceptionsClientBase* b) + { + test([b.b isEqualToString:@"UnknownMostDerived2.b"]); + test([[b ice_name] isEqualToString:@"Test::Base"]); + } + @catch(...) + { + test(NO); + } + [self called]; +} +@end + +id<TestSlicingExceptionsClientTestIntfPrx> +slicingExceptionsAllTests(id<ICECommunicator> communicator) +{ + id<ICEObjectPrx> obj = [communicator stringToProxy:@"Test:default -p 12010"]; + id<TestSlicingExceptionsClientTestIntfPrx> test = [TestSlicingExceptionsClientTestIntfPrx checkedCast:obj]; + tprintf("base... "); + { + @try + { + [test baseAsBase]; + test(NO); + } + @catch(TestSlicingExceptionsClientBase* b) + { + test([b.b isEqual:@"Base.b"]); + test([[b ice_name] isEqualToString:@"Test::Base"]); + } + @catch(...) + { + test(NO); + } + } + tprintf("ok\n"); + + tprintf("base (AMI)... "); + { + TestSlicingExceptionsClientCallback *cb = [TestSlicingExceptionsClientCallback create]; + [test begin_baseAsBase:^ { test(NO); } exception:^(ICEException* e) { [cb baseAsBaseException:e]; }]; + [cb check]; + } + tprintf("ok\n"); + + tprintf("slicing of unknown derived... "); + { + @try + { + [test unknownDerivedAsBase]; + test(NO); + } + @catch(TestSlicingExceptionsClientBase* b) + { + test([b.b isEqualToString:@"UnknownDerived.b"]); + test([[b ice_name] isEqualToString:@"Test::Base"]); + } + @catch(...) + { + test(NO); + } + } + tprintf("ok\n"); + + tprintf("slicing of unknown derived (AMI)... "); + { + TestSlicingExceptionsClientCallback* cb = [TestSlicingExceptionsClientCallback create]; + [test begin_unknownDerivedAsBase:^ { test(NO); } exception:^(ICEException* e) { [cb unknownDerivedAsBaseException:e]; }]; + [cb check]; + } + tprintf("ok\n"); + + tprintf("non-slicing of known derived as base... "); + { + @try + { + [test knownDerivedAsBase]; + test(NO); + } + @catch(TestSlicingExceptionsClientKnownDerived* k) + { + test([k.b isEqualToString:@"KnownDerived.b"]); + test([k.kd isEqualToString:@"KnownDerived.kd"]); + test([[k ice_name] isEqualToString:@"Test::KnownDerived"]); + } + @catch(...) + { + test(NO); + } + } + tprintf("ok\n"); + + tprintf("non-slicing of known derived as base (AMI)... "); + { + TestSlicingExceptionsClientCallback* cb = [TestSlicingExceptionsClientCallback create]; + [test begin_knownDerivedAsBase:^ { test(NO); } exception:^(ICEException* e) { [cb knownDerivedException:e]; }]; + [cb check]; + } + tprintf("ok\n"); + + tprintf("non-slicing of known derived as derived... "); + { + @try + { + [test knownDerivedAsKnownDerived]; + test(NO); + } + @catch(TestSlicingExceptionsClientKnownDerived* k) + { + test([k.b isEqualToString:@"KnownDerived.b"]); + test([k.kd isEqualToString:@"KnownDerived.kd"]); + test([[k ice_name] isEqualToString:@"Test::KnownDerived"]); + } + @catch(...) + { + test(NO); + } + } + tprintf("ok\n"); + + tprintf("non-slicing of known derived as derived (AMI)... "); + { + TestSlicingExceptionsClientCallback* cb = [TestSlicingExceptionsClientCallback create]; + [test begin_knownDerivedAsKnownDerived:^ { test(NO); } exception:^(ICEException* e) { [cb knownDerivedException:e]; }]; + [cb check]; + } + tprintf("ok\n"); + + tprintf("slicing of unknown intermediate as base... "); + { + @try + { + [test unknownIntermediateAsBase]; + test(NO); + } + @catch(TestSlicingExceptionsClientBase* b) + { + test([b.b isEqualToString:@"UnknownIntermediate.b"]); + test([[b ice_name] isEqualToString:@"Test::Base"]); + } + @catch(...) + { + test(NO); + } + } + tprintf("ok\n"); + + tprintf("slicing of unknown intermediate as base (AMI)... "); + { + TestSlicingExceptionsClientCallback* cb = [TestSlicingExceptionsClientCallback create]; + [test begin_unknownIntermediateAsBase:^ { test(NO); } exception:^(ICEException* e) { [cb unknownIntermediateAsBaseException:e]; }]; + [cb check]; + } + tprintf("ok\n"); + + tprintf("slicing of known intermediate as base... "); + { + @try + { + [test knownIntermediateAsBase]; + test(NO); + } + @catch(TestSlicingExceptionsClientKnownIntermediate* ki) + { + test([ki.b isEqualToString:@"KnownIntermediate.b"]); + test([ki.ki isEqualToString:@"KnownIntermediate.ki"]); + test([[ki ice_name] isEqualToString:@"Test::KnownIntermediate"]); + } + @catch(...) + { + test(NO); + } + } + tprintf("ok\n"); + + tprintf("slicing of known intermediate as base (AMI)... "); + { + TestSlicingExceptionsClientCallback* cb = [TestSlicingExceptionsClientCallback create]; + [test begin_knownIntermediateAsBase:^ { test(NO); } exception:^(ICEException* e) { [cb knownIntermediateAsBaseException:e]; }]; + [cb check]; + } + tprintf("ok\n"); + + tprintf("slicing of known most derived as base... "); + { + @try + { + [test knownMostDerivedAsBase]; + test(NO); + } + @catch(TestSlicingExceptionsClientKnownMostDerived* kmd) + { + test([kmd.b isEqualToString:@"KnownMostDerived.b"]); + test([kmd.ki isEqualToString:@"KnownMostDerived.ki"]); + test([kmd.kmd isEqualToString:@"KnownMostDerived.kmd"]); + test([[kmd ice_name] isEqualToString:@"Test::KnownMostDerived"]); + } + @catch(...) + { + test(NO); + } + } + tprintf("ok\n"); + + tprintf("slicing of known most derived as base (AMI)... "); + { + TestSlicingExceptionsClientCallback* cb = [TestSlicingExceptionsClientCallback create]; + [test begin_knownMostDerivedAsBase:^ { test(NO); } exception:^(ICEException* e) { [cb knownMostDerivedException:e]; }]; + [cb check]; + } + tprintf("ok\n"); + + tprintf("non-slicing of known intermediate as intermediate... "); + { + @try + { + [test knownIntermediateAsKnownIntermediate]; + test(NO); + } + @catch(TestSlicingExceptionsClientKnownIntermediate* ki) + { + test([ki.b isEqualToString:@"KnownIntermediate.b"]); + test([ki.ki isEqualToString:@"KnownIntermediate.ki"]); + test([[ki ice_name] isEqualToString:@"Test::KnownIntermediate"]); + } + @catch(...) + { + test(NO); + } + } + tprintf("ok\n"); + + tprintf("non-slicing of known intermediate as intermediate (AMI)... "); + { + TestSlicingExceptionsClientCallback* cb = [TestSlicingExceptionsClientCallback create]; + [test begin_knownIntermediateAsKnownIntermediate:^ { test(NO); } exception:^(ICEException* e) { [cb knownIntermediateAsKnownIntermediateException:e]; }]; + [cb check]; + } + tprintf("ok\n"); + + tprintf("non-slicing of known most derived exception as intermediate... "); + { + @try + { + [test knownMostDerivedAsKnownIntermediate]; + test(NO); + } + @catch(TestSlicingExceptionsClientKnownMostDerived* kmd) + { + test([kmd.b isEqualToString:@"KnownMostDerived.b"]); + test([kmd.ki isEqualToString:@"KnownMostDerived.ki"]); + test([kmd.kmd isEqualToString:@"KnownMostDerived.kmd"]); + test([[kmd ice_name] isEqualToString:@"Test::KnownMostDerived"]); + } + @catch(...) + { + test(NO); + } + } + tprintf("ok\n"); + + tprintf("non-slicing of known most derived as intermediate (AMI)... "); + { + TestSlicingExceptionsClientCallback* cb = [TestSlicingExceptionsClientCallback create]; + [test begin_knownMostDerivedAsKnownIntermediate:^ { test(NO); } exception:^(ICEException* e) { [cb knownMostDerivedException:e]; }]; + [cb check]; + } + tprintf("ok\n"); + + tprintf("non-slicing of known most derived as most derived... "); + { + @try + { + [test knownMostDerivedAsKnownMostDerived]; + test(NO); + } + @catch(TestSlicingExceptionsClientKnownMostDerived* kmd) + { + test([kmd.b isEqualToString:@"KnownMostDerived.b"]); + test([kmd.ki isEqualToString:@"KnownMostDerived.ki"]); + test([kmd.kmd isEqualToString:@"KnownMostDerived.kmd"]); + test([[kmd ice_name] isEqualToString:@"Test::KnownMostDerived"]); + } + @catch(...) + { + test(NO); + } + } + tprintf("ok\n"); + + tprintf("non-slicing of known most derived as most derived (AMI)... "); + { + TestSlicingExceptionsClientCallback* cb = [TestSlicingExceptionsClientCallback create]; + [test begin_knownMostDerivedAsKnownMostDerived:^ { test(NO); } exception:^(ICEException* e) { [cb knownMostDerivedException:e]; }]; + [cb check]; + } + tprintf("ok\n"); + + tprintf("slicing of unknown most derived, known intermediate as base... "); + { + @try + { + [test unknownMostDerived1AsBase]; + test(NO); + } + @catch(TestSlicingExceptionsClientKnownIntermediate* ki) + { + test([ki.b isEqualToString:@"UnknownMostDerived1.b"]); + test([ki.ki isEqualToString:@"UnknownMostDerived1.ki"]); + test([[ki ice_name] isEqualToString:@"Test::KnownIntermediate"]); + } + @catch(...) + { + test(NO); + } + } + tprintf("ok\n"); + + tprintf("slicing of unknown most derived, known intermediate as base (AMI)... "); + { + TestSlicingExceptionsClientCallback* cb = [TestSlicingExceptionsClientCallback create]; + [test begin_unknownMostDerived1AsBase:^ { test(NO); } exception:^(ICEException* e) { [cb unknownMostDerived1Exception:e]; }]; + [cb check]; + } + tprintf("ok\n"); + + tprintf("slicing of unknown most derived, known intermediate as intermediate... "); + { + @try + { + [test unknownMostDerived1AsKnownIntermediate]; + test(NO); + } + @catch(TestSlicingExceptionsClientKnownIntermediate* ki) + { + test([ki.b isEqualToString:@"UnknownMostDerived1.b"]); + test([ki.ki isEqualToString:@"UnknownMostDerived1.ki"]); + test([[ki ice_name] isEqualToString:@"Test::KnownIntermediate"]); + } + @catch(...) + { + test(NO); + } + } + tprintf("ok\n"); + + tprintf("slicing of unknown most derived, known intermediate as intermediate (AMI)... "); + { + TestSlicingExceptionsClientCallback* cb = [TestSlicingExceptionsClientCallback create]; + [test begin_unknownMostDerived1AsKnownIntermediate:^ { test(NO); } exception:^(ICEException* e) { [cb unknownMostDerived1Exception:e]; }]; + [cb check]; + } + tprintf("ok\n"); + + tprintf("slicing of unknown most derived, unknown intermediate as base... "); + { + @try + { + [test unknownMostDerived2AsBase]; + test(NO); + } + @catch(TestSlicingExceptionsClientBase* b) + { + test([b.b isEqualToString:@"UnknownMostDerived2.b"]); + test([[b ice_name] isEqualToString:@"Test::Base"]); + } + @catch(...) + { + test(NO); + } + } + tprintf("ok\n"); + + tprintf("slicing of unknown most derived, unknown intermediate as base (AMI)... "); + { + TestSlicingExceptionsClientCallback* cb = [TestSlicingExceptionsClientCallback create]; + [test begin_unknownMostDerived2AsBase:^ { test(NO); } exception:^(ICEException* e) { [cb unknownMostDerived2Exception:e]; }]; + [cb check]; + } + tprintf("ok\n"); + + tprintf("unknown most derived in compact format... "); + { + @try + { + [test unknownMostDerived2AsBaseCompact]; + test(false); + } + @catch(TestSlicingExceptionsClientBase*) + { + // + // For the 1.0 encoding, the unknown exception is sliced to Base. + // + test([[test ice_getEncodingVersion] isEqual:ICEEncoding_1_0]); + } + @catch(ICEUnknownUserException*) + { + // + // An UnknownUserException is raised for the compact format because the + // most-derived type is unknown and the exception cannot be sliced. + // + test(![[test ice_getEncodingVersion] isEqual:ICEEncoding_1_0]); + } + @catch(ICEOperationNotExistException*) + { + } + @catch(...) + { + test(NO); + } + } + tprintf("ok\n"); + + tprintf("preserved exceptions... "); + { + id<ICEObjectAdapter> adapter = [communicator createObjectAdapterWithEndpoints:@"Relay" endpoints:@"default"]; + TestSlicingExceptionsClientRelayPrx* relay = + [TestSlicingExceptionsClientRelayPrx uncheckedCast:[adapter addWithUUID:[RelayI relay]]]; + [adapter activate]; + + @try + { + [test relayKnownPreservedAsBase:relay]; + test(NO); + } + @catch(TestSlicingExceptionsClientKnownPreservedDerived* ex) + { + test([ex.b isEqualToString:@"base"]); + test([ex.kp isEqualToString:@"preserved"]); + test([ex.kpd isEqualToString:@"derived"]); + } + @catch(ICEOperationNotExistException*) + { + } + @catch(NSException*) + { + test(NO); + } + + @try + { + [test relayKnownPreservedAsKnownPreserved:relay]; + test(NO); + } + @catch(TestSlicingExceptionsClientKnownPreservedDerived* ex) + { + test([ex.b isEqualToString:@"base"]); + test([ex.kp isEqualToString:@"preserved"]); + test([ex.kpd isEqualToString:@"derived"]); + } + @catch(const ICEOperationNotExistException*) + { + } + @catch(NSException*) + { + test(NO); + } + + @try + { + [test relayUnknownPreservedAsBase:relay]; + test(NO); + } + @catch(TestSlicingExceptionsClientPreserved2* ex) + { + test([ex.b isEqualToString:@"base"]); + test([ex.kp isEqualToString:@"preserved"]); + test([ex.kpd isEqualToString:@"derived"]); + test([[ex.p1 ice_id] isEqualToString:[TestSlicingExceptionsClientPreservedClass ice_staticId]]); + + test([ex.p1 isKindOfClass:[TestSlicingExceptionsClientPreservedClass class]]); + TestSlicingExceptionsClientPreservedClass* pc = (TestSlicingExceptionsClientPreservedClass*)ex.p1; + test([pc.bc isEqualToString:@"bc"]); + test([pc.pc isEqualToString:@"pc"]); + test([ex.p2 isEqual:ex.p1]); + } + @catch(ICEOperationNotExistException*) + { + } + @catch(TestSlicingExceptionsClientKnownPreservedDerived* ex) + { + // + // For the 1.0 encoding, the unknown exception is sliced to KnownPreserved. + // + test([[test ice_getEncodingVersion] isEqual:ICEEncoding_1_0]); + test([ex.b isEqualToString:@"base"]); + test([ex.kp isEqualToString:@"preserved"]); + test([ex.kpd isEqualToString:@"derived"]); + } + @catch(NSException*) + { + test(NO); + } + + @try + { + [test relayUnknownPreservedAsKnownPreserved:relay]; + test(NO); + } + @catch(ICEOperationNotExistException*) + { + } + @catch(TestSlicingExceptionsClientPreserved2* ex) + { + test([ex.b isEqualToString:@"base"]); + test([ex.kp isEqualToString:@"preserved"]); + test([ex.kpd isEqualToString:@"derived"]); + test([[ex.p1 ice_id] isEqualToString:[TestSlicingExceptionsClientPreservedClass ice_staticId]]); + test([ex.p1 isKindOfClass:[TestSlicingExceptionsClientPreservedClass class]]); + TestSlicingExceptionsClientPreservedClass* pc = (TestSlicingExceptionsClientPreservedClass*)ex.p1; + test([pc.bc isEqualToString:@"bc"]); + test([pc.pc isEqualToString:@"pc"]); + test([ex.p2 isEqual:ex.p1]); + } + @catch(TestSlicingExceptionsClientKnownPreservedDerived* ex) + { + // + // For the 1.0 encoding, the unknown exception is sliced to KnownPreserved. + // + test([[test ice_getEncodingVersion] isEqual:ICEEncoding_1_0]); + test([ex.b isEqualToString:@"base"]); + test([ex.kp isEqualToString:@"preserved"]); + test([ex.kpd isEqualToString:@"derived"]); + } + @catch(NSException*) + { + test(NO); + } + + [adapter destroy]; + } + tprintf("ok\n"); + return test; +} diff --git a/objective-c/test/Ice/slicing/exceptions/Client.m b/objective-c/test/Ice/slicing/exceptions/Client.m new file mode 100644 index 00000000000..da49e96ff3a --- /dev/null +++ b/objective-c/test/Ice/slicing/exceptions/Client.m @@ -0,0 +1,70 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <TestCommon.h> +#import <SlicingExceptionsTestClient.h> + +static int +run(id<ICECommunicator> communicator) +{ + id<TestSlicingExceptionsClientTestIntfPrx> slicingExceptionsAllTests(id<ICECommunicator>); + id<TestSlicingExceptionsClientTestIntfPrx> thrower = slicingExceptionsAllTests(communicator); + [thrower shutdown]; + return EXIT_SUCCESS; +} + +#if TARGET_OS_IPHONE +# define main slicingExceptionsClient +#endif + +int +main(int argc, char* argv[]) +{ + int status; + @autoreleasepool + { + id<ICECommunicator> communicator = nil; + @try + { + ICEInitializationData* initData = [ICEInitializationData initializationData]; + initData.properties = defaultClientProperties(&argc, argv); +#if TARGET_OS_IPHONE + initData.prefixTable__ = [NSDictionary dictionaryWithObjectsAndKeys: + @"TestSlicingExceptionsClient", @"::Test", + nil]; +#endif + communicator = [ICEUtil createCommunicator:&argc argv:argv initData:initData]; + status = run(communicator); + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + @catch(TestFailedException* ex) + { + status = EXIT_FAILURE; + } + + if(communicator) + { + @try + { + [communicator destroy]; + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + } + } + return status; +} diff --git a/objective-c/test/Ice/slicing/exceptions/Makefile b/objective-c/test/Ice/slicing/exceptions/Makefile new file mode 100644 index 00000000000..b67fcc04b3c --- /dev/null +++ b/objective-c/test/Ice/slicing/exceptions/Makefile @@ -0,0 +1,40 @@ +# ********************************************************************** +# +# Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +# +# This copy of Ice is licensed to you under the terms described in the +# ICE_LICENSE file included in this distribution. +# +# ********************************************************************** + +top_srcdir = ../../../.. + +CLIENT = client +SERVER = server + +TARGETS = $(CLIENT) $(SERVER) + +SLICE_OBJS = SlicingExceptionsTestClient.o \ + SlicingExceptionsTestServer.o + +COBJS = Client.o \ + AllTests.o \ + SlicingExceptionsTestClient.o + +SOBJS = TestI.o \ + Server.o \ + SlicingExceptionsTestServer.o + +OBJS = $(COBJS) $(SOBJS) + +include $(top_srcdir)/config/Make.rules + +CPPFLAGS := -I. -I../.. -I../../../include $(CPPFLAGS) + +$(CLIENT): $(COBJS) + rm -f $@ + $(CXX) $(LDFLAGS) $(LDEXEFLAGS) -o $@ $(COBJS) $(TEST_LIBS) + +$(SERVER): $(SOBJS) + rm -f $@ + $(CXX) $(LDFLAGS) $(LDEXEFLAGS) -o $@ $(SOBJS) $(TEST_LIBS) diff --git a/objective-c/test/Ice/slicing/exceptions/Server.m b/objective-c/test/Ice/slicing/exceptions/Server.m new file mode 100644 index 00000000000..bda4add3635 --- /dev/null +++ b/objective-c/test/Ice/slicing/exceptions/Server.m @@ -0,0 +1,74 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <slicing/exceptions/TestI.h> +#import <TestCommon.h> + +static int +run(id<ICECommunicator> communicator) +{ + [[communicator getProperties] setProperty:@"Ice.Warn.Dispatch" value:@"0"]; + [[communicator getProperties] setProperty:@"TestAdapter.Endpoints" value:@"default -p 12010"]; + id<ICEObjectAdapter> adapter = [communicator createObjectAdapter:@"TestAdapter"]; + ICEObject* object = [TestSlicingExceptionsServerI testIntf]; + [adapter add:object identity:[communicator stringToIdentity:@"Test"]]; + [adapter activate]; + + serverReady(communicator); + + [communicator waitForShutdown]; + return EXIT_SUCCESS; +} + +#if TARGET_OS_IPHONE +# define main slicingExceptionsServer +#endif + +int +main(int argc, char* argv[]) +{ + int status; + @autoreleasepool + { + id<ICECommunicator> communicator = nil; + + @try + { + ICEInitializationData* initData = [ICEInitializationData initializationData]; + initData.properties = defaultServerProperties(&argc, argv); +#if TARGET_OS_IPHONE + initData.prefixTable__ = [NSDictionary dictionaryWithObjectsAndKeys: + @"TestSlicingExceptionsServer", @"::Test", + nil]; +#endif + communicator = [ICEUtil createCommunicator:&argc argv:argv initData:initData]; + status = run(communicator); + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + + if(communicator) + { + @try + { + [communicator destroy]; + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + } + } + return status; +} diff --git a/objective-c/test/Ice/slicing/exceptions/SlicingExceptionsTestClient.ice b/objective-c/test/Ice/slicing/exceptions/SlicingExceptionsTestClient.ice new file mode 100644 index 00000000000..96b58c02114 --- /dev/null +++ b/objective-c/test/Ice/slicing/exceptions/SlicingExceptionsTestClient.ice @@ -0,0 +1,113 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#pragma once + +["objc:prefix:TestSlicingExceptionsClient"] +module Test +{ + +exception Base +{ + string b; +}; + +exception KnownDerived extends Base +{ + string kd; +}; + +exception KnownIntermediate extends Base +{ + string ki; +}; + +exception KnownMostDerived extends KnownIntermediate +{ + string kmd; +}; + +["preserve-slice"] +exception KnownPreserved extends Base +{ + string kp; +}; + +exception KnownPreservedDerived extends KnownPreserved +{ + string kpd; +}; + +["preserve-slice"] +class BaseClass +{ + string bc; +}; + +class PreservedClass extends BaseClass +{ + string pc; +}; + +exception Preserved1 extends KnownPreservedDerived +{ + BaseClass p1; +}; + +exception Preserved2 extends Preserved1 +{ + BaseClass p2; +}; + +["format:sliced"] +interface Relay +{ + void knownPreservedAsBase() throws Base; + void knownPreservedAsKnownPreserved() throws KnownPreserved; + + void unknownPreservedAsBase() throws Base; + void unknownPreservedAsKnownPreserved() throws KnownPreserved; +}; + +["format:sliced"] interface TestIntf +{ + void baseAsBase() throws Base; + void unknownDerivedAsBase() throws Base; + void knownDerivedAsBase() throws Base; + void knownDerivedAsKnownDerived() throws KnownDerived; + + void unknownIntermediateAsBase() throws Base; + void knownIntermediateAsBase() throws Base; + void knownMostDerivedAsBase() throws Base; + void knownIntermediateAsKnownIntermediate() throws KnownIntermediate; + void knownMostDerivedAsKnownIntermediate() throws KnownIntermediate; + void knownMostDerivedAsKnownMostDerived() throws KnownMostDerived; + + void unknownMostDerived1AsBase() throws Base; + void unknownMostDerived1AsKnownIntermediate() throws KnownIntermediate; + void unknownMostDerived2AsBase() throws Base; + + ["format:compact"] void unknownMostDerived2AsBaseCompact() throws Base; + + void knownPreservedAsBase() throws Base; + void knownPreservedAsKnownPreserved() throws KnownPreserved; + + void relayKnownPreservedAsBase(Relay* r) throws Base; + void relayKnownPreservedAsKnownPreserved(Relay* r) throws KnownPreserved; + + void unknownPreservedAsBase() throws Base; + void unknownPreservedAsKnownPreserved() throws KnownPreserved; + + void relayUnknownPreservedAsBase(Relay* r) throws Base; + void relayUnknownPreservedAsKnownPreserved(Relay* r) throws KnownPreserved; + + void shutdown(); +}; + +}; diff --git a/objective-c/test/Ice/slicing/exceptions/SlicingExceptionsTestServer.ice b/objective-c/test/Ice/slicing/exceptions/SlicingExceptionsTestServer.ice new file mode 100644 index 00000000000..e80aff5598f --- /dev/null +++ b/objective-c/test/Ice/slicing/exceptions/SlicingExceptionsTestServer.ice @@ -0,0 +1,134 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#pragma once + +["objc:prefix:TestSlicingExceptionsServer"] +module Test +{ + +exception Base +{ + string b; +}; + +exception KnownDerived extends Base +{ + string kd; +}; + +exception KnownIntermediate extends Base +{ + string ki; +}; + +exception KnownMostDerived extends KnownIntermediate +{ + string kmd; +}; + +["preserve-slice"] +exception KnownPreserved extends Base +{ + string kp; +}; + +exception KnownPreservedDerived extends KnownPreserved +{ + string kpd; +}; + +["preserve-slice"] +class BaseClass +{ + string bc; +}; + +["format:sliced"] +interface Relay +{ + void knownPreservedAsBase() throws Base; + void knownPreservedAsKnownPreserved() throws KnownPreserved; + + void unknownPreservedAsBase() throws Base; + void unknownPreservedAsKnownPreserved() throws KnownPreserved; +}; + +["format:sliced"] interface TestIntf +{ + void baseAsBase() throws Base; + void unknownDerivedAsBase() throws Base; + void knownDerivedAsBase() throws Base; + void knownDerivedAsKnownDerived() throws KnownDerived; + + void unknownIntermediateAsBase() throws Base; + void knownIntermediateAsBase() throws Base; + void knownMostDerivedAsBase() throws Base; + void knownIntermediateAsKnownIntermediate() throws KnownIntermediate; + void knownMostDerivedAsKnownIntermediate() throws KnownIntermediate; + void knownMostDerivedAsKnownMostDerived() throws KnownMostDerived; + + void unknownMostDerived1AsBase() throws Base; + void unknownMostDerived1AsKnownIntermediate() throws KnownIntermediate; + void unknownMostDerived2AsBase() throws Base; + + ["format:compact"] void unknownMostDerived2AsBaseCompact() throws Base; + + void knownPreservedAsBase() throws Base; + void knownPreservedAsKnownPreserved() throws KnownPreserved; + + void relayKnownPreservedAsBase(Relay* r) throws Base; + void relayKnownPreservedAsKnownPreserved(Relay* r) throws KnownPreserved; + + void unknownPreservedAsBase() throws Base; + void unknownPreservedAsKnownPreserved() throws KnownPreserved; + + void relayUnknownPreservedAsBase(Relay* r) throws Base; + void relayUnknownPreservedAsKnownPreserved(Relay* r) throws KnownPreserved; + + void shutdown(); +}; + +// Stuff present in the server, not present in the client. +exception UnknownDerived extends Base +{ + string ud; +}; + +exception UnknownIntermediate extends Base +{ + string ui; +}; + +exception UnknownMostDerived1 extends KnownIntermediate +{ + string umd1; +}; + +exception UnknownMostDerived2 extends UnknownIntermediate +{ + string umd2; +}; + +class SPreservedClass extends BaseClass +{ + string spc; +}; + +exception SPreserved1 extends KnownPreservedDerived +{ + BaseClass p1; +}; + +exception SPreserved2 extends SPreserved1 +{ + BaseClass p2; +}; + +}; diff --git a/objective-c/test/Ice/slicing/exceptions/TestI.h b/objective-c/test/Ice/slicing/exceptions/TestI.h new file mode 100644 index 00000000000..719b4db0914 --- /dev/null +++ b/objective-c/test/Ice/slicing/exceptions/TestI.h @@ -0,0 +1,13 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <SlicingExceptionsTestServer.h> + +@interface TestSlicingExceptionsServerI : TestSlicingExceptionsServerTestIntf<TestSlicingExceptionsServerTestIntf> +@end diff --git a/objective-c/test/Ice/slicing/exceptions/TestI.m b/objective-c/test/Ice/slicing/exceptions/TestI.m new file mode 100644 index 00000000000..ac7dc14380a --- /dev/null +++ b/objective-c/test/Ice/slicing/exceptions/TestI.m @@ -0,0 +1,156 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <slicing/exceptions/TestI.h> +#import <TestCommon.h> +#import <objc/Ice.h> + +@implementation TestSlicingExceptionsServerI +-(void) baseAsBase:(ICECurrent*)current +{ + @throw [TestSlicingExceptionsServerBase base:@"Base.b"]; +} + +-(void) unknownDerivedAsBase:(ICECurrent*)current +{ + @throw [TestSlicingExceptionsServerUnknownDerived unknownDerived:@"UnknownDerived.b" ud:@"UnknownDerived.ud"]; +} + +-(void) knownDerivedAsBase:(ICECurrent*)current +{ + @throw [TestSlicingExceptionsServerKnownDerived knownDerived:@"KnownDerived.b" kd:@"KnownDerived.kd"]; +} + +-(void) knownDerivedAsKnownDerived:(ICECurrent*)current +{ + @throw [TestSlicingExceptionsServerKnownDerived knownDerived:@"KnownDerived.b" kd:@"KnownDerived.kd"]; +} + +-(void) unknownIntermediateAsBase:(ICECurrent*)current +{ + @throw [TestSlicingExceptionsServerUnknownIntermediate unknownIntermediate:@"UnknownIntermediate.b" ui:@"UnknownIntermediate.ui"]; +} + +-(void) knownIntermediateAsBase:(ICECurrent*)current +{ + @throw [TestSlicingExceptionsServerKnownIntermediate knownIntermediate:@"KnownIntermediate.b" ki:@"KnownIntermediate.ki"]; +} + +-(void) knownMostDerivedAsBase:(ICECurrent*)current +{ + @throw [TestSlicingExceptionsServerKnownMostDerived knownMostDerived:@"KnownMostDerived.b" ki:@"KnownMostDerived.ki" kmd:@"KnownMostDerived.kmd"]; +} + +-(void) knownIntermediateAsKnownIntermediate:(ICECurrent*)current +{ + @throw [TestSlicingExceptionsServerKnownIntermediate knownIntermediate:@"KnownIntermediate.b" ki:@"KnownIntermediate.ki"]; +} + +-(void) knownMostDerivedAsKnownIntermediate:(ICECurrent*)current +{ + @throw [TestSlicingExceptionsServerKnownMostDerived knownMostDerived:@"KnownMostDerived.b" ki:@"KnownMostDerived.ki" kmd:@"KnownMostDerived.kmd"]; +} + +-(void) knownMostDerivedAsKnownMostDerived:(ICECurrent*)current +{ + @throw [TestSlicingExceptionsServerKnownMostDerived knownMostDerived:@"KnownMostDerived.b" ki:@"KnownMostDerived.ki" kmd:@"KnownMostDerived.kmd"]; +} + +-(void) unknownMostDerived1AsBase:(ICECurrent*)current +{ + @throw [TestSlicingExceptionsServerUnknownMostDerived1 unknownMostDerived1:@"UnknownMostDerived1.b" ki:@"UnknownMostDerived1.ki" umd1:@"UnknownMostDerived1.umd1"]; +} + +-(void) unknownMostDerived1AsKnownIntermediate:(ICECurrent*)current +{ + @throw [TestSlicingExceptionsServerUnknownMostDerived1 unknownMostDerived1:@"UnknownMostDerived1.b" + ki:@"UnknownMostDerived1.ki" + umd1:@"UnknownMostDerived1.umd1"]; +} + +-(void) unknownMostDerived2AsBase:(ICECurrent*)current +{ + @throw [TestSlicingExceptionsServerUnknownMostDerived2 unknownMostDerived2:@"UnknownMostDerived2.b" + ui:@"UnknownMostDerived2.ui" + umd2:@"UnknownMostDerived2.umd2"]; +} + +-(void) unknownMostDerived2AsBaseCompact:(ICECurrent*)current +{ + @throw [TestSlicingExceptionsServerUnknownMostDerived2 unknownMostDerived2:@"UnknownMostDerived2.b" + ui:@"UnknownMostDerived2.ui" + umd2:@"UnknownMostDerived2.umd2"]; +} + +-(void) knownPreservedAsBase:(ICECurrent*)current +{ + @throw [TestSlicingExceptionsServerKnownPreservedDerived knownPreservedDerived:@"base" + kp:@"preserved" + kpd:@"derived"]; +} + +-(void) knownPreservedAsKnownPreserved:(ICECurrent*)current +{ + @throw [TestSlicingExceptionsServerKnownPreservedDerived knownPreservedDerived:@"base" + kp:@"preserved" + kpd:@"derived"]; +} + +-(void) relayKnownPreservedAsBase:(TestSlicingExceptionsServerRelayPrx*)relay current:(ICECurrent*)current +{ + [relay knownPreservedAsBase]; + test(NO); +} + +-(void) relayKnownPreservedAsKnownPreserved:(TestSlicingExceptionsServerRelayPrx*)relay current:(ICECurrent*)current +{ + [relay knownPreservedAsKnownPreserved]; + test(NO); +} + +-(void) unknownPreservedAsBase:(ICECurrent*)current +{ + TestSlicingExceptionsServerSPreserved2* ex = [TestSlicingExceptionsServerSPreserved2 alloc]; + ex.b = @"base"; + ex.kp = @"preserved"; + ex.kpd = @"derived"; + ex.p1 = [TestSlicingExceptionsServerSPreservedClass sPreservedClass:@"bc" spc:@"spc"]; + ex.p2 = ex.p1; + @throw ex; +} + +-(void) unknownPreservedAsKnownPreserved:(ICECurrent*)current +{ + TestSlicingExceptionsServerSPreserved2* ex = [TestSlicingExceptionsServerSPreserved2 alloc]; + ex.b = @"base"; + ex.kp = @"preserved"; + ex.kpd = @"derived"; + ex.p1 = [TestSlicingExceptionsServerSPreservedClass sPreservedClass:@"bc" spc:@"spc"]; + ex.p2 = ex.p1; + @throw ex; +} + +-(void) relayUnknownPreservedAsBase:(TestSlicingExceptionsServerRelayPrx*)relay current:(ICECurrent*)current +{ + [relay unknownPreservedAsBase]; + test(NO); +} + +-(void) relayUnknownPreservedAsKnownPreserved:(TestSlicingExceptionsServerRelayPrx*)relay current:(ICECurrent*)current +{ + [relay unknownPreservedAsKnownPreserved]; + test(NO); +} + + +-(void) shutdown:(ICECurrent*)current +{ + [[current.adapter getCommunicator] shutdown]; +} +@end diff --git a/objective-c/test/Ice/slicing/exceptions/run.py b/objective-c/test/Ice/slicing/exceptions/run.py new file mode 100755 index 00000000000..15c789db2b5 --- /dev/null +++ b/objective-c/test/Ice/slicing/exceptions/run.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python +# ********************************************************************** +# +# Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +# +# This copy of Ice is licensed to you under the terms described in the +# ICE_LICENSE file included in this distribution. +# +# ********************************************************************** + +import os, sys + +path = [ ".", "..", "../..", "../../..", "../../../..", "../../../../..", "../../../../../.." ] +head = os.path.dirname(sys.argv[0]) +if len(head) > 0: + path = [os.path.join(head, p) for p in path] +path = [os.path.abspath(p) for p in path if os.path.exists(os.path.join(p, "scripts", "TestUtil.py")) ] +if len(path) == 0: + raise RuntimeError("can't find toplevel directory!") +sys.path.append(os.path.join(path[0], "scripts")) +import TestUtil + +print("Running test with sliced format.") +TestUtil.clientServerTest() + +print("Running test with 1.0 encoding.") +TestUtil.clientServerTest(additionalClientOptions="--Ice.Default.EncodingVersion=1.0", + additionalServerOptions="--Ice.Default.EncodingVersion=1.0") diff --git a/objective-c/test/Ice/slicing/objects/.gitignore b/objective-c/test/Ice/slicing/objects/.gitignore new file mode 100644 index 00000000000..a2c2a1c0974 --- /dev/null +++ b/objective-c/test/Ice/slicing/objects/.gitignore @@ -0,0 +1,14 @@ +// Generated by makegitignore.py + +// IMPORTANT: Do not edit this file -- any edits made here will be lost! +client +server +.depend +SlicingObjectsTestClient.m +SlicingObjectsForwardClient.m +SlicingObjectsTestServer.m +SlicingObjectsForwardServer.m +SlicingObjectsTestClient.h +SlicingObjectsForwardClient.h +SlicingObjectsTestServer.h +SlicingObjectsForwardServer.h diff --git a/objective-c/test/Ice/slicing/objects/AllTests.m b/objective-c/test/Ice/slicing/objects/AllTests.m new file mode 100644 index 00000000000..979c9f11e73 --- /dev/null +++ b/objective-c/test/Ice/slicing/objects/AllTests.m @@ -0,0 +1,2228 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <TestCommon.h> +#import <SlicingObjectsTestClient.h> +#import <SlicingObjectsForwardClient.h> + +#import <Foundation/Foundation.h> + +@interface TestSlicingObjectsClientCallback : NSObject +{ + BOOL called; + NSCondition* cond; +@public + id r; + id bout; +} +@property(nonatomic, retain) id r; +@property(nonatomic, retain) id bout; +-(void) check; +-(void) called; +@end + +@implementation TestSlicingObjectsClientCallback +@synthesize r; +@synthesize bout; +-(id) init +{ + if(![super init]) + { + return nil; + } + cond = [[NSCondition alloc] init]; + return self; +} + ++(id) create +{ + return ICE_AUTORELEASE([[TestSlicingObjectsClientCallback alloc] init]); +} + +#if defined(__clang__) && !__has_feature(objc_arc) +-(void) dealloc +{ + [cond release]; + [super dealloc]; +} +#endif + +-(void) check +{ + [cond lock]; + while(!called) + { + [cond wait]; + } + called = NO; + [cond unlock]; +} +-(void) called +{ + [cond lock]; + called = YES; + [cond signal]; + [cond unlock]; +} +-(void) SBaseAsObjectResponse:(ICEObject*)o +{ + test(o); + test([[o ice_id:nil] isEqualToString:@"::Test::SBase"]); + test([o isKindOfClass:[TestSlicingObjectsClientSBase class]]); + TestSlicingObjectsClientSBase* sb = (TestSlicingObjectsClientSBase*)o; + test([sb.sb isEqualToString:@"SBase.sb"]); + [self called]; +} + +-(void) SBaseAsObjectException:(ICEException*)exc +{ + test(NO); +} + +-(void) SBaseAsSBaseResponse:(TestSlicingObjectsClientSBase*)sb +{ + test([sb.sb isEqualToString:@"SBase.sb"]); + [self called]; +} + +-(void) SBaseAsSBaseException:(ICEException*)exc +{ + test(NO); +} + +-(void) SBSKnownDerivedAsSBaseResponse:(TestSlicingObjectsClientSBase*)sb +{ + test([sb isKindOfClass:[TestSlicingObjectsClientSBSKnownDerived class]]); + TestSlicingObjectsClientSBSKnownDerived* sbskd = (TestSlicingObjectsClientSBSKnownDerived*)sb; + test([sbskd.sbskd isEqualToString:@"SBSKnownDerived.sbskd"]); + [self called]; +} + +-(void) SBSKnownDerivedAsSBaseException:(ICEException*)exc +{ + test(NO); +} + +-(void) SBSKnownDerivedAsSBSKnownDerivedResponse:(TestSlicingObjectsClientSBSKnownDerived*)sbskd +{ + test([sbskd.sbskd isEqualToString:@"SBSKnownDerived.sbskd"]); + [self called]; +} + +-(void) SBSKnownDerivedAsSBSKnownDerivedException:(ICEException*)exc +{ + test(NO); +} + +-(void) SBSUnknownDerivedAsSBaseResponse:(TestSlicingObjectsClientSBase*)sb +{ + test([sb.sb isEqualToString:@"SBSUnknownDerived.sb"]); + [self called]; +} + +-(void) SBSUnknownDerivedAsSBaseException:(ICEException*)exc +{ + test(NO); +} + +-(void) SBSUnknownDerivedAsSBaseCompactResponse:(TestSlicingObjectsClientSBase*)sb +{ + test(NO); +} + +-(void) SBSUnknownDerivedAsSBaseCompactException:(ICEException*)exc +{ + test([[exc ice_name] isEqualToString:@"Ice::NoObjectFactoryException"]); + [self called]; +} + +-(void) SUnknownAsObjectResponse10:(ICEObject*)o +{ + test(NO); +} + +-(void) SUnknownAsObjectException10:(ICEException*)exc +{ + test([[exc ice_name] isEqualToString:@"Ice::NoObjectFactoryException"]); + [self called]; +} + +-(void) SUnknownAsObjectResponse11:(ICEObject*)o +{ + [self called]; +} + +-(void) SUnknownAsObjectException11:(ICEException*)exc +{ + test(NO); +} + +-(void) oneElementCycleResponse:(TestSlicingObjectsClientB*)b +{ + test(b); + test([[b ice_id:nil] isEqualToString:@"::Test::B"]); + test([b.sb isEqualToString:@"B1.sb"]); + test(b.pb == b); + [self called]; +} + +-(void) oneElementCycleException:(ICEException*)exc +{ + test(NO); +} + +-(void) twoElementCycleResponse:(TestSlicingObjectsClientB*)b1 +{ + test(b1); + test([[b1 ice_id:nil] isEqualToString:@"::Test::B"]); + test([b1.sb isEqualToString:@"B1.sb"]); + + TestSlicingObjectsClientB* b2 = b1.pb; + test(b2); + test([[b2 ice_id:nil] isEqualToString:@"::Test::B"]); + test([b2.sb isEqualToString:@"B2.sb"]); + test(b2.pb == b1); + [self called]; +} + +-(void) twoElementCycleException:(ICEException*)exc +{ + test(NO); +} + +-(void) D1AsBResponse:(TestSlicingObjectsClientB*)b1 +{ + test(b1); + test([[b1 ice_id:nil] isEqualToString:@"::Test::D1"]); + test([b1.sb isEqualToString:@"D1.sb"]); + test(b1.pb); + test(b1.pb != b1); + test([b1 isKindOfClass:[TestSlicingObjectsClientD1 class]]); + TestSlicingObjectsClientD1* d1 = (TestSlicingObjectsClientD1*)b1; + test([d1.sd1 isEqualToString:@"D1.sd1"]); + test(d1.pd1); + test(d1.pd1 != b1); + test(b1.pb == d1.pd1); + + TestSlicingObjectsClientB* b2 = b1.pb; + test(b2); + test(b2.pb == b1); + test([b2.sb isEqualToString:@"D2.sb"]); + test([[b2 ice_id:nil] isEqualToString:@"::Test::B"]); + [self called]; +} + +-(void) D1AsBException:(ICEException*)exc +{ + test(NO); +} + +-(void) D1AsD1Response:(TestSlicingObjectsClientD1*)d1 +{ + test(d1); + test([[d1 ice_id:nil] isEqualToString:@"::Test::D1"]); + test([d1.sb isEqualToString:@"D1.sb"]); + test(d1.pb); + test(d1.pb != d1); + + TestSlicingObjectsClientB* b2 = d1.pb; + test(b2); + test([[b2 ice_id:nil] isEqualToString:@"::Test::B"]); + test([b2.sb isEqualToString:@"D2.sb"]); + test(b2.pb == d1); + [self called]; +} + +-(void) D1AsD1Exception:(ICEException*)exc +{ + test(NO); +} + +-(void) D2AsBResponse:(TestSlicingObjectsClientB*)b2 +{ + test(b2); + test([[b2 ice_id:nil] isEqualToString:@"::Test::B"]); + test([b2.sb isEqualToString:@"D2.sb"]); + test(b2.pb); + test(b2.pb != b2); + + TestSlicingObjectsClientB* b1 = b2.pb; + test(b1); + test([[b1 ice_id:nil] isEqualToString:@"::Test::D1"]); + test([b1.sb isEqualToString:@"D1.sb"]); + test(b1.pb == b2); + test([b1 isKindOfClass:[TestSlicingObjectsClientD1 class]]); + TestSlicingObjectsClientD1* d1 = (TestSlicingObjectsClientD1*)b1; + test([d1.sd1 isEqualToString:@"D1.sd1"]); + test(d1.pd1 == b2); + [self called]; +} + +-(void) D2AsBException:(ICEException*)exc +{ + test(NO); +} + +-(void) paramTest1Response:(TestSlicingObjectsClientB*)b1 p2:(TestSlicingObjectsClientB*)b2 +{ + test(b1); + test([[b1 ice_id:nil] isEqualToString:@"::Test::D1"]); + test([b1.sb isEqualToString:@"D1.sb"]); + test(b1.pb == b2); + test([b1 isKindOfClass:[TestSlicingObjectsClientD1 class]]); + TestSlicingObjectsClientD1* d1 = (TestSlicingObjectsClientD1*)b1; + test([d1.sd1 isEqualToString:@"D1.sd1"]); + test(d1.pd1 == b2); + + test(b2); + test([[b2 ice_id:nil] isEqualToString:@"::Test::B"]); // No factory, must be sliced + test([b2.sb isEqualToString:@"D2.sb"]); + test(b2.pb == b1); + [self called]; +} + +-(void) paramTest1Exception:(ICEException*)exc +{ + test(NO); +} + +-(void) returnTest1Response:(TestSlicingObjectsClientB*)r_ p1:(TestSlicingObjectsClientB*)p1 p2:(TestSlicingObjectsClientB*)p2 +{ + test(r_ == p1); + [self called]; +} + +-(void) returnTest1Exception:(ICEException*)exc +{ + test(NO); +} + +-(void) returnTest2Response:(TestSlicingObjectsClientB*)r_ p1:(TestSlicingObjectsClientB*)p1 p2:(TestSlicingObjectsClientB*)p2 +{ + test(r_ == p1); + [self called]; +} + +-(void) returnTest2Exception:(ICEException*)exc +{ + test(NO); +} + +-(void) returnTest3Response:(TestSlicingObjectsClientB*)b +{ + self.r = b; + [self called]; +} + +-(void) returnTest3Exception:(ICEException*)exc +{ + test(NO); +} + +-(void) paramTest3Response:(TestSlicingObjectsClientB*)ret p1:(TestSlicingObjectsClientB*)p1 p2:(TestSlicingObjectsClientB*)p2 +{ + test(p1); + test([p1.sb isEqualToString:@"D2.sb (p1 1)"]); + test(p1.pb == 0); + test([[p1 ice_id:nil] isEqualToString:@"::Test::B"]); + + test(p2); + test([p2.sb isEqualToString:@"D2.sb (p2 1)"]); + test(p2.pb == 0); + test([[p2 ice_id:nil] isEqualToString:@"::Test::B"]); + + test(ret); + test([ret.sb isEqualToString:@"D1.sb (p2 2)"]); + test(ret.pb == 0); + test([[ret ice_id:nil] isEqualToString:@"::Test::D1"]); + [self called]; +} + +-(void) paramTest3Exception:(ICEException*)exc +{ + test(NO); +} + +-(void) paramTest4Response:(TestSlicingObjectsClientB*)ret p1:(TestSlicingObjectsClientB*)b +{ + test(b); + test([b.sb isEqualToString:@"D4.sb (1)"]); + test(b.pb == 0); + test([[b ice_id:nil] isEqualToString:@"::Test::B"]); + + test(ret); + test([ret.sb isEqualToString:@"B.sb (2)"]); + test(ret.pb == 0); + test([[ret ice_id:nil] isEqualToString:@"::Test::B"]); + [self called]; +} + +-(void) paramTest4Exception:(ICEException*)exc +{ + test(NO); +} + +-(void) sequenceTestResponse:(TestSlicingObjectsClientSS*)ss +{ + self.r = ss; + [self called]; +} + +-(void) sequenceTestException:(ICEException*)exc +{ + test(NO); +} + +-(void) dictionaryTestResponse:(TestSlicingObjectsClientBDict*)r_ bout:(TestSlicingObjectsClientBDict*)bout_ +{ + self.r = r_; + self.bout = bout_; + [self called]; +} + +-(void) dictionaryTestException:(ICEException*)exc +{ + test(NO); +} + +-(void) throwBaseAsBaseResponse +{ + test(NO); +} + +-(void) throwBaseAsBaseException:(ICEException*)ex +{ + test([[ex ice_name] isEqualToString:@"Test::BaseException"]); + TestSlicingObjectsClientBaseException* e = (TestSlicingObjectsClientBaseException*)ex; + test([e.sbe isEqualToString:@"sbe"]); + test(e.pb); + test([e.pb.sb isEqualToString:@"sb"]); + test(e.pb.pb == e.pb); + [self called]; +} + +-(void) throwDerivedAsBaseResponse +{ + test(NO); +} + +-(void) throwDerivedAsBaseException:(ICEException*)ex +{ + test([[ex ice_name] isEqualToString:@"Test::DerivedException"]); + TestSlicingObjectsClientDerivedException* e = (TestSlicingObjectsClientDerivedException*)ex; + test([e.sbe isEqualToString:@"sbe"]); + test(e.pb); + test([e.pb.sb isEqualToString:@"sb1"]); + test(e.pb.pb == e.pb); + test([e.sde isEqualToString:@"sde1"]); + test(e.pd1); + test([e.pd1.sb isEqualToString:@"sb2"]); + test(e.pd1.pb == e.pd1); + test([e.pd1.sd1 isEqualToString:@"sd2"]); + test(e.pd1.pd1 == e.pd1); + [self called]; +} + +-(void) throwDerivedAsDerivedResponse +{ + test(NO); +} + +-(void) throwDerivedAsDerivedException:(ICEException*)ex +{ + test([[ex ice_name] isEqualToString:@"Test::DerivedException"]); + TestSlicingObjectsClientDerivedException* e = (TestSlicingObjectsClientDerivedException*)ex; + test([e.sbe isEqualToString:@"sbe"]); + test(e.pb); + test([e.pb.sb isEqualToString:@"sb1"]); + test(e.pb.pb == e.pb); + test([e.sde isEqualToString:@"sde1"]); + test(e.pd1); + test([e.pd1.sb isEqualToString:@"sb2"]); + test(e.pd1.pb == e.pd1); + test([e.pd1.sd1 isEqualToString:@"sd2"]); + test(e.pd1.pd1 == e.pd1); + [self called]; +} + +-(void) throwUnknownDerivedAsBaseResponse +{ + test(NO); +} + +-(void) throwUnknownDerivedAsBaseException:(ICEException*)ex +{ + test([[ex ice_name] isEqualToString:@"Test::BaseException"]); + TestSlicingObjectsClientBaseException* e = (TestSlicingObjectsClientBaseException*)ex; + test([e.sbe isEqualToString:@"sbe"]); + test(e.pb); + test([e.pb.sb isEqualToString:@"sb d2"]); + test(e.pb.pb == e.pb); + [self called]; +} + +-(void) useForwardResponse:(TestSlicingObjectsClientForward*)f +{ + test(f); + [self called]; +} + +-(void) useForwardException:(ICEException*)exc +{ + test(NO); +} + +-(void) responsePreserved1:(TestSlicingObjectsClientPBase*)res +{ + test([res isKindOfClass:[TestSlicingObjectsClientPDerived class]]); + TestSlicingObjectsClientPDerived* pd = (TestSlicingObjectsClientPDerived*)res; + test(pd); + test(pd.pi == 3); + test([pd.ps isEqualToString:@"preserved"]); + test([pd.pb isEqual:pd]); + [self called]; +} + +-(void) responsePreserved2:(TestSlicingObjectsClientPBase*)res +{ + test(![res isKindOfClass:[TestSlicingObjectsClientPCUnknown class]]); + test(res.pi == 3); + [self called]; +} + +-(void) responsePreserved3:(TestSlicingObjectsClientPBase*)res +{ + // + // Encoding 1.0 + // + test(![res isKindOfClass:[TestSlicingObjectsClientPCDerived class]]); + test(res.pi == 3); + [self called]; +} + +-(void) responsePreserved4:(TestSlicingObjectsClientPBase*)res +{ + // + // Encoding > 1.0 + // + test([res isKindOfClass:[TestSlicingObjectsClientPCDerived class]]); + TestSlicingObjectsClientPCDerived* p2 = (TestSlicingObjectsClientPCDerived*)res; + test(p2.pi == 3); + test([[p2.pbs objectAtIndex:0] isEqual:p2]); + [self called]; +} + +-(void) responsePreserved5:(TestSlicingObjectsClientPBase*)res +{ + test([res isKindOfClass:[TestSlicingObjectsClientPCDerived3 class]]); + TestSlicingObjectsClientPCDerived3* p3 = (TestSlicingObjectsClientPCDerived3*)res; + test(p3.pi == 3); + for(int i = 0; i < 300; ++i) + { + TestSlicingObjectsClientPCDerived2* p2 = (TestSlicingObjectsClientPCDerived2*)[p3.pbs objectAtIndex:i]; + test(p2.pi == i); + test([p2.pbs count] == 1); + test([[p2.pbs objectAtIndex:0] isEqual:[NSNull null]]); + test(p2.pcd2 == i); + } + test(p3.pcd2 == p3.pi); + test([p3.pcd3 isEqual:[p3.pbs objectAtIndex:10]]); + [self called]; +} + +-(void) responseCompactPreserved1:(TestSlicingObjectsClientPBase*)res +{ + // + // Encoding 1.0 + // + test(![res isKindOfClass:[TestSlicingObjectsClientCompactPCDerived class]]); + test(res.pi == 3); + [self called]; +} + +-(void) responseCompactPreserved2:(TestSlicingObjectsClientPBase*)res +{ + // + // Encoding > 1.0 + // + test([res isKindOfClass:[TestSlicingObjectsClientCompactPCDerived class]]); + TestSlicingObjectsClientCompactPCDerived* p2 = (TestSlicingObjectsClientCompactPCDerived*)res; + test(p2.pi == 3); + test([[p2.pbs objectAtIndex:0] isEqual:p2]); + [self called]; +} + +-(void) response +{ + test(NO); +} + +-(void) exception:(ICEException*)ex +{ + if(![ex isKindOfClass:[ICEOperationNotExistException class]]) + { + test(NO); + } + else + { + [self called]; + } +} + +@end + +id<TestSlicingObjectsClientTestIntfPrx> +slicingObjectsAllTests(id<ICECommunicator> communicator) +{ + id<ICEObjectPrx> obj = [communicator stringToProxy:@"Test:default -p 12010"]; + id<TestSlicingObjectsClientTestIntfPrx> test = [TestSlicingObjectsClientTestIntfPrx checkedCast:obj]; + + tprintf("base as Object... "); + { + ICEObject* o = nil; + @try + { + o = [test SBaseAsObject]; + test(o); + test([[o ice_id] isEqualToString:@"::Test::SBase"]); + } + @catch(...) + { + test(0); + } + + test([o isKindOfClass:[TestSlicingObjectsClientSBase class]]); + test([((TestSlicingObjectsClientSBase*)o).sb isEqualToString:@"SBase.sb"]); + } + tprintf("ok\n"); + + tprintf("base as Object (AMI)... "); + { + TestSlicingObjectsClientCallback* cb = [TestSlicingObjectsClientCallback create]; + [test begin_SBaseAsObject:^(ICEObject* o) { [cb SBaseAsObjectResponse:o]; } + exception:^(ICEException* ex) { [cb SBaseAsObjectException:ex]; }]; + [cb check]; + } + tprintf("ok\n"); + + tprintf("base as base... "); + { + TestSlicingObjectsClientSBase* sb; + @try + { + sb = [test SBaseAsSBase]; + test([sb.sb isEqualToString:@"SBase.sb"]); + } + @catch(...) + { + test(0); + } + } + tprintf("ok\n"); + + tprintf("base as base (AMI)... "); + { + TestSlicingObjectsClientCallback* cb = [TestSlicingObjectsClientCallback create]; + [test begin_SBaseAsSBase:^(TestSlicingObjectsClientSBase* o) { [cb SBaseAsSBaseResponse:o]; } + exception:^(ICEException* e) { [cb SBaseAsSBaseException:e]; }]; + [cb check]; + } + tprintf("ok\n"); + + tprintf("base with known derived as base... "); + { + TestSlicingObjectsClientSBase* sb = nil; + @try + { + sb = [test SBSKnownDerivedAsSBase]; + test([sb.sb isEqualToString:@"SBSKnownDerived.sb"]); + } + @catch(...) + { + test(0); + } + test([sb isKindOfClass:[TestSlicingObjectsClientSBSKnownDerived class]]); + test([((TestSlicingObjectsClientSBSKnownDerived*)sb).sbskd isEqualToString:@"SBSKnownDerived.sbskd"]); + } + tprintf("ok\n"); + + tprintf("base with known derived as base (AMI)... "); + { + TestSlicingObjectsClientCallback* cb = [TestSlicingObjectsClientCallback create]; + [test begin_SBSKnownDerivedAsSBase:^(TestSlicingObjectsClientSBase* o) { [cb SBSKnownDerivedAsSBaseResponse:o]; } exception:^(ICEException* e) { [cb SBSKnownDerivedAsSBaseException:e]; }]; + [cb check]; + } + tprintf("ok\n"); + + tprintf("base with known derived as known derived... "); + { + TestSlicingObjectsClientSBSKnownDerived* sbskd; + @try + { + sbskd = [test SBSKnownDerivedAsSBSKnownDerived]; + test([sbskd.sbskd isEqualToString:@"SBSKnownDerived.sbskd"]); + } + @catch(...) + { + test(0); + } + } + tprintf("ok\n"); + + tprintf("base with known derived as known derived (AMI)... "); + { + TestSlicingObjectsClientCallback* cb = [TestSlicingObjectsClientCallback create]; + [test begin_SBSKnownDerivedAsSBSKnownDerived:^(TestSlicingObjectsClientSBSKnownDerived* o) { [cb SBSKnownDerivedAsSBSKnownDerivedResponse:o]; } exception:^(ICEException* e) { [cb SBSKnownDerivedAsSBSKnownDerivedException:e]; }]; + [cb check]; + } + tprintf("ok\n"); + + tprintf("base with unknown derived as base... "); + { + TestSlicingObjectsClientSBase* sb; + @try + { + sb = [test SBSUnknownDerivedAsSBase]; + test([sb.sb isEqualToString:@"SBSUnknownDerived.sb"]); + } + @catch(...) + { + test(0); + } + if([[test ice_getEncodingVersion] isEqual:ICEEncoding_1_0]) + { + @try + { + // + // This test succeeds for the 1.0 encoding. + // + sb = [test SBSUnknownDerivedAsSBaseCompact]; + test([[sb sb] isEqual:@"SBSUnknownDerived.sb"]); + } + @catch(ICEOperationNotExistException*) + { + } + @catch(...) + { + test(NO); + } + } + else + { + @try + { + // + // This test fails when using the compact format because the instance cannot + // be sliced to a known type. + // + sb = [test SBSUnknownDerivedAsSBaseCompact]; + test(NO); + } + @catch(const ICEOperationNotExistException*) + { + } + @catch(const ICENoObjectFactoryException*) + { + // Expected. + } + @catch(...) + { + test(NO); + } + } + } + tprintf("ok\n"); + + tprintf("base with unknown derived as base (AMI)... "); + { + TestSlicingObjectsClientCallback* cb = [TestSlicingObjectsClientCallback create]; + [test begin_SBSUnknownDerivedAsSBase:^(TestSlicingObjectsClientSBase* o) { [cb SBSUnknownDerivedAsSBaseResponse:o]; } exception:^(ICEException* e) { [cb SBSUnknownDerivedAsSBaseException:e]; }]; + [cb check]; + } + if([[test ice_getEncodingVersion] isEqual:ICEEncoding_1_0]) + { + // + // This test succeeds for the 1.0 encoding. + // + TestSlicingObjectsClientCallback* cb = [TestSlicingObjectsClientCallback create]; + [test begin_SBSUnknownDerivedAsSBaseCompact:^(TestSlicingObjectsClientSBase* o) { [cb SBSUnknownDerivedAsSBaseResponse:o]; } exception:^(ICEException* e) { [cb SBSUnknownDerivedAsSBaseException:e]; }]; + [cb check]; + } + else + { + // + // This test fails when using the compact format because the instance cannot + // be sliced to a known type. + // + TestSlicingObjectsClientCallback* cb = [TestSlicingObjectsClientCallback create]; + [test begin_SBSUnknownDerivedAsSBaseCompact:^(TestSlicingObjectsClientSBase* o) { [cb SBSUnknownDerivedAsSBaseCompactResponse:o]; } exception:^(ICEException* e) { [cb SBSUnknownDerivedAsSBaseCompactException:e]; }]; + [cb check]; + } + tprintf("ok\n"); + + tprintf("unknown with Object as Object... "); + { + ICEObject* o; + @try + { + o = [test SUnknownAsObject]; + test(![[test ice_getEncodingVersion] isEqual:ICEEncoding_1_0]); + test([o isKindOfClass:[ICEUnknownSlicedObject class]]); + test([[((ICEUnknownSlicedObject*)o) getUnknownTypeId] isEqualToString:@"::Test::SUnknown"]); + [test checkSUnknown:o]; + } + @catch(ICENoObjectFactoryException*) + { + test([[test ice_getEncodingVersion] isEqual:ICEEncoding_1_0]); + } + @catch(NSException* ex) + { + NSLog(@"exception: %@", ex); + test(0); + } + } + tprintf("ok\n"); + + tprintf("unknown with Object as Object (AMI)... "); + { + @try + { + TestSlicingObjectsClientCallback* cb = [TestSlicingObjectsClientCallback create]; + if([[test ice_getEncodingVersion] isEqual:ICEEncoding_1_0]) + { + [test begin_SUnknownAsObject:^(ICEObject* o) { [cb SUnknownAsObjectResponse10:o]; } + exception:^(ICEException* e) { [cb SUnknownAsObjectException10:e]; }]; + } + else + { + [test begin_SUnknownAsObject:^(ICEObject* o) { [cb SUnknownAsObjectResponse11:o]; } + exception:^(ICEException* e) { [cb SUnknownAsObjectException11:e]; }]; + } + [cb check]; + } + @catch(NSException*) + { + test(NO); + } + } + tprintf("ok\n"); + + tprintf("one-element cycle... "); + { + @try + { + TestSlicingObjectsClientB* b = [test oneElementCycle]; + test(b); + test([[b ice_id] isEqualToString:@"::Test::B"]); + test([b.sb isEqualToString:@"B1.sb"]); + test([b.pb.sb isEqualToString:@"B1.sb"]); + } + @catch(...) + { + test(0); + } + } + tprintf("ok\n"); + + tprintf("one-element cycle (AMI)... "); + { + TestSlicingObjectsClientCallback* cb = [TestSlicingObjectsClientCallback create]; + [test begin_oneElementCycle:^(TestSlicingObjectsClientB* o) { [cb oneElementCycleResponse:o]; } exception:^(ICEException* e) { [cb oneElementCycleException:e]; }]; + [cb check]; + } + tprintf("ok\n"); + + tprintf("two-element cycle... "); + { + @try + { + TestSlicingObjectsClientB* b1 = [test twoElementCycle]; + test(b1); + test([[b1 ice_id] isEqualToString:@"::Test::B"]); + test([b1.sb isEqualToString:@"B1.sb"]); + + TestSlicingObjectsClientB* b2 = b1.pb; + test(b2); + test([[b2 ice_id] isEqualToString:@"::Test::B"]); + test([b2.sb isEqualToString:@"B2.sb"]); + test(b2.pb == b1); + } + @catch(...) + { + test(0); + } + } + tprintf("ok\n"); + + tprintf("two-element cycle (AMI)... "); + { + TestSlicingObjectsClientCallback* cb = [TestSlicingObjectsClientCallback create]; + [test begin_twoElementCycle:^(TestSlicingObjectsClientB* o) { [cb twoElementCycleResponse:o]; } exception:^(ICEException* e) { [cb twoElementCycleException:e]; }]; + [cb check]; + } + tprintf("ok\n"); + + tprintf("known derived pointer slicing as base... "); + { + @try + { + TestSlicingObjectsClientB* b1; + b1 = [test D1AsB]; + test(b1); + test([[b1 ice_id] isEqualToString:@"::Test::D1"]); + test([b1.sb isEqualToString:@"D1.sb"]); + test(b1.pb); + test(b1.pb != b1); + test([b1 isKindOfClass:[TestSlicingObjectsClientD1 class]]); + TestSlicingObjectsClientD1* d1 = (TestSlicingObjectsClientD1*)b1; + test([d1.sd1 isEqualToString:@"D1.sd1"]); + test(d1.pd1); + test(d1.pd1 != b1); + test(b1.pb == d1.pd1); + + TestSlicingObjectsClientB* b2 = b1.pb; + test(b2); + test(b2.pb == b1); + test([b2.sb isEqualToString:@"D2.sb"]); + test([[b2 ice_id] isEqualToString:@"::Test::B"]); + } + @catch(...) + { + test(0); + } + } + tprintf("ok\n"); + + tprintf("known derived pointer slicing as base (AMI)... "); + { + TestSlicingObjectsClientCallback* cb = [TestSlicingObjectsClientCallback create]; + [test begin_D1AsB:^(TestSlicingObjectsClientB* o) { [cb D1AsBResponse:o]; } exception:^(ICEException* e) { [cb D1AsBException:e]; }]; + [cb check]; + } + tprintf("ok\n"); + + tprintf("known derived pointer slicing as derived... "); + { + @try + { + TestSlicingObjectsClientD1* d1; + d1 = [test D1AsD1]; + test(d1); + test([[d1 ice_id] isEqualToString:@"::Test::D1"]); + test([d1.sb isEqualToString:@"D1.sb"]); + test(d1.pb); + test(d1.pb != d1); + + TestSlicingObjectsClientB* b2 = d1.pb; + test(b2); + test([[b2 ice_id] isEqualToString:@"::Test::B"]); + test([b2.sb isEqualToString:@"D2.sb"]); + test(b2.pb == d1); + } + @catch(...) + { + test(0); + } + } + tprintf("ok\n"); + + tprintf("known derived pointer slicing as derived (AMI)... "); + { + TestSlicingObjectsClientCallback* cb = [TestSlicingObjectsClientCallback create]; + [test begin_D1AsD1:^(TestSlicingObjectsClientD1* o) { [cb D1AsD1Response:o]; } exception:^(ICEException* e) { [cb D1AsD1Exception:e]; }]; + [cb check]; + } + tprintf("ok\n"); + + tprintf("unknown derived pointer slicing as base... "); + { + @try + { + TestSlicingObjectsClientB* b2; + b2 = [test D2AsB]; + test(b2); + test([[b2 ice_id] isEqualToString:@"::Test::B"]); + test([b2.sb isEqualToString:@"D2.sb"]); + test(b2.pb); + test(b2.pb != b2); + + TestSlicingObjectsClientB* b1 = b2.pb; + test(b1); + test([[b1 ice_id] isEqualToString:@"::Test::D1"]); + test([b1.sb isEqualToString:@"D1.sb"]); + test(b1.pb == b2); + test([b1 isKindOfClass:[TestSlicingObjectsClientD1 class]]); + TestSlicingObjectsClientD1* d1 = (TestSlicingObjectsClientD1*)b1; + test([d1.sd1 isEqualToString:@"D1.sd1"]); + test(d1.pd1 == b2); + } + @catch(...) + { + test(0); + } + } + tprintf("ok\n"); + + tprintf("unknown derived pointer slicing as base (AMI)... "); + { + TestSlicingObjectsClientCallback* cb = [TestSlicingObjectsClientCallback create]; + [test begin_D2AsB:^(TestSlicingObjectsClientB* o) { [cb D2AsBResponse:o]; } exception:^(ICEException* e) { [cb D2AsBException:e]; }]; + [cb check]; + } + tprintf("ok\n"); + + tprintf("param ptr slicing with known first... "); + { + @try + { + TestSlicingObjectsClientB* b1; + TestSlicingObjectsClientB* b2; + [test paramTest1:&b1 p2:&b2]; + + test(b1); + test([[b1 ice_id] isEqualToString:@"::Test::D1"]); + test([b1.sb isEqualToString:@"D1.sb"]); + test(b1.pb == b2); + test([b1 isKindOfClass:[TestSlicingObjectsClientD1 class]]); + TestSlicingObjectsClientD1* d1 = (TestSlicingObjectsClientD1*)b1; + test([d1.sd1 isEqualToString:@"D1.sd1"]); + test(d1.pd1 == b2); + + test(b2); + test([[b2 ice_id] isEqualToString:@"::Test::B"]); // No factory, must be sliced + test([b2.sb isEqualToString:@"D2.sb"]); + test(b2.pb == b1); + } + @catch(...) + { + test(0); + } + } + tprintf("ok\n"); + + tprintf("param ptr slicing with known first (AMI)... "); + { + TestSlicingObjectsClientCallback* cb = [TestSlicingObjectsClientCallback create]; + [test begin_paramTest1:^(TestSlicingObjectsClientB* o, TestSlicingObjectsClientB* b2) { [cb paramTest1Response:o p2:b2]; } exception:^(ICEException* e) { [cb paramTest1Exception:e]; }]; + [cb check]; + } + tprintf("ok\n"); + + tprintf("param ptr slicing with unknown first... "); + { + @try + { + TestSlicingObjectsClientB* b2; + TestSlicingObjectsClientB* b1; + [test paramTest2:&b2 p1:&b1]; + + test(b1); + test([[b1 ice_id] isEqualToString:@"::Test::D1"]); + test([b1.sb isEqualToString:@"D1.sb"]); + test(b1.pb == b2); + test([b1 isKindOfClass:[TestSlicingObjectsClientD1 class]]); + TestSlicingObjectsClientD1* d1 = (TestSlicingObjectsClientD1*)b1; + test([d1.sd1 isEqualToString:@"D1.sd1"]); + test(d1.pd1 == b2); + + test(b2); + test([[b2 ice_id] isEqualToString:@"::Test::B"]); // No factory, must be sliced + test([b2.sb isEqualToString:@"D2.sb"]); + test(b2.pb == b1); + } + @catch(...) + { + test(0); + } + } + tprintf("ok\n"); + + tprintf("return value identity with known first... "); + { + @try + { + TestSlicingObjectsClientB* p1; + TestSlicingObjectsClientB* p2; + TestSlicingObjectsClientB* r = [test returnTest1:&p1 p2:&p2]; + test(r == p1); + } + @catch(...) + { + test(0); + } + } + tprintf("ok\n"); + + tprintf("return value identity with known first (AMI)... "); + { + TestSlicingObjectsClientCallback* cb = [TestSlicingObjectsClientCallback create]; + [test begin_returnTest1:^(TestSlicingObjectsClientB* o, TestSlicingObjectsClientB* b1, TestSlicingObjectsClientB* b2) { [cb returnTest1Response:o p1:b1 p2:b2]; } exception:^(ICEException* e) { [cb returnTest1Exception:e]; }]; + [cb check]; + } + tprintf("ok\n"); + + tprintf("return value identity with unknown first... "); + { + @try + { + TestSlicingObjectsClientB* p1; + TestSlicingObjectsClientB* p2; + TestSlicingObjectsClientB* r = [test returnTest2:&p1 p1:&p2]; + test(r == p1); + } + @catch(...) + { + test(0); + } + } + tprintf("ok\n"); + + tprintf("return value identity with unknown first (AMI)... "); + { + TestSlicingObjectsClientCallback* cb = [TestSlicingObjectsClientCallback create]; + [test begin_returnTest2:^(TestSlicingObjectsClientB* o, TestSlicingObjectsClientB* b1, TestSlicingObjectsClientB* b2) { [cb returnTest2Response:o p1:b1 p2:b2]; } exception:^(ICEException* e) { [cb returnTest2Exception:e]; }]; + [cb check]; + } + tprintf("ok\n"); + + tprintf("return value identity for input params known first... "); + { + @try + { + TestSlicingObjectsClientD1* d1 = [TestSlicingObjectsClientD1 d1]; + d1.sb = @"D1.sb"; + d1.sd1 = @"D1.sd1"; + TestSlicingObjectsClientD3* d3 = [TestSlicingObjectsClientD3 d3]; + d3.pb = d1; + d3.sb = @"D3.sb"; + d3.sd3 = @"D3.sd3"; + d3.pd3 = d1; + d1.pb = d3; + d1.pd1 = d3; + + TestSlicingObjectsClientB* b1 = [test returnTest3:d1 p2:d3]; + + test(b1); + test([b1.sb isEqualToString:@"D1.sb"]); + test([[b1 ice_id] isEqualToString:@"::Test::D1"]); + test([b1 isKindOfClass:[TestSlicingObjectsClientD1 class]]); + TestSlicingObjectsClientD1* p1 = (TestSlicingObjectsClientD1*)b1; + test([p1.sd1 isEqualToString:@"D1.sd1"]); + test(p1.pd1 == b1.pb); + + TestSlicingObjectsClientB* b2 = b1.pb; + test(b2); + test([b2.sb isEqualToString:@"D3.sb"]); + test([[b2 ice_id] isEqualToString:@"::Test::B"]); // Sliced by server + test(b2.pb == b1); + test(![b2 isKindOfClass:[TestSlicingObjectsClientD3 class]]); + + test(b1 != d1); + test(b1 != d3); + test(b2 != d1); + test(b2 != d3); + } + @catch(...) + { + test(0); + } + } + tprintf("ok\n"); + + tprintf("return value identity for input params known first (AMI)... "); + { + @try + { + TestSlicingObjectsClientD1* d1 = [TestSlicingObjectsClientD1 d1]; + d1.sb = @"D1.sb"; + d1.sd1 = @"D1.sd1"; + TestSlicingObjectsClientD3* d3 = [TestSlicingObjectsClientD3 d3]; + d3.pb = d1; + d3.sb = @"D3.sb"; + d3.sd3 = @"D3.sd3"; + d3.pd3 = d1; + d1.pb = d3; + d1.pd1 = d3; + + TestSlicingObjectsClientCallback* cb = [TestSlicingObjectsClientCallback create]; + [test begin_returnTest3:d1 p2:d3 response:^(TestSlicingObjectsClientB* o) { [cb returnTest3Response:o]; } exception:^(ICEException* e) { [cb returnTest3Exception:e]; }]; + [cb check]; + TestSlicingObjectsClientB* b1 = cb.r; + + test(b1); + test([b1.sb isEqualToString:@"D1.sb"]); + test([[b1 ice_id:nil] isEqualToString:@"::Test::D1"]); + test([b1 isKindOfClass:[TestSlicingObjectsClientD1 class]]); + TestSlicingObjectsClientD1* p1 = (TestSlicingObjectsClientD1*)b1; + test([p1.sd1 isEqualToString:@"D1.sd1"]); + test(p1.pd1 == b1.pb); + + TestSlicingObjectsClientB* b2 = b1.pb; + test(b2); + test([b2.sb isEqualToString:@"D3.sb"]); + test([[b2 ice_id:nil] isEqualToString:@"::Test::B"]); // Sliced by server + test(b2.pb == b1); + test(![b2 isKindOfClass:[TestSlicingObjectsClientD3 class]]); + + test(b1 != d1); + test(b1 != d3); + test(b2 != d1); + test(b2 != d3); + } + @catch(NSException*) + { + test(NO); + } + } + tprintf("ok\n"); + + tprintf("return value identity for input params unknown first... "); + { + @try + { + TestSlicingObjectsClientD1* d1 = [TestSlicingObjectsClientD1 d1]; + d1.sb = @"D1.sb"; + d1.sd1 = @"D1.sd1"; + TestSlicingObjectsClientD3* d3 = [TestSlicingObjectsClientD3 d3]; + d3.pb = d1; + d3.sb = @"D3.sb"; + d3.sd3 = @"D3.sd3"; + d3.pd3 = d1; + d1.pb = d3; + d1.pd1 = d3; + + TestSlicingObjectsClientB* b1 = [test returnTest3:d3 p2:d1]; + + test(b1); + test([b1.sb isEqualToString:@"D3.sb"]); + test([[b1 ice_id] isEqualToString:@"::Test::B"]); // Sliced by server + test(![b1 isKindOfClass:[TestSlicingObjectsClientD3 class]]); + + TestSlicingObjectsClientB* b2 = b1.pb; + test(b2); + test([b2.sb isEqualToString:@"D1.sb"]); + test([[b2 ice_id] isEqualToString:@"::Test::D1"]); + test(b2.pb == b1); + test([b2 isKindOfClass:[TestSlicingObjectsClientD1 class]]); + TestSlicingObjectsClientD1* p3 = (TestSlicingObjectsClientD1*)b2; + test([p3.sd1 isEqualToString:@"D1.sd1"]); + test(p3.pd1 == b1); + + test(b1 != d1); + test(b1 != d3); + test(b2 != d1); + test(b2 != d3); + } + @catch(...) + { + test(0); + } + } + tprintf("ok\n"); + + tprintf("return value identity for input params unknown first (AMI)... "); + { + @try + { + TestSlicingObjectsClientD1* d1 = [TestSlicingObjectsClientD1 d1]; + d1.sb = @"D1.sb"; + d1.sd1 = @"D1.sd1"; + TestSlicingObjectsClientD3* d3 = [TestSlicingObjectsClientD3 d3]; + d3.pb = d1; + d3.sb = @"D3.sb"; + d3.sd3 = @"D3.sd3"; + d3.pd3 = d1; + d1.pb = d3; + d1.pd1 = d3; + + TestSlicingObjectsClientCallback* cb = [TestSlicingObjectsClientCallback create]; + [test begin_returnTest3:d3 p2:d1 response:^(TestSlicingObjectsClientB* o) { [cb returnTest3Response:o]; } exception:^(ICEException* e) { [cb returnTest3Exception:e]; }]; + [cb check]; + TestSlicingObjectsClientB* b1 = cb.r; + + test(b1); + test([b1.sb isEqualToString:@"D3.sb"]); + test([[b1 ice_id:nil] isEqualToString:@"::Test::B"]); // Sliced by server + test(![b1 isKindOfClass:[TestSlicingObjectsClientD3 class]]); + + TestSlicingObjectsClientB* b2 = b1.pb; + test(b2); + test([b2.sb isEqualToString:@"D1.sb"]); + test([[b2 ice_id:nil] isEqualToString:@"::Test::D1"]); + test(b2.pb == b1); + test([b2 isKindOfClass:[TestSlicingObjectsClientD1 class]]); + TestSlicingObjectsClientD1* p3 = (TestSlicingObjectsClientD1*)b2; + test([p3.sd1 isEqualToString:@"D1.sd1"]); + test(p3.pd1 == b1); + + test(b1 != d1); + test(b1 != d3); + test(b2 != d1); + test(b2 != d3); + } + @catch(NSException*) + { + test(NO); + } + } + tprintf("ok\n"); + + tprintf("remainder unmarshaling (3 instances)... "); + { + @try + { + TestSlicingObjectsClientB* p1; + TestSlicingObjectsClientB* p2; + TestSlicingObjectsClientB* ret = [test paramTest3:&p1 p2:&p2]; + + test(p1); + test([p1.sb isEqualToString:@"D2.sb (p1 1)"]); + test(!p1.pb); + test([[p1 ice_id] isEqualToString:@"::Test::B"]); + + test(p2); + test([p2.sb isEqualToString:@"D2.sb (p2 1)"]); + test(!p2.pb); + test([[p2 ice_id] isEqualToString:@"::Test::B"]); + + test(ret); + test([ret.sb isEqualToString:@"D1.sb (p2 2)"]); + test(!ret.pb); + test([[ret ice_id] isEqualToString:@"::Test::D1"]); + } + @catch(...) + { + test(0); + } + } + tprintf("ok\n"); + + tprintf("remainder unmarshaling (3 instances) (AMI)... "); + { + TestSlicingObjectsClientCallback* cb = [TestSlicingObjectsClientCallback create]; + [test begin_paramTest3:^(TestSlicingObjectsClientB* o, TestSlicingObjectsClientB* b1, TestSlicingObjectsClientB* b2) { [cb paramTest3Response:o p1:b1 p2:b2]; } exception:^(ICEException* e) { [cb paramTest3Exception:e]; }]; + [cb check]; + } + tprintf("ok\n"); + + tprintf("remainder unmarshaling (4 instances)... "); + { + @try + { + TestSlicingObjectsClientB* b; + TestSlicingObjectsClientB* ret = [test paramTest4:&b]; + + test(b); + test([b.sb isEqualToString:@"D4.sb (1)"]); + test(!b.pb); + test([[b ice_id] isEqualToString:@"::Test::B"]); + + test(ret); + test([ret.sb isEqualToString:@"B.sb (2)"]); + test(!ret.pb); + test([[ret ice_id] isEqualToString:@"::Test::B"]); + } + @catch(...) + { + test(0); + } + } + tprintf("ok\n"); + + tprintf("remainder unmarshaling (4 instances) (AMI)... "); + { + TestSlicingObjectsClientCallback* cb = [TestSlicingObjectsClientCallback create]; + [test begin_paramTest4:^(TestSlicingObjectsClientB* o, TestSlicingObjectsClientB* b) { [cb paramTest4Response:o p1:b]; } exception:^(ICEException* e) { [cb paramTest4Exception:e]; }]; + [cb check]; + } + tprintf("ok\n"); + + tprintf("param ptr slicing, instance marshaled in unknown derived as base... "); + { + @try + { + TestSlicingObjectsClientB* b1 = [TestSlicingObjectsClientB b]; + b1.sb = @"B.sb(1)"; + b1.pb = b1; + + TestSlicingObjectsClientD3* d3 = [TestSlicingObjectsClientD3 d3]; + d3.sb = @"D3.sb"; + d3.pb = d3; + d3.sd3 = @"D3.sd3"; + d3.pd3 = b1; + + TestSlicingObjectsClientB* b2 = [TestSlicingObjectsClientB b]; + b2.sb = @"B.sb(2)"; + b2.pb = b1; + + TestSlicingObjectsClientB* r = [test returnTest3:d3 p2:b2]; + + test(r); + test([[r ice_id] isEqualToString:@"::Test::B"]); + test([r.sb isEqualToString:@"D3.sb"]); + test(r.pb == r); + } + @catch(...) + { + test(0); + } + } + tprintf("ok\n"); + + tprintf("param ptr slicing, instance marshaled in unknown derived as base (AMI)... "); + { + @try + { + TestSlicingObjectsClientB* b1 = [TestSlicingObjectsClientB b]; + b1.sb = @"B.sb(1)"; + b1.pb = b1; + + TestSlicingObjectsClientD3* d3 = [TestSlicingObjectsClientD3 d3]; + d3.sb = @"D3.sb"; + d3.pb = d3; + d3.sd3 = @"D3.sd3"; + d3.pd3 = b1; + + TestSlicingObjectsClientB* b2 = [TestSlicingObjectsClientB b]; + b2.sb = @"B.sb(2)"; + b2.pb = b1; + + TestSlicingObjectsClientCallback* cb = [TestSlicingObjectsClientCallback create]; + [test begin_returnTest3:d3 p2:b2 response:^(TestSlicingObjectsClientB* o) { [cb returnTest3Response:o]; } exception:^(ICEException* e) { [cb returnTest3Exception:e]; }]; + [cb check]; + TestSlicingObjectsClientB* r = cb.r; + + test(r); + test([[r ice_id:nil] isEqualToString:@"::Test::B"]); + test([r.sb isEqualToString:@"D3.sb"]); + test(r.pb == r); + } + @catch(NSException*) + { + test(NO); + } + } + tprintf("ok\n"); + + tprintf("param ptr slicing, instance marshaled in unknown derived as derived... "); + { + @try + { + TestSlicingObjectsClientD1* d11 = [TestSlicingObjectsClientD1 d1]; + d11.sb = @"D1.sb(1)"; + d11.pb = d11; + d11.sd1 = @"D1.sd1(1)"; + + TestSlicingObjectsClientD3* d3 = [TestSlicingObjectsClientD3 d3]; + d3.sb = @"D3.sb"; + d3.pb = d3; + d3.sd3 = @"D3.sd3"; + d3.pd3 = d11; + + TestSlicingObjectsClientD1* d12 = [TestSlicingObjectsClientD1 d1]; + d12.sb = @"D1.sb(2)"; + d12.pb = d12; + d12.sd1 = @"D1.sd1(2)"; + d12.pd1 = d11; + + TestSlicingObjectsClientB* r = [test returnTest3:d3 p2:d12]; + test(r); + test([[r ice_id] isEqualToString:@"::Test::B"]); + test([r.sb isEqualToString:@"D3.sb"]); + test(r.pb == r); + } + @catch(...) + { + test(0); + } + } + tprintf("ok\n"); + + tprintf("param ptr slicing, instance marshaled in unknown derived as derived (AMI)... "); + { + @try + { + TestSlicingObjectsClientD1* d11 = [TestSlicingObjectsClientD1 d1]; + d11.sb = @"D1.sb(1)"; + d11.pb = d11; + d11.sd1 = @"D1.sd1(1)"; + + TestSlicingObjectsClientD3* d3 = [TestSlicingObjectsClientD3 d3]; + d3.sb = @"D3.sb"; + d3.pb = d3; + d3.sd3 = @"D3.sd3"; + d3.pd3 = d11; + + TestSlicingObjectsClientD1* d12 = [TestSlicingObjectsClientD1 d1]; + d12.sb = @"D1.sb(2)"; + d12.pb = d12; + d12.sd1 = @"D1.sd1(2)"; + d12.pd1 = d11; + + TestSlicingObjectsClientCallback* cb = [TestSlicingObjectsClientCallback create]; + [test begin_returnTest3:d3 p2:d12 response:^(TestSlicingObjectsClientB* o) { [cb returnTest3Response:o]; } exception:^(ICEException* e) { [cb returnTest3Exception:e]; }]; + [cb check]; + TestSlicingObjectsClientB* r = cb.r; + test(r); + test([[r ice_id:nil] isEqualToString:@"::Test::B"]); + test([r.sb isEqualToString:@"D3.sb"]); + test(r.pb == r); + } + @catch(NSException*) + { + test(NO); + } + } + tprintf("ok\n"); + + tprintf("sequence slicing... "); + { + @try + { + TestSlicingObjectsClientSS* ss; + { + TestSlicingObjectsClientB* ss1b = [TestSlicingObjectsClientB b]; + ss1b.sb = @"B.sb"; + ss1b.pb = ss1b; + + TestSlicingObjectsClientD1* ss1d1 = [TestSlicingObjectsClientD1 d1]; + ss1d1.sb = @"D1.sb"; + ss1d1.sd1 = @"D1.sd1"; + ss1d1.pb = ss1b; + + TestSlicingObjectsClientD3* ss1d3 = [TestSlicingObjectsClientD3 d3]; + ss1d3.sb = @"D3.sb"; + ss1d3.sd3 = @"D3.sd3"; + ss1d3.pb = ss1b; + + TestSlicingObjectsClientB* ss2b = [TestSlicingObjectsClientB b]; + ss2b.sb = @"B.sb"; + ss2b.pb = ss1b; + + TestSlicingObjectsClientD1* ss2d1 = [TestSlicingObjectsClientD1 d1]; + ss2d1.sb = @"D1.sb"; + ss2d1.sd1 = @"D1.sd1"; + ss2d1.pb = ss2b; + + TestSlicingObjectsClientD3* ss2d3 = [TestSlicingObjectsClientD3 d3]; + ss2d3.sb = @"D3.sb"; + ss2d3.sd3 = @"D3.sd3"; + ss2d3.pb = ss2b; + + ss1d1.pd1 = ss2b; + ss1d3.pd3 = ss2d1; + + ss2d1.pd1 = ss1d3; + ss2d3.pd3 = ss1d1; + + TestSlicingObjectsClientSS1* ss1 = [TestSlicingObjectsClientSS1 ss1]; + ss1.s = [TestSlicingObjectsClientMutableBSeq arrayWithCapacity:0]; + [(TestSlicingObjectsClientMutableBSeq*)ss1.s addObject:ss1b]; + [(TestSlicingObjectsClientMutableBSeq*)ss1.s addObject:ss1d1]; + [(TestSlicingObjectsClientMutableBSeq*)ss1.s addObject:ss1d3]; + + TestSlicingObjectsClientSS2* ss2 = [TestSlicingObjectsClientSS2 ss2]; + ss2.s = [TestSlicingObjectsClientMutableBSeq arrayWithCapacity:0]; + [(TestSlicingObjectsClientMutableBSeq*)ss2.s addObject:ss2b]; + [(TestSlicingObjectsClientMutableBSeq*)ss2.s addObject:ss2d1]; + [(TestSlicingObjectsClientMutableBSeq*)ss2.s addObject:ss2d3]; + + ss = [test sequenceTest:ss1 p2:ss2]; + } + + test(ss.c1); + TestSlicingObjectsClientB* ss1b = [ss.c1.s objectAtIndex:0]; + TestSlicingObjectsClientB* ss1d1 = [ss.c1.s objectAtIndex:1]; + test(ss.c2); + TestSlicingObjectsClientB* ss1d3 = [ss.c1.s objectAtIndex:2]; + + test(ss.c2); + TestSlicingObjectsClientB* ss2b = [ss.c2.s objectAtIndex:0]; + TestSlicingObjectsClientB* ss2d1 = [ss.c2.s objectAtIndex:1]; + TestSlicingObjectsClientB* ss2d3 = [ss.c2.s objectAtIndex:2]; + + test(ss1b.pb == ss1b); + test(ss1d1.pb == ss1b); + test(ss1d3.pb == ss1b); + + test(ss2b.pb == ss1b); + test(ss2d1.pb == ss2b); + test(ss2d3.pb == ss2b); + + test([[ss1b ice_id] isEqualToString:@"::Test::B"]); + test([[ss1d1 ice_id] isEqualToString:@"::Test::D1"]); + test([[ss1d3 ice_id] isEqualToString:@"::Test::B"]); + + test([[ss2b ice_id] isEqualToString:@"::Test::B"]); + test([[ss2d1 ice_id] isEqualToString:@"::Test::D1"]); + test([[ss2d3 ice_id] isEqualToString:@"::Test::B"]); + } + @catch(ICEException*) + { + test(0); + } + } + tprintf("ok\n"); + + tprintf("sequence slicing (AMI)... "); + { + @try + { + TestSlicingObjectsClientSS* ss; + { + TestSlicingObjectsClientB* ss1b = [TestSlicingObjectsClientB b]; + ss1b.sb = @"B.sb"; + ss1b.pb = ss1b; + + TestSlicingObjectsClientD1* ss1d1 = [TestSlicingObjectsClientD1 d1]; + ss1d1.sb = @"D1.sb"; + ss1d1.sd1 = @"D1.sd1"; + ss1d1.pb = ss1b; + + TestSlicingObjectsClientD3* ss1d3 = [TestSlicingObjectsClientD3 d3]; + ss1d3.sb = @"D3.sb"; + ss1d3.sd3 = @"D3.sd3"; + ss1d3.pb = ss1b; + + TestSlicingObjectsClientB* ss2b = [TestSlicingObjectsClientB b]; + ss2b.sb = @"B.sb"; + ss2b.pb = ss1b; + + TestSlicingObjectsClientD1* ss2d1 = [TestSlicingObjectsClientD1 d1]; + ss2d1.sb = @"D1.sb"; + ss2d1.sd1 = @"D1.sd1"; + ss2d1.pb = ss2b; + + TestSlicingObjectsClientD3* ss2d3 = [TestSlicingObjectsClientD3 d3]; + ss2d3.sb = @"D3.sb"; + ss2d3.sd3 = @"D3.sd3"; + ss2d3.pb = ss2b; + + ss1d1.pd1 = ss2b; + ss1d3.pd3 = ss2d1; + + ss2d1.pd1 = ss1d3; + ss2d3.pd3 = ss1d1; + + TestSlicingObjectsClientSS1* ss1 = [TestSlicingObjectsClientSS1 ss1]; + ss1.s = [TestSlicingObjectsClientMutableBSeq array]; + [(NSMutableArray*)ss1.s addObject:ss1b]; + [(NSMutableArray*)ss1.s addObject:ss1d1]; + [(NSMutableArray*)ss1.s addObject:ss1d3]; + + TestSlicingObjectsClientSS2* ss2 = [TestSlicingObjectsClientSS2 ss2]; + ss2.s = [TestSlicingObjectsClientMutableBSeq array]; + [(NSMutableArray*)ss2.s addObject:ss2b]; + [(NSMutableArray*)ss2.s addObject:ss2d1]; + [(NSMutableArray*)ss2.s addObject:ss2d3]; + + TestSlicingObjectsClientCallback* cb = [TestSlicingObjectsClientCallback create]; + [test begin_sequenceTest:ss1 p2:ss2 response:^(TestSlicingObjectsClientSS* o) { [cb sequenceTestResponse:o]; } exception:^(ICEException* e) { [cb sequenceTestException:e]; }]; + [cb check]; + ss = cb.r; + } + + test(ss.c1); + TestSlicingObjectsClientB* ss1b = [ss.c1.s objectAtIndex:0]; + TestSlicingObjectsClientB* ss1d1 = [ss.c1.s objectAtIndex:1]; + test(ss.c2); + TestSlicingObjectsClientB* ss1d3 = [ss.c1.s objectAtIndex:2]; + + test(ss.c2); + TestSlicingObjectsClientB* ss2b = [ss.c2.s objectAtIndex:0]; + TestSlicingObjectsClientB* ss2d1 = [ss.c2.s objectAtIndex:1]; + TestSlicingObjectsClientB* ss2d3 = [ss.c2.s objectAtIndex:2]; + + test(ss1b.pb == ss1b); + test(ss1d1.pb == ss1b); + test(ss1d3.pb == ss1b); + + test(ss2b.pb == ss1b); + test(ss2d1.pb == ss2b); + test(ss2d3.pb == ss2b); + + test([[ss1b ice_id:nil] isEqualToString:@"::Test::B"]); + test([[ss1d1 ice_id:nil] isEqualToString:@"::Test::D1"]); + test([[ss1d3 ice_id:nil] isEqualToString:@"::Test::B"]); + + test([[ss2b ice_id:nil] isEqualToString:@"::Test::B"]); + test([[ss2d1 ice_id:nil] isEqualToString:@"::Test::D1"]); + test([[ss2d3 ice_id:nil] isEqualToString:@"::Test::B"]); + } + @catch(ICEException*) + { + test(NO); + } + } + tprintf("ok\n"); + + tprintf("dictionary slicing... "); + { + @try + { + TestSlicingObjectsClientMutableBDict* bin = [TestSlicingObjectsClientMutableBDict dictionary]; + TestSlicingObjectsClientMutableBDict* bout; + TestSlicingObjectsClientBDict* r; + int i; + for(i = 0; i < 10; ++i) + { + TestSlicingObjectsClientD1* d1 = [TestSlicingObjectsClientD1 d1]; + NSString *s = [@"D1." stringByAppendingString:[NSString stringWithFormat:@"%d", i]]; + d1.sb = s; + d1.pb = d1; + d1.sd1 = s; + [bin setObject:d1 forKey:[NSNumber numberWithInt:i]]; + } + + r = [test dictionaryTest:bin bout:&bout]; + + test([bout count] == 10); + for(i = 0; i < 10; ++i) + { + TestSlicingObjectsClientB* b = [bout objectForKey:[NSNumber numberWithInt:i * 10]]; + test(b); + NSString *s = [@"D1." stringByAppendingString:[NSString stringWithFormat:@"%d", i]]; + test([b.sb isEqualToString:s]); + test(b.pb); + test(b.pb != b); + test([b.pb.sb isEqualToString:s]); + test(b.pb.pb == b.pb); + } + + test([r count] == 10); + for(i = 0; i < 10; ++i) + { + TestSlicingObjectsClientB* b = [r objectForKey:[NSNumber numberWithInt:i * 20]]; + test(b); + NSString *s = [@"D1." stringByAppendingString:[NSString stringWithFormat:@"%d", i * 20]]; + test([b.sb isEqualToString:s]); + test(b.pb == (i == 0 ? nil : [r objectForKey:[NSNumber numberWithInt:(i - 1) * 20]])); + test([b isKindOfClass:[TestSlicingObjectsClientD1 class]]); + TestSlicingObjectsClientD1* d1 = (TestSlicingObjectsClientD1*)b; + test([d1.sd1 isEqualToString:s]); + test(d1.pd1 == d1); + } + } + @catch(ICEException*) + { + test(0); + } + } + tprintf("ok\n"); + + tprintf("dictionary slicing (AMI)... "); + { + @try + { + TestSlicingObjectsClientMutableBDict* bin = [TestSlicingObjectsClientMutableBDict dictionary]; + TestSlicingObjectsClientMutableBDict* bout; + TestSlicingObjectsClientMutableBDict* r; + int i; + for(i = 0; i < 10; ++i) + { + TestSlicingObjectsClientD1* d1 = [TestSlicingObjectsClientD1 d1]; + d1.sb = [NSString stringWithFormat:@"D1.%d",i]; + d1.pb = d1; + d1.sd1 = d1.sb; + [bin setObject:d1 forKey:[NSNumber numberWithInt:i]]; + } + + TestSlicingObjectsClientCallback* cb = [TestSlicingObjectsClientCallback create]; + [test begin_dictionaryTest:bin response:^(TestSlicingObjectsClientMutableBDict* o, TestSlicingObjectsClientMutableBDict* bout) { [cb dictionaryTestResponse:o bout:bout]; } exception:^(ICEException* e) { [cb dictionaryTestException:e]; }]; + [cb check]; + bout = cb.bout; + r = cb.r; + + test([bout count] == 10); + for(i = 0; i < 10; ++i) + { + TestSlicingObjectsClientB* b = [bout objectForKey:[NSNumber numberWithInt:(i * 10)]]; + test(b); + NSString* s = [NSString stringWithFormat:@"D1.%d",i]; + test([b.sb isEqualToString:s]); + test(b.pb); + test(b.pb != b); + test([b.pb.sb isEqualToString:s]); + test(b.pb.pb == b.pb); + } + + test([r count] == 10); + for(i = 0; i < 10; ++i) + { + TestSlicingObjectsClientB* b = [r objectForKey:[NSNumber numberWithInt:(i * 20)]]; + test(b); + NSString* s = [NSString stringWithFormat:@"D1.%d",(i * 20)]; + test([b.sb isEqualToString:s]); + test(b.pb == (i == 0 ? nil : [r objectForKey:[NSNumber numberWithInt:((i - 1) * 20)]])); + test([b isKindOfClass:[TestSlicingObjectsClientD1 class]]); + TestSlicingObjectsClientD1* d1 = (TestSlicingObjectsClientD1*)b; + test([d1.sd1 isEqualToString:s]); + test(d1.pd1 == d1); + } + } + @catch(ICEException*) + { + test(NO); + } + } + tprintf("ok\n"); + + tprintf("base exception thrown as base exception... "); + { + @try + { + [test throwBaseAsBase]; + test(0); + } + @catch(TestSlicingObjectsClientBaseException* e) + { + test([[e ice_name] isEqualToString: @"Test::BaseException"]); + test([e.sbe isEqualToString:@"sbe"]); + test(e.pb); + test([e.pb.sb isEqualToString:@"sb"]); + test(e.pb.pb == e.pb); + } + @catch(...) + { + test(0); + } + } + tprintf("ok\n"); + + tprintf("base exception thrown as base exception (AMI)... "); + { + TestSlicingObjectsClientCallback* cb = [TestSlicingObjectsClientCallback create]; + [test begin_throwBaseAsBase:^ { [cb throwBaseAsBaseResponse]; } exception:^(ICEException* e) { [cb throwBaseAsBaseException:e]; }]; + [cb check]; + } + tprintf("ok\n"); + + tprintf("derived exception thrown as base exception... "); + { + @try + { + [test throwDerivedAsBase]; + test(0); + } + @catch(TestSlicingObjectsClientDerivedException* e) + { + test([[e ice_name] isEqualToString:@"Test::DerivedException"]); + test([e.sbe isEqualToString:@"sbe"]); + test(e.pb); + test([e.pb.sb isEqualToString:@"sb1"]); + test(e.pb.pb == e.pb); + test([e.sde isEqualToString:@"sde1"]); + test(e.pd1); + test([e.pd1.sb isEqualToString:@"sb2"]); + test(e.pd1.pb == e.pd1); + test([e.pd1.sd1 isEqualToString:@"sd2"]); + test(e.pd1.pd1 == e.pd1); + } + @catch(...) + { + test(0); + } + } + tprintf("ok\n"); + + tprintf("derived exception thrown as base exception (AMI)... "); + { + TestSlicingObjectsClientCallback* cb = [TestSlicingObjectsClientCallback create]; + [test begin_throwDerivedAsBase:^ { [cb throwDerivedAsBaseResponse]; } exception:^(ICEException* e) { [cb throwDerivedAsBaseException:e]; }]; + [cb check]; + } + tprintf("ok\n"); + + tprintf("derived exception thrown as derived exception... "); + { + @try + { + [test throwDerivedAsDerived]; + test(0); + } + @catch(TestSlicingObjectsClientDerivedException* e) + { + test([[e ice_name] isEqualToString:@"Test::DerivedException"]); + test([e.sbe isEqualToString:@"sbe"]); + test(e.pb); + test([e.pb.sb isEqualToString:@"sb1"]); + test(e.pb.pb == e.pb); + test([e.sde isEqualToString:@"sde1"]); + test(e.pd1); + test([e.pd1.sb isEqualToString:@"sb2"]); + test(e.pd1.pb == e.pd1); + test([e.pd1.sd1 isEqualToString:@"sd2"]); + test(e.pd1.pd1 == e.pd1); + } + @catch(...) + { + test(0); + } + } + tprintf("ok\n"); + + tprintf("derived exception thrown as derived exception (AMI)... "); + { + TestSlicingObjectsClientCallback* cb = [TestSlicingObjectsClientCallback create]; + [test begin_throwDerivedAsDerived:^ { [cb throwDerivedAsDerivedResponse]; } exception:^(ICEException* e) { [cb throwDerivedAsDerivedException:e]; }]; + [cb check]; + } + tprintf("ok\n"); + + tprintf("unknown derived exception thrown as base exception... "); + { + @try + { + [test throwUnknownDerivedAsBase]; + test(0); + } + @catch(TestSlicingObjectsClientBaseException* e) + { + test([[e ice_name] isEqualToString:@"Test::BaseException"]); + test([e.sbe isEqualToString:@"sbe"]); + test(e.pb); + test([e.pb.sb isEqualToString:@"sb d2"]); + test(e.pb.pb == e.pb); + } + @catch(...) + { + test(0); + } + } + tprintf("ok\n"); + + tprintf("unknown derived exception thrown as base exception (AMI)... "); + { + TestSlicingObjectsClientCallback* cb = [TestSlicingObjectsClientCallback create]; + [test begin_throwUnknownDerivedAsBase:^ { [cb throwUnknownDerivedAsBaseResponse]; } exception:^(ICEException* e) { [cb throwUnknownDerivedAsBaseException:e]; }]; + [cb check]; + } + tprintf("ok\n"); + + tprintf("forward-declared class... "); + { + @try + { + TestSlicingObjectsClientForward* f; + [test useForward:&f]; + test(f); + } + @catch(...) + { + test(0); + } + } + tprintf("ok\n"); + + tprintf("forward-declared class (AMI)... "); + { + TestSlicingObjectsClientCallback* cb = [TestSlicingObjectsClientCallback create]; + [test begin_useForward:^(TestSlicingObjectsClientForward* o) { [cb useForwardResponse:o]; } exception:^(ICEException* e) { [cb useForwardException:e]; }]; + [cb check]; + } + tprintf("ok\n"); + + tprintf("preserved classes... "); + @try + { + // + // Server knows the most-derived class PDerived. + // + TestSlicingObjectsClientPDerived* pd = [TestSlicingObjectsClientPDerived pDerived]; + pd.pi = 3; + pd.ps = @"preserved"; + pd.pb = pd; + + TestSlicingObjectsClientPBase* r = [test exchangePBase:pd]; + TestSlicingObjectsClientPDerived* p2 = (TestSlicingObjectsClientPDerived*)r; + test(p2); + test(p2.pi == 3); + test([p2.ps isEqual:@"preserved"]); + test(p2.pb == p2); + } + @catch(ICEOperationNotExistException*) + { + } + + @try + { + // + // Server only knows the base (non-preserved) type, so the object is sliced. + // + TestSlicingObjectsClientPCUnknown* pu = [TestSlicingObjectsClientPCUnknown pcUnknown]; + pu.pi = 3; + pu.pu = @"preserved"; + + TestSlicingObjectsClientPBase* r = [test exchangePBase:pu]; + test(![r isKindOfClass:[TestSlicingObjectsClientPCUnknown class]]); + test(r.pi == 3); + } + @catch(ICEOperationNotExistException*) + { + } + + @try + { + // + // Server only knows the intermediate type Preserved. The object will be sliced to + // Preserved for the 1.0 encoding; otherwise it should be returned intact. + // + TestSlicingObjectsClientPCDerived* pcd = [TestSlicingObjectsClientPCDerived pcDerived]; + pcd.pi = 3; + pcd.pbs = [NSArray arrayWithObjects:pcd, nil]; + + TestSlicingObjectsClientPBase* r = [test exchangePBase:pcd]; + + if([[test ice_getEncodingVersion] isEqual:ICEEncoding_1_0]) + { + test(![r isKindOfClass:[TestSlicingObjectsClientPCDerived class]]); + test(r.pi == 3); + } + else + { + test([r isKindOfClass:[TestSlicingObjectsClientPCDerived class]]); + TestSlicingObjectsClientPCDerived* p2 = (TestSlicingObjectsClientPCDerived*)r; + test(p2); + test(p2.pi == 3); + test([[[p2 pbs] objectAtIndex:0] isEqual:p2]); + } + } + @catch(ICEOperationNotExistException*) + { + } + + @try + { + // + // Server only knows the intermediate type CompactPDerived. The object will be sliced to + // CompactPDerived for the 1.0 encoding; otherwise it should be returned intact. + // + TestSlicingObjectsClientCompactPCDerived* pcd = [TestSlicingObjectsClientCompactPCDerived compactPCDerived]; + pcd.pi = 3; + pcd.pbs = [NSArray arrayWithObjects:pcd, nil]; + + TestSlicingObjectsClientPBase* r = [test exchangePBase:pcd]; + + if([[test ice_getEncodingVersion] isEqual:ICEEncoding_1_0]) + { + test(![r isKindOfClass:[TestSlicingObjectsClientCompactPCDerived class]]); + test(r.pi == 3); + } + else + { + test([r isKindOfClass:[TestSlicingObjectsClientCompactPCDerived class]]); + TestSlicingObjectsClientCompactPCDerived* p2 = (TestSlicingObjectsClientCompactPCDerived*)r; + test(p2); + test(p2.pi == 3); + test([p2.pbs objectAtIndex:0] == p2); + } + } + @catch(ICEOperationNotExistException*) + { + } + + @try + { + // + // Send an object that will have multiple preserved slices in the server. + // The object will be sliced to Preserved for the 1.0 encoding. + // + TestSlicingObjectsClientPCDerived3* pcd = [TestSlicingObjectsClientPCDerived3 pcDerived3]; + pcd.pi = 3; + // + // Sending more than 254 objects exercises the encoding for object ids. + // + int i; + pcd.pbs = [NSArray array]; + for(i = 0; i < 300; ++i) + { + TestSlicingObjectsClientPCDerived2* p2 = [TestSlicingObjectsClientPCDerived2 pcDerived2]; + p2.pi = i; + p2.pbs = [NSArray arrayWithObjects:[NSNull null], nil]; // Nil reference. This slice should not have an indirection table. + p2.pcd2 = i; + pcd.pbs = [pcd.pbs arrayByAddingObject:p2]; + } + pcd.pcd2 = pcd.pi; + pcd.pcd3 = [pcd.pbs objectAtIndex:10]; + + TestSlicingObjectsClientPBase* r = [test exchangePBase:pcd]; + if([[test ice_getEncodingVersion] isEqual:ICEEncoding_1_0]) + { + test(![r isKindOfClass:[TestSlicingObjectsClientPCDerived3 class]]); + test([r isKindOfClass:[TestSlicingObjectsClientPreserved class]]); + test(r.pi == 3); + } + else + { + test([r isKindOfClass:[TestSlicingObjectsClientPCDerived3 class]]); + TestSlicingObjectsClientPCDerived3* p3 = (TestSlicingObjectsClientPCDerived3*)r; + test(p3.pi == 3); + for(i = 0; i < 300; ++i) + { + TestSlicingObjectsClientPCDerived2* p2 = (TestSlicingObjectsClientPCDerived2*)[p3.pbs objectAtIndex:i]; + test(p2.pi == i); + test([p2.pbs count] == 1); + test([[p2.pbs objectAtIndex:0] isEqual:[NSNull null]]); + test(p2.pcd2 == i); + } + test(p3.pcd2 == p3.pi); + test(p3.pcd3 == [p3.pbs objectAtIndex:10]); + } + } + @catch(ICEOperationNotExistException*) + { + } + + @try + { + // + // Obtain an object with preserved slices and send it back to the server. + // The preserved slices should be excluded for the 1.0 encoding, otherwise + // they should be included. + // + TestSlicingObjectsClientPreserved* p = [test PBSUnknownAsPreserved]; + [test checkPBSUnknown:p]; + if(![[test ice_getEncodingVersion] isEqual:ICEEncoding_1_0]) + { + [[test ice_encodingVersion:ICEEncoding_1_0] checkPBSUnknown:p]; + } + } + @catch(ICEOperationNotExistException*) + { + } + + tprintf("ok\n"); + + tprintf("preserved classes (AMI)... "); + { + // + // Server knows the most-derived class PDerived. + // + TestSlicingObjectsClientPDerived* pd = [TestSlicingObjectsClientPDerived pDerived]; + pd.pi = 3; + pd.ps = @"preserved"; + pd.pb = pd; + + TestSlicingObjectsClientCallback* cb = [TestSlicingObjectsClientCallback create]; + [test begin_exchangePBase:pd + response:^(TestSlicingObjectsClientPBase* o) { [cb responsePreserved1:o]; } + exception:^(ICEException* ex) { [cb exception:ex]; }]; + [cb check]; + } + + { + TestSlicingObjectsClientPCUnknown* pu = [TestSlicingObjectsClientPCUnknown pcUnknown]; + pu.pi = 3; + pu.pu = @"preserved"; + + // + // Server only knows the base (non-preserved) type, so the object is sliced. + // + TestSlicingObjectsClientCallback* cb = [TestSlicingObjectsClientCallback create]; + [test begin_exchangePBase:pu + response:^(TestSlicingObjectsClientPBase* o) { [cb responsePreserved2:o]; } + exception:^(ICEException* ex) { [cb exception:ex]; }]; + [cb check]; + } + + { + // + // Server only knows the intermediate type Preserved. The object will be sliced to + // Preserved for the 1.0 encoding; otherwise it should be returned intact. + // + TestSlicingObjectsClientPCDerived* pcd = [TestSlicingObjectsClientPCDerived pcDerived]; + pcd.pi = 3; + pcd.pbs = [NSArray arrayWithObjects:pcd, nil]; + + TestSlicingObjectsClientCallback* cb = [TestSlicingObjectsClientCallback create]; + if([[test ice_getEncodingVersion] isEqual:ICEEncoding_1_0]) + { + [test begin_exchangePBase:pcd + response:^(TestSlicingObjectsClientPBase* o) { [cb responsePreserved3:o]; } + exception:^(ICEException* ex) { [cb exception:ex]; }]; + } + else + { + [test begin_exchangePBase:pcd + response:^(TestSlicingObjectsClientPBase* o) { [cb responsePreserved4:o]; } + exception:^(ICEException* ex) { [cb exception:ex]; }]; + } + [cb check]; + } + + { + // + // Server only knows the intermediate type CompactPDerived. The object will be sliced to + // CompactPDerived for the 1.0 encoding; otherwise it should be returned intact. + // + TestSlicingObjectsClientCompactPCDerived* pcd = [TestSlicingObjectsClientCompactPCDerived compactPCDerived]; + pcd.pi = 3; + pcd.pbs = [NSArray arrayWithObjects:pcd, nil]; + + TestSlicingObjectsClientCallback* cb = [TestSlicingObjectsClientCallback create]; + if([[test ice_getEncodingVersion] isEqual:ICEEncoding_1_0]) + { + [test begin_exchangePBase:pcd + response:^(TestSlicingObjectsClientPBase* o) { [cb responseCompactPreserved1:o]; } + exception:^(ICEException* ex) { [cb exception:ex]; }]; + } + else + { + [test begin_exchangePBase:pcd + response:^(TestSlicingObjectsClientPBase* o) { [cb responseCompactPreserved2:o]; } + exception:^(ICEException* ex) { [cb exception:ex]; }]; + } + [cb check]; + } + + { + // + // Send an object that will have multiple preserved slices in the server. + // The object will be sliced to Preserved for the 1.0 encoding. + // + TestSlicingObjectsClientPCDerived3* pcd = [TestSlicingObjectsClientPCDerived3 pcDerived3]; + pcd.pi = 3; + + // + // Sending more than 254 objects exercises the encoding for object ids. + // + int i; + pcd.pbs = [NSArray array]; + for(i = 0; i < 300; ++i) + { + TestSlicingObjectsClientPCDerived2* p2 = [TestSlicingObjectsClientPCDerived2 pcDerived2]; + p2.pi = i; + p2.pbs = [NSArray arrayWithObjects:[NSNull null], nil]; // Nil reference. This slice should not have an indirection table. + p2.pcd2 = i; + pcd.pbs = [pcd.pbs arrayByAddingObject:p2]; + } + pcd.pcd2 = pcd.pi; + pcd.pcd3 = [pcd.pbs objectAtIndex:10]; + + TestSlicingObjectsClientCallback* cb = [TestSlicingObjectsClientCallback create]; + if([[test ice_getEncodingVersion] isEqual:ICEEncoding_1_0]) + { + [test begin_exchangePBase:pcd + response:^(TestSlicingObjectsClientPBase* o) { [cb responsePreserved3:o]; } + exception:^(ICEException* ex) { [cb exception:ex]; }]; + } + else + { + [test begin_exchangePBase:pcd + response:^(TestSlicingObjectsClientPBase* o) { [cb responsePreserved5:o]; } + exception:^(ICEException* ex) { [cb exception:ex]; }]; + } + [cb check]; + } + + tprintf("ok\n"); + + return test; +} diff --git a/objective-c/test/Ice/slicing/objects/Client.m b/objective-c/test/Ice/slicing/objects/Client.m new file mode 100644 index 00000000000..3e8147698dc --- /dev/null +++ b/objective-c/test/Ice/slicing/objects/Client.m @@ -0,0 +1,71 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <TestCommon.h> +#import <SlicingObjectsTestClient.h> + +static int +run(id<ICECommunicator> communicator) +{ + id<TestSlicingObjectsClientTestIntfPrx> slicingObjectsAllTests(id<ICECommunicator>); + id<TestSlicingObjectsClientTestIntfPrx> TestSlicingObjectsClient = slicingObjectsAllTests(communicator); + [TestSlicingObjectsClient shutdown]; + return EXIT_SUCCESS; +} + +#if TARGET_OS_IPHONE +# define main slicingObjectsClient +#endif + +int +main(int argc, char* argv[]) +{ + int status; + @autoreleasepool + { + id<ICECommunicator> communicator = nil; + @try + { + ICEInitializationData* initData = [ICEInitializationData initializationData]; + initData.properties = defaultClientProperties(&argc, argv); +#if TARGET_OS_IPHONE + initData.prefixTable__ = [NSDictionary dictionaryWithObjectsAndKeys: + @"TestSlicingObjectsClient", @"::Test", + @"TestSlicingObjectsShared", @"::TestShared", + nil]; +#endif + communicator = [ICEUtil createCommunicator:&argc argv:argv initData:initData]; + status = run(communicator); + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + @catch(TestFailedException* ex) + { + status = EXIT_FAILURE; + } + + if(communicator) + { + @try + { + [communicator destroy]; + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + } + } + return status; +} diff --git a/objective-c/test/Ice/slicing/objects/Makefile b/objective-c/test/Ice/slicing/objects/Makefile new file mode 100644 index 00000000000..4a2a8876ab2 --- /dev/null +++ b/objective-c/test/Ice/slicing/objects/Makefile @@ -0,0 +1,45 @@ +# ********************************************************************** +# +# Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +# +# This copy of Ice is licensed to you under the terms described in the +# ICE_LICENSE file included in this distribution. +# +# ********************************************************************** + +top_srcdir = ../../../.. + +CLIENT = client +SERVER = server + +TARGETS = $(CLIENT) $(SERVER) + +SLICE_OBJS = SlicingObjectsTestClient.o \ + SlicingObjectsForwardClient.o \ + SlicingObjectsTestServer.o \ + SlicingObjectsForwardServer.o + +COBJS = SlicingObjectsTestClient.o \ + SlicingObjectsForwardClient.o \ + Client.o \ + AllTests.o + +SOBJS = SlicingObjectsTestServer.o \ + SlicingObjectsForwardServer.o \ + TestI.o \ + Server.o + +OBJS = $(COBJS) $(SOBJS) + +include $(top_srcdir)/config/Make.rules + +CPPFLAGS := -I. -I../.. -I../../../include $(CPPFLAGS) +SLICE2OBJCFLAGS := -I. $(SLICE2OBJCFLAGS) + +$(CLIENT): $(COBJS) + rm -f $@ + $(CXX) $(LDFLAGS) $(LDEXEFLAGS) -o $@ $(COBJS) $(TEST_LIBS) + +$(SERVER): $(SOBJS) + rm -f $@ + $(CXX) $(LDFLAGS) $(LDEXEFLAGS) -o $@ $(SOBJS) $(TEST_LIBS) diff --git a/objective-c/test/Ice/slicing/objects/Server.m b/objective-c/test/Ice/slicing/objects/Server.m new file mode 100644 index 00000000000..ea75e85472b --- /dev/null +++ b/objective-c/test/Ice/slicing/objects/Server.m @@ -0,0 +1,76 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <slicing/objects/TestI.h> +#include <TestCommon.h> + +static int +run(id<ICECommunicator> communicator) +{ + id<ICEProperties> properties = [communicator getProperties]; + [properties setProperty:@"Ice.Warn.Dispatch" value:@"0"]; + [[communicator getProperties] setProperty:@"TestAdapter.Endpoints" value:@"default -p 12010"]; + id<ICEObjectAdapter> adapter = [communicator createObjectAdapter:@"TestAdapter"]; + ICEObject* object = [TestSlicingObjectsServerI testIntf]; + [adapter add:object identity:[communicator stringToIdentity:@"Test"]]; + [adapter activate]; + + serverReady(communicator); + + [communicator waitForShutdown]; + return EXIT_SUCCESS; +} + +#if TARGET_OS_IPHONE +# define main slicingObjectsServer +#endif + +int +main(int argc, char* argv[]) +{ + int status; + @autoreleasepool + { + id<ICECommunicator> communicator = nil; + + @try + { + ICEInitializationData* initData = [ICEInitializationData initializationData]; + initData.properties = defaultServerProperties(&argc, argv); +#if TARGET_OS_IPHONE + initData.prefixTable__ = [NSDictionary dictionaryWithObjectsAndKeys: + @"TestSlicingObjectsServer", @"::Test", + @"TestSlicingObjectsShared", @"::TestShared", + nil]; +#endif + communicator = [ICEUtil createCommunicator:&argc argv:argv initData:initData]; + status = run(communicator); + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + + if(communicator) + { + @try + { + [communicator destroy]; + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + } + } + return status; +} diff --git a/objective-c/test/Ice/slicing/objects/SlicingObjectsForwardClient.ice b/objective-c/test/Ice/slicing/objects/SlicingObjectsForwardClient.ice new file mode 100644 index 00000000000..962607a6327 --- /dev/null +++ b/objective-c/test/Ice/slicing/objects/SlicingObjectsForwardClient.ice @@ -0,0 +1,28 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#pragma once + +["objc:prefix:TestSlicingObjectsClient"] +module Test +{ + +class Forward; + +class Hidden +{ + Forward f; +}; + +class Forward +{ + Hidden h; +}; + +}; diff --git a/objective-c/test/Ice/slicing/objects/SlicingObjectsForwardServer.ice b/objective-c/test/Ice/slicing/objects/SlicingObjectsForwardServer.ice new file mode 100644 index 00000000000..d579d5d701e --- /dev/null +++ b/objective-c/test/Ice/slicing/objects/SlicingObjectsForwardServer.ice @@ -0,0 +1,28 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#pragma once + +["objc:prefix:TestSlicingObjectsServer"] +module Test +{ + +class Forward; + +class Hidden +{ + Forward f; +}; + +class Forward +{ + Hidden h; +}; + +}; diff --git a/objective-c/test/Ice/slicing/objects/SlicingObjectsTestClient.ice b/objective-c/test/Ice/slicing/objects/SlicingObjectsTestClient.ice new file mode 100644 index 00000000000..be866367184 --- /dev/null +++ b/objective-c/test/Ice/slicing/objects/SlicingObjectsTestClient.ice @@ -0,0 +1,196 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#pragma once + +["objc:prefix:TestSlicingObjectsClient"] +module Test +{ + +class SBase +{ + string sb; +}; + +class SBSKnownDerived extends SBase +{ + string sbskd; +}; + +class B +{ + string sb; + B pb; +}; + +class D1 extends B +{ + string sd1; + B pd1; +}; + +sequence<B> BSeq; + +class SS1 +{ + BSeq s; +}; + +class SS2 +{ + BSeq s; +}; + +struct SS +{ + SS1 c1; + SS2 c2; +}; + +dictionary<int, B> BDict; + +exception BaseException +{ + string sbe; + B pb; +}; + +exception DerivedException extends BaseException +{ + string sde; + D1 pd1; +}; + +class Forward; /* Forward-declared class defined in another compilation unit */ + +class PBase +{ + int pi; +}; + +sequence<PBase> PBaseSeq; + +["preserve-slice"] +class Preserved extends PBase +{ + string ps; +}; + +class PDerived extends Preserved +{ + PBase pb; +}; + +class CompactPDerived(56) extends Preserved +{ + PBase pb; +}; + +["preserve-slice"] +class PNode +{ + PNode next; +}; + +["preserve-slice"] +exception PreservedException +{ +}; + +["preserve-slice"] +class PCUnknown extends PBase +{ + string pu; +}; + +class PCDerived extends PDerived +{ + PBaseSeq pbs; +}; + +class PCDerived2 extends PCDerived +{ + int pcd2; +}; + +class PCDerived3 extends PCDerived2 +{ + Object pcd3; +}; + +class CompactPCDerived(57) extends CompactPDerived +{ + PBaseSeq pbs; +}; + +["format:sliced"] interface TestIntf +{ + Object SBaseAsObject(); + SBase SBaseAsSBase(); + SBase SBSKnownDerivedAsSBase(); + SBSKnownDerived SBSKnownDerivedAsSBSKnownDerived(); + + SBase SBSUnknownDerivedAsSBase(); + ["format:compact"] SBase SBSUnknownDerivedAsSBaseCompact(); + + Object SUnknownAsObject(); + void checkSUnknown(Object o); + + B oneElementCycle(); + B twoElementCycle(); + B D1AsB(); + D1 D1AsD1(); + B D2AsB(); + + void paramTest1(out B p1, out B p2); + void paramTest2(out B p2, out B p1); + B paramTest3(out B p1, out B p2); + B paramTest4(out B p); + + B returnTest1(out B p1, out B p2); + B returnTest2(out B p2, out B p1); + B returnTest3(B p1, B p2); + + SS sequenceTest(SS1 p1, SS2 p2); + + BDict dictionaryTest(BDict bin, out BDict bout); + + PBase exchangePBase(PBase pb); + + Preserved PBSUnknownAsPreserved(); + void checkPBSUnknown(Preserved p); + + Preserved PBSUnknownAsPreservedWithGraph(); + void checkPBSUnknownWithGraph(Preserved p); + + Preserved PBSUnknown2AsPreservedWithGraph(); + void checkPBSUnknown2WithGraph(Preserved p); + + PNode exchangePNode(PNode pn); + + void throwBaseAsBase() throws BaseException; + void throwDerivedAsBase() throws BaseException; + void throwDerivedAsDerived() throws DerivedException; + void throwUnknownDerivedAsBase() throws BaseException; + ["amd"] void throwPreservedException() throws PreservedException; + + void useForward(out Forward f); // Use of forward-declared class to verify that code is generated correctly. + + void shutdown(); +}; + +// Things private to the client. + +class D3 extends B +{ + string sd3; + B pd3; +}; + +}; diff --git a/objective-c/test/Ice/slicing/objects/SlicingObjectsTestServer.ice b/objective-c/test/Ice/slicing/objects/SlicingObjectsTestServer.ice new file mode 100644 index 00000000000..f9d21a13561 --- /dev/null +++ b/objective-c/test/Ice/slicing/objects/SlicingObjectsTestServer.ice @@ -0,0 +1,215 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#pragma once + +["objc:prefix:TestSlicingObjectsServer"] +module Test +{ + +class SBase +{ + string sb; +}; + +class SBSKnownDerived extends SBase +{ + string sbskd; +}; + +class B +{ + string sb; + B pb; +}; + +class D1 extends B +{ + string sd1; + B pd1; +}; + +sequence<B> BSeq; + +class SS1 +{ + BSeq s; +}; + +class SS2 +{ + BSeq s; +}; + +struct SS +{ + SS1 c1; + SS2 c2; +}; + +dictionary<int, B> BDict; + +exception BaseException +{ + string sbe; + B pb; +}; + +exception DerivedException extends BaseException +{ + string sde; + D1 pd1; +}; + +class Forward; /* Forward-declared class defined in another compilation unit */ + +class PBase +{ + int pi; +}; + +sequence<PBase> PBaseSeq; + +["preserve-slice"] +class Preserved extends PBase +{ + string ps; +}; + +class PDerived extends Preserved +{ + PBase pb; +}; + +class CompactPDerived(56) extends Preserved +{ + PBase pb; +}; + +["preserve-slice"] +class PNode +{ + PNode next; +}; + +class MyClass +{ + int i; +}; + +class PSUnknown extends Preserved +{ + string psu; + PNode graph; + MyClass cl; +}; + +class PSUnknown2 extends Preserved +{ + PBase pb; +}; + +["preserve-slice"] +exception PreservedException +{ +}; + +exception PSUnknownException extends PreservedException +{ + PSUnknown2 p; +}; + +["format:sliced"] interface TestIntf +{ + Object SBaseAsObject(); + SBase SBaseAsSBase(); + SBase SBSKnownDerivedAsSBase(); + SBSKnownDerived SBSKnownDerivedAsSBSKnownDerived(); + + SBase SBSUnknownDerivedAsSBase(); + ["format:compact"] SBase SBSUnknownDerivedAsSBaseCompact(); + + Object SUnknownAsObject(); + void checkSUnknown(Object o); + + B oneElementCycle(); + B twoElementCycle(); + B D1AsB(); + D1 D1AsD1(); + B D2AsB(); + + void paramTest1(out B p1, out B p2); + void paramTest2(out B p2, out B p1); + B paramTest3(out B p1, out B p2); + B paramTest4(out B p); + + B returnTest1(out B p1, out B p2); + B returnTest2(out B p2, out B p1); + B returnTest3(B p1, B p2); + + SS sequenceTest(SS1 p1, SS2 p2); + + BDict dictionaryTest(BDict bin, out BDict bout); + + PBase exchangePBase(PBase pb); + + Preserved PBSUnknownAsPreserved(); + void checkPBSUnknown(Preserved p); + + Preserved PBSUnknownAsPreservedWithGraph(); + void checkPBSUnknownWithGraph(Preserved p); + + Preserved PBSUnknown2AsPreservedWithGraph(); + void checkPBSUnknown2WithGraph(Preserved p); + + PNode exchangePNode(PNode pn); + + void throwBaseAsBase() throws BaseException; + void throwDerivedAsBase() throws BaseException; + void throwDerivedAsDerived() throws DerivedException; + void throwUnknownDerivedAsBase() throws BaseException; + ["amd"] void throwPreservedException() throws PreservedException; + + void useForward(out Forward f); // Use of forward-declared class to verify that code is generated correctly. + + void shutdown(); +}; + + +// Things private to the server. + +class SBSUnknownDerived extends SBase +{ + string sbsud; +}; + +class SUnknown +{ + string su; +}; + +class D2 extends B +{ + string sd2; + B pd2; +}; + +class D4 extends B +{ + B p1; + B p2; +}; + +exception UnknownDerivedException extends BaseException +{ + string sude; + D2 pd2; +}; + +}; diff --git a/objective-c/test/Ice/slicing/objects/TestI.h b/objective-c/test/Ice/slicing/objects/TestI.h new file mode 100644 index 00000000000..a7b6d0b90a7 --- /dev/null +++ b/objective-c/test/Ice/slicing/objects/TestI.h @@ -0,0 +1,18 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <SlicingObjectsTestServer.h> +#import <SlicingObjectsForwardServer.h> + +@interface TestSlicingObjectsServerI : TestSlicingObjectsServerTestIntf<TestSlicingObjectsServerTestIntf> +{ +@private + TestSlicingObjectsServerPSUnknownException* ex_; +} +@end diff --git a/objective-c/test/Ice/slicing/objects/TestI.m b/objective-c/test/Ice/slicing/objects/TestI.m new file mode 100644 index 00000000000..d840ef8a0ab --- /dev/null +++ b/objective-c/test/Ice/slicing/objects/TestI.m @@ -0,0 +1,440 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <slicing/objects/TestI.h> +#import <TestCommon.h> + +@implementation TestSlicingObjectsServerI +-(ICEObject*) SBaseAsObject:(ICECurrent*)current +{ + return [TestSlicingObjectsServerSBase sBase:@"SBase.sb"]; +} + +-(TestSlicingObjectsServerSBase*) SBaseAsSBase:(ICECurrent*)current +{ + return [TestSlicingObjectsServerSBase sBase:@"SBase.sb"]; +} + +-(TestSlicingObjectsServerSBase*) SBSKnownDerivedAsSBase:(ICECurrent*)current +{ + return [TestSlicingObjectsServerSBSKnownDerived sbsKnownDerived:@"SBSKnownDerived.sb" + sbskd:@"SBSKnownDerived.sbskd"]; +} + +-(TestSlicingObjectsServerSBSKnownDerived*) SBSKnownDerivedAsSBSKnownDerived:(ICECurrent*)current +{ + return [TestSlicingObjectsServerSBSKnownDerived sbsKnownDerived:@"SBSKnownDerived.sb" + sbskd:@"SBSKnownDerived.sbskd"]; +} + +-(TestSlicingObjectsServerSBase*) SBSUnknownDerivedAsSBase:(ICECurrent*)current +{ + return [TestSlicingObjectsServerSBSUnknownDerived sbsUnknownDerived:@"SBSUnknownDerived.sb" + sbsud:@"SBSUnknownDerived.sbsud"]; +} + +-(TestSlicingObjectsServerSBase*) SBSUnknownDerivedAsSBaseCompact:(ICECurrent*)current +{ + return [TestSlicingObjectsServerSBSUnknownDerived sbsUnknownDerived:@"SBSUnknownDerived.sb" + sbsud:@"SBSUnknownDerived.sbsud"]; +} + +-(ICEObject*) SUnknownAsObject:(ICECurrent*)current +{ + return [TestSlicingObjectsServerSUnknown sUnknown:@"SUnknown.su"]; +} + +-(void) checkSUnknown:(ICEObject*) object current:(ICECurrent*)current +{ + if([current encoding] == ICEEncoding_1_0) + { + test(![object isKindOfClass:[TestSlicingObjectsServerSUnknown class]]); + } + else + { + test([object isKindOfClass:[TestSlicingObjectsServerSUnknown class]]); + TestSlicingObjectsServerSUnknown* su = (TestSlicingObjectsServerSUnknown*)object; + test([[su su] isEqual:@"SUnknown.su"]); + } +} + +-(TestSlicingObjectsServerB*) oneElementCycle:(ICECurrent*)current +{ + TestSlicingObjectsServerB* b1 = [TestSlicingObjectsServerB b]; + b1.sb = @"B1.sb"; + b1.pb = b1; + return b1; +} +-(TestSlicingObjectsServerB*) twoElementCycle:(ICECurrent*)current +{ + TestSlicingObjectsServerB* b1 = [TestSlicingObjectsServerB b]; + b1.sb = @"B1.sb"; + TestSlicingObjectsServerB* b2 = [TestSlicingObjectsServerB b]; + b2.sb = @"B2.sb"; + b2.pb = b1; + b1.pb = b2; + return b1; +} +-(TestSlicingObjectsServerB*) D1AsB:(ICECurrent*)current +{ + TestSlicingObjectsServerD1* d1 = [TestSlicingObjectsServerD1 d1]; + d1.sb = @"D1.sb"; + d1.sd1 = @"D1.sd1"; + + TestSlicingObjectsServerD2* d2 = [TestSlicingObjectsServerD2 d2]; + d2.pb = d1; + d2.sb = @"D2.sb"; + d2.sd2 = @"D2.sd2"; + d2.pd2 = d1; + d1.pb = d2; + d1.pd1 = d2; + return d1; +} +-(TestSlicingObjectsServerD1*) D1AsD1:(ICECurrent*)current +{ + TestSlicingObjectsServerD1* d1 = [TestSlicingObjectsServerD1 d1]; + d1.sb = @"D1.sb"; + d1.sd1 = @"D1.sd1"; + TestSlicingObjectsServerD2* d2 = [TestSlicingObjectsServerD2 d2]; + d2.pb = d1; + d2.sb = @"D2.sb"; + d2.sd2 = @"D2.sd2"; + d2.pd2 = d1; + d1.pb = d2; + d1.pd1 = d2; + return d1; +} +-(TestSlicingObjectsServerB*) D2AsB:(ICECurrent*)current +{ + TestSlicingObjectsServerD2* d2 = [TestSlicingObjectsServerD2 d2]; + d2.sb = @"D2.sb"; + d2.sd2 = @"D2.sd2"; + TestSlicingObjectsServerD1* d1 = [TestSlicingObjectsServerD1 d1]; + d1.pb = d2; + d1.sb = @"D1.sb"; + d1.sd1 = @"D1.sd1"; + d1.pd1 = d2; + d2.pb = d1; + d2.pd2 = d1; + return d2; +} +-(void) paramTest1:(TestSlicingObjectsServerB**)p1 p2:(TestSlicingObjectsServerB**)p2 current:(ICECurrent*)current +{ + TestSlicingObjectsServerD1* d1 = [TestSlicingObjectsServerD1 d1]; + d1.sb = @"D1.sb"; + d1.sd1 = @"D1.sd1"; + TestSlicingObjectsServerD2* d2 = [TestSlicingObjectsServerD2 d2]; + d2.pb = d1; + d2.sb = @"D2.sb"; + d2.sd2 = @"D2.sd2"; + d2.pd2 = d1; + d1.pb = d2; + d1.pd1 = d2; + *p1 = d1; + *p2 = d2; +} +-(void) paramTest2:(TestSlicingObjectsServerB**)p1 p1:(TestSlicingObjectsServerB**)p2 current:(ICECurrent*)current +{ + [self paramTest1:p2 p2:p1 current:current]; +} +-(TestSlicingObjectsServerB*) paramTest3:(TestSlicingObjectsServerB**)p1 p2:(TestSlicingObjectsServerB**)p2 current:(ICECurrent*)current +{ + TestSlicingObjectsServerD2* d2 = [TestSlicingObjectsServerD2 d2]; + d2.sb = @"D2.sb (p1 1)"; + d2.pb = 0; + d2.sd2 = @"D2.sd2 (p1 1)"; + *p1 = d2; + + TestSlicingObjectsServerD1* d1 = [TestSlicingObjectsServerD1 d1]; + d1.sb = @"D1.sb (p1 2)"; + d1.pb = 0; + d1.sd1 = @"D1.sd2 (p1 2)"; + d1.pd1 = 0; + d2.pd2 = d1; + + TestSlicingObjectsServerD2* d4 = [TestSlicingObjectsServerD2 d2]; + d4.sb = @"D2.sb (p2 1)"; + d4.pb = 0; + d4.sd2 = @"D2.sd2 (p2 1)"; + *p2 = d4; + + TestSlicingObjectsServerD1* d3 = [TestSlicingObjectsServerD1 d1]; + d3.sb = @"D1.sb (p2 2)"; + d3.pb = 0; + d3.sd1 = @"D1.sd2 (p2 2)"; + d3.pd1 = 0; + d4.pd2 = d3; + + return d3; +} +-(TestSlicingObjectsServerB*) paramTest4:(TestSlicingObjectsServerB**)p1 current:(ICECurrent*)current +{ + TestSlicingObjectsServerD4* d4 = [TestSlicingObjectsServerD4 d4]; + d4.sb = @"D4.sb (1)"; + d4.pb = 0; + d4.p1 = [TestSlicingObjectsServerB b]; + d4.p1.sb = @"B.sb (1)"; + d4.p2 = [TestSlicingObjectsServerB b]; + d4.p2.sb = @"B.sb (2)"; + *p1 = d4; + return d4.p2; +} +-(TestSlicingObjectsServerB*) returnTest1:(TestSlicingObjectsServerB**)p1 p2:(TestSlicingObjectsServerB**)p2 current:(ICECurrent*)current +{ + [self paramTest1:p1 p2:p2 current:current]; + return *p1; +} +-(TestSlicingObjectsServerB*) returnTest2:(TestSlicingObjectsServerB**)p1 p1:(TestSlicingObjectsServerB**)p2 current:(ICECurrent*)current +{ + [self paramTest1:p2 p2:p1 current:current]; + return *p1; +} +-(TestSlicingObjectsServerB*) returnTest3:(TestSlicingObjectsServerB*)p1 p2:(TestSlicingObjectsServerB*)p2 current:(ICECurrent*)current +{ + return p1; +} +-(TestSlicingObjectsServerSS*) sequenceTest:(TestSlicingObjectsServerSS1*)p1 p2:(TestSlicingObjectsServerSS2*)p2 current:(ICECurrent*)current +{ + TestSlicingObjectsServerSS* ss = [TestSlicingObjectsServerSS ss]; + ss.c1 = p1; + ss.c2 = p2; + return ss; +} +-(TestSlicingObjectsServerBDict*) dictionaryTest:(TestSlicingObjectsServerMutableBDict*)bin + bout:(TestSlicingObjectsServerBDict**)bout current:(ICECurrent*)current +{ + int i; + *bout = [TestSlicingObjectsServerMutableBDict dictionary]; + for(i = 0; i < 10; ++i) + { + TestSlicingObjectsServerB* b = [bin objectForKey:[NSNumber numberWithInt:i]]; + TestSlicingObjectsServerD2* d2 = [TestSlicingObjectsServerD2 d2]; + d2.sb = b.sb; + d2.pb = b.pb; + d2.sd2 = @"D2"; + d2.pd2 = d2; + [(NSMutableDictionary*)*bout setObject:d2 forKey:[NSNumber numberWithInt:(i * 10)]]; + } + TestSlicingObjectsServerMutableBDict* r = [TestSlicingObjectsServerMutableBDict dictionary]; + for(i = 0; i < 10; ++i) + { + TestSlicingObjectsServerD1* d1 = [TestSlicingObjectsServerD1 d1]; + d1.sb = [NSString stringWithFormat:@"D1.%d",(i * 20)]; + d1.pb = (i == 0 ? nil : [r objectForKey:[NSNumber numberWithInt:((i - 1) * 20)]]); + d1.sd1 = d1.sb; + d1.pd1 = d1; + [r setObject:d1 forKey:[NSNumber numberWithInt:(i * 20)]]; + } + return r; +} + +-(TestSlicingObjectsServerPBase*) exchangePBase:(TestSlicingObjectsServerPBase*)pb + current:(ICECurrent*)current +{ + return pb; +} + +-(TestSlicingObjectsServerPreserved*) PBSUnknownAsPreserved:(ICECurrent*)current +{ + if([current.encoding isEqual:ICEEncoding_1_0]) + { + // + // 1.0 encoding doesn't support unmarshaling unknown classes even if referenced + // from unread slice. + // + return [[TestSlicingObjectsServerPSUnknown alloc] init:5 + ps:@"preserved" + psu:@"unknown" + graph:0 + cl:nil]; + } + else + { + return [[TestSlicingObjectsServerPSUnknown alloc] init:5 + ps:@"preserved" + psu:@"unknown" + graph:0 + cl:[[TestSlicingObjectsServerMyClass alloc] init:15]]; + } +} + +-(void) checkPBSUnknown:(TestSlicingObjectsServerPreserved*)p current:(ICECurrent*)current +{ + if([current.encoding isEqual:ICEEncoding_1_0]) + { + test(![p isKindOfClass:[TestSlicingObjectsServerPSUnknown class]]); + test(p.pi == 5); + test([p.ps isEqual:@"preserved"]); + } + else + { + test([p isKindOfClass:[TestSlicingObjectsServerPSUnknown class]]); + TestSlicingObjectsServerPSUnknown* pu = (TestSlicingObjectsServerPSUnknown*)p; + test(pu.pi == 5); + test([pu.ps isEqual:@"preserved"]); + test([pu.psu isEqual:@"unknown"]); + test(!pu.graph); + test(pu.cl && pu.cl.i == 15); + } +} + +-(TestSlicingObjectsServerPreserved*) PBSUnknownAsPreservedWithGraph:(ICECurrent*)current +{ + TestSlicingObjectsServerPSUnknown* r = [TestSlicingObjectsServerPSUnknown alloc]; + r.pi = 5; + r.ps = @"preserved"; + r.psu = @"unknown"; + r.graph = [TestSlicingObjectsServerPNode alloc]; + r.graph.next = [TestSlicingObjectsServerPNode alloc]; + r.graph.next.next = [TestSlicingObjectsServerPNode alloc]; + r.graph.next.next.next = r.graph; + return r; +} + +-(void) checkPBSUnknownWithGraph:(TestSlicingObjectsServerPreserved*) p current:(ICECurrent*)current +{ + if([current.encoding isEqual:ICEEncoding_1_0]) + { + test(![p isKindOfClass:[TestSlicingObjectsServerPSUnknown class]]); + test(p.pi == 5); + test([p.ps isEqual:@"preserved"]); + } + else + { + test([p isKindOfClass:[TestSlicingObjectsServerPSUnknown class]]); + TestSlicingObjectsServerPSUnknown* pu = (TestSlicingObjectsServerPSUnknown*)p; + test(pu.pi == 5); + test([pu.ps isEqual:@"preserved"]); + test([pu.psu isEqual:@"unknown"]); + test(pu.graph != pu.graph.next); + test(pu.graph.next != pu.graph.next.next); + test(pu.graph.next.next.next == pu.graph); + pu.graph.next.next.next = nil; // Break the cycle. + } +} + +-(TestSlicingObjectsServerPreserved*) PBSUnknown2AsPreservedWithGraph:(ICECurrent*)current +{ + TestSlicingObjectsServerPSUnknown2* r = [TestSlicingObjectsServerPSUnknown2 alloc]; + r.pi = 5; + r.ps = @"preserved"; + r.pb = r; + return r; +} + +-(void) checkPBSUnknown2WithGraph:(TestSlicingObjectsServerPreserved*) p current:(ICECurrent*)current +{ + if([current.encoding isEqual:ICEEncoding_1_0]) + { + test(![p isKindOfClass:[TestSlicingObjectsServerPSUnknown2 class]]); + test(p.pi == 5); + test([p.ps isEqual:@"preserved"]); + } + else + { + test([p isKindOfClass:[TestSlicingObjectsServerPSUnknown2 class]]); + TestSlicingObjectsServerPSUnknown2* pu = (TestSlicingObjectsServerPSUnknown2*)p; + test(pu.pi == 5); + test([pu.ps isEqual:@"preserved"]); + test(pu.pb == pu); + pu.pb = 0; // Break the cycle. + } +} + +-(TestSlicingObjectsServerPNode*) exchangePNode:(TestSlicingObjectsServerPNode*)pn current:(ICECurrent*)current +{ + return pn; +} + +-(void) throwBaseAsBase:(ICECurrent*)current +{ + TestSlicingObjectsServerBaseException* be = [TestSlicingObjectsServerBaseException baseException]; + be.sbe = @"sbe"; + be.pb = [TestSlicingObjectsServerB b]; + be.pb.sb = @"sb"; + be.pb.pb = be.pb; + @throw be; +} +-(void) throwDerivedAsBase:(ICECurrent*)current +{ + TestSlicingObjectsServerDerivedException* de = [TestSlicingObjectsServerDerivedException derivedException]; + de.sbe = @"sbe"; + de.pb = [TestSlicingObjectsServerB b]; + de.pb.sb = @"sb1"; + de.pb.pb = de.pb; + de.sde = @"sde1"; + de.pd1 = [TestSlicingObjectsServerD1 d1]; + de.pd1.sb = @"sb2"; + de.pd1.pb = de.pd1; + de.pd1.sd1 = @"sd2"; + de.pd1.pd1 = de.pd1; + @throw de; +} +-(void) throwDerivedAsDerived:(ICECurrent*)current +{ + TestSlicingObjectsServerDerivedException* de = [TestSlicingObjectsServerDerivedException derivedException]; + de.sbe = @"sbe"; + de.pb = [TestSlicingObjectsServerB b]; + de.pb.sb = @"sb1"; + de.pb.pb = de.pb; + de.sde = @"sde1"; + de.pd1 = [TestSlicingObjectsServerD1 d1]; + de.pd1.sb = @"sb2"; + de.pd1.pb = de.pd1; + de.pd1.sd1 = @"sd2"; + de.pd1.pd1 = de.pd1; + @throw de; +} +-(void) throwUnknownDerivedAsBase:(ICECurrent*)current +{ + TestSlicingObjectsServerD2* d2 = [TestSlicingObjectsServerD2 d2]; + d2.sb = @"sb d2"; + d2.pb = d2; + d2.sd2 = @"sd2 d2"; + d2.pd2 = d2; + + TestSlicingObjectsServerUnknownDerivedException* ude = [TestSlicingObjectsServerUnknownDerivedException unknownDerivedException]; + ude.sbe = @"sbe"; + ude.pb = d2; + ude.sude = @"sude"; + ude.pd2 = d2; + @throw ude; +} +-(void) throwPreservedException:(ICECurrent*)current +{ + TestSlicingObjectsServerPSUnknownException* ue = [TestSlicingObjectsServerPSUnknownException psUnknownException]; + ue.p = [TestSlicingObjectsServerPSUnknown2 psUnknown2]; + ue.p.pi = 5; + ue.p.ps = @"preserved"; + ue.p.pb = ue.p; + if(ex_ != nil) + { + ex_.p.pb = nil; + ICE_RELEASE(ex_); + } + ex_ = ICE_RETAIN(ue); + @throw ue; +} +-(void) useForward:(TestSlicingObjectsServerForward**)f current:(ICECurrent*)current +{ + *f = [TestSlicingObjectsServerForward forward]; + (*f).h = [TestSlicingObjectsServerHidden hidden]; + (*f).h.f = *f; +} +-(void) shutdown:(ICECurrent*)current +{ + if(ex_ != nil) + { + ex_.p.pb = nil; + ICE_RELEASE(ex_); + } + [[current.adapter getCommunicator] shutdown]; +} +@end diff --git a/objective-c/test/Ice/slicing/objects/run.py b/objective-c/test/Ice/slicing/objects/run.py new file mode 100755 index 00000000000..2af0d5cf76a --- /dev/null +++ b/objective-c/test/Ice/slicing/objects/run.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python +# ********************************************************************** +# +# Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +# +# This copy of Ice is licensed to you under the terms described in the +# ICE_LICENSE file included in this distribution. +# +# ********************************************************************** + +import os, sys + +path = [ ".", "..", "../..", "../../..", "../../../..", "../../../../..", "../../../../../.." ] +head = os.path.dirname(sys.argv[0]) +if len(head) > 0: + path = [os.path.join(head, p) for p in path] +path = [os.path.abspath(p) for p in path if os.path.exists(os.path.join(p, "scripts", "TestUtil.py")) ] +if len(path) == 0: + raise RuntimeError("can't find toplevel directory!") +sys.path.append(os.path.join(path[0], "scripts")) +import TestUtil + +print("Running test with sliced format.") +TestUtil.clientServerTest() + +print("Running test with 1.0 encoding.") +TestUtil.clientServerTest(additionalClientOptions="--Ice.Default.EncodingVersion=1.0", + additionalServerOptions="--Ice.Default.EncodingVersion=1.0") diff --git a/objective-c/test/Ice/stream/.gitignore b/objective-c/test/Ice/stream/.gitignore new file mode 100644 index 00000000000..deeebc026e0 --- /dev/null +++ b/objective-c/test/Ice/stream/.gitignore @@ -0,0 +1,7 @@ +// Generated by makegitignore.py + +// IMPORTANT: Do not edit this file -- any edits made here will be lost! +client +.depend +StreamTest.m +StreamTest.h diff --git a/objective-c/test/Ice/stream/Client.m b/objective-c/test/Ice/stream/Client.m new file mode 100644 index 00000000000..415d113787e --- /dev/null +++ b/objective-c/test/Ice/stream/Client.m @@ -0,0 +1,973 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <TestCommon.h> +#import <StreamTest.h> + +static int +run(id<ICECommunicator> communicator) +{ + id<ICEInputStream> in; + id<ICEOutputStream> out; + NSMutableData* data; + + // + // Test the stream api. + // + tprintf("testing primitive types... "); + + { + NSData* byte = [NSData data]; + in = [ICEUtil createInputStream:communicator data:byte]; + } + + { + out = [ICEUtil createOutputStream:communicator]; + [out startEncapsulation]; + [out writeBool:YES]; + [out endEncapsulation]; + data = [out finished]; + NSData* d = [out finishedNoCopy]; + test([d isEqual:data]); + out = nil; + + in = [ICEUtil createInputStream:communicator data:data]; + [in startEncapsulation]; + BOOL v; + v = [in readBool]; + test(v); + [in endEncapsulation]; + + in = [ICEUtil wrapInputStream:communicator data:data]; + [in startEncapsulation]; + v = [in readBool]; + test(v); + [in endEncapsulation]; + } + + { + NSData* byte = [NSData data]; + in = [ICEUtil createInputStream:communicator data:byte]; + @try + { + BOOL v; + v = [in readBool]; + test(NO); + } + @catch(ICEUnmarshalOutOfBoundsException* ex) + { + } + } + + { + out = [ICEUtil createOutputStream:communicator]; + [out writeBool:YES]; + data = [out finished]; + in = [ICEUtil createInputStream:communicator data:data]; + BOOL v = [in readBool]; + test(v); + } + + { + out = [ICEUtil createOutputStream:communicator]; + [out writeByte:(ICEByte)1]; + data = [out finished]; + in = [ICEUtil createInputStream:communicator data:data]; + ICEByte v = [in readByte]; + test(v == 1); + } + + { + out = [ICEUtil createOutputStream:communicator]; + [out writeShort:(ICEShort)2]; + data = [out finished]; + in = [ICEUtil createInputStream:communicator data:data]; + ICEShort v = [in readShort]; + test(v == 2); + } + + { + out = [ICEUtil createOutputStream:communicator]; + [out writeInt:(ICEInt)3]; + data = [out finished]; + in = [ICEUtil createInputStream:communicator data:data]; + ICEInt v; + v = [in readInt]; + test(v == 3); + } + + { + out = [ICEUtil createOutputStream:communicator]; + [out writeLong:(ICELong)4]; + data = [out finished]; + in = [ICEUtil createInputStream:communicator data:data]; + ICELong v; + v = [in readLong]; + test(v == 4); + } + + { + out = [ICEUtil createOutputStream:communicator]; + [out writeFloat:(ICEFloat)5.0]; + data = [out finished]; + in = [ICEUtil createInputStream:communicator data:data]; + ICEFloat v; + v = [in readFloat]; + test(v == 5.0); + } + + { + out = [ICEUtil createOutputStream:communicator]; + [out writeDouble:(ICEDouble)6.0]; + data = [out finished]; + in = [ICEUtil createInputStream:communicator data:data]; + ICEDouble v; + v = [in readDouble]; + test(v == 6.0); + } + + { + out = [ICEUtil createOutputStream:communicator]; + [out writeString:@"hello world"]; + data = [out finished]; + in = [ICEUtil createInputStream:communicator data:data]; + NSString* v; + v = [in readString]; + test([v isEqualToString:@"hello world"]); + } + + tprintf("ok\n"); + + tprintf("testing constructed types... "); + + { + out = [ICEUtil createOutputStream:communicator]; + [TestStreamMyEnumHelper write:@(TestStreamenum3) stream:out]; + data = [out finished]; + in = [ICEUtil createInputStream:communicator data:data]; + id e = [TestStreamMyEnumHelper read:in]; + test([e isEqual:@(TestStreamenum3)]); + } + + { + out = [ICEUtil createOutputStream:communicator]; + TestStreamSmallStruct* s = [TestStreamSmallStruct smallStruct]; + s.bo = YES; + s.by = 1; + s.sh = 2; + s.i = 3; + s.l = 4; + s.f = 5.0; + s.d = 6.0; + s.str = @"7"; + s.e = TestStreamenum2; + s.p = [TestStreamMyClassPrx uncheckedCast:[communicator stringToProxy:@"test:default"]]; + [TestStreamSmallStructHelper write:s stream:out]; + data = [out finished]; + in = [ICEUtil createInputStream:communicator data:data]; + TestStreamSmallStruct* s2 = [TestStreamSmallStructHelper read:in]; + test([s2 isEqual:s]); + } + + { + out = [ICEUtil createOutputStream:communicator]; + TestStreamClassStruct* s = [TestStreamClassStruct classStruct]; + s.i = 10; + [TestStreamClassStructHelper write:s stream:out]; + data = [out finished]; + in = [ICEUtil createInputStream:communicator data:data]; + TestStreamClassStruct* s2 = [TestStreamClassStructHelper read:in]; + test(s2.i == s.i); + } + + { + out = [ICEUtil createOutputStream:communicator]; + TestStreamOptionalClass* o = [TestStreamOptionalClass optionalClass]; + o.bo = NO; + o.by = 5; + o.sh = 4; + o.i = 3; + [TestStreamOptionalClassHelper write:o stream:out]; + [out writePendingObjects]; + data = [out finished]; + in = [ICEUtil createInputStream:communicator data:data]; + TestStreamOptionalClass* ICE_AUTORELEASING_QUALIFIER o2; + [TestStreamOptionalClassHelper read:&o2 stream:in]; + [in readPendingObjects]; + test(o2.bo == o.bo); + test(o2.by == o.by); + if([in getEncoding] == ICEEncoding_1_0) + { + test(![o2 hasSh]); + test(![o2 hasI]); + } + else + { + test(o2.sh == o.sh); + test(o2.i == o.i); + } + } + + { + out = [ICEUtil createOutputStream:communicator encoding:ICEEncoding_1_0]; + TestStreamOptionalClass* o = [TestStreamOptionalClass optionalClass]; + o.bo = NO; + o.by = 5; + o.sh = 4; + o.i = 3; + [TestStreamOptionalClassHelper write:o stream:out]; + [out writePendingObjects]; + data = [out finished]; + in = [ICEUtil createInputStream:communicator data:data encoding:ICEEncoding_1_0]; + TestStreamOptionalClass* ICE_AUTORELEASING_QUALIFIER o2; + [TestStreamOptionalClassHelper read:&o2 stream:in]; + [in readPendingObjects]; + test(o2.bo == o.bo); + test(o2.by == o.by); + test(![o2 hasSh]); + test(![o2 hasI]); + } + + { + BOOL buf[] = { YES, YES, NO, YES }; + ICEBoolSeq* arr = [ICEBoolSeq dataWithBytes:buf length:sizeof(buf)]; + + out = [ICEUtil createOutputStream:communicator]; + [ICEBoolSeqHelper write:arr stream:out]; + data = [out finished]; + + in = [ICEUtil createInputStream:communicator data:data]; + ICEBoolSeq* arr2 = [ICEBoolSeqHelper read:in]; + test([arr2 isEqual:arr]); + + TestStreamMutableBoolSS* arrS = [TestStreamMutableBoolSS array]; + [arrS addObject:arr]; + [arrS addObject:[ICEBoolSeq data]]; + [arrS addObject:arr]; + + out = [ICEUtil createOutputStream:communicator]; + [TestStreamBoolSSHelper write:arrS stream:out]; + data = [out finished]; + + in = [ICEUtil createInputStream:communicator data:data]; + TestStreamBoolSS* arr2S = [TestStreamBoolSSHelper read:in]; + test([arr2S isEqual:arrS]); + } + + { + ICEByte buf[] = { 0x01, 0x11, 0x12, 0x22 }; + ICEByteSeq* arr = [ICEByteSeq dataWithBytes:buf length:sizeof(buf)]; + + out = [ICEUtil createOutputStream:communicator]; + [ICEByteSeqHelper write:arr stream:out]; + data = [out finished]; + in = [ICEUtil createInputStream:communicator data:data]; + ICEByteSeq* arr2 = [ICEByteSeqHelper read:in]; + test([arr2 isEqual:arr]); + + TestStreamMutableByteSS* arrS = [TestStreamMutableByteSS array]; + [arrS addObject:arr]; + [arrS addObject:[ICEByteSeq data]]; + [arrS addObject:arr]; + + out = [ICEUtil createOutputStream:communicator]; + [TestStreamByteSSHelper write:arrS stream:out]; + data = [out finished]; + + in = [ICEUtil createInputStream:communicator data:data]; + TestStreamByteSS* arr2S = [TestStreamByteSSHelper read:in]; + test([arr2S isEqual:arrS]); + } + + { + ICEShort buf[] = { 1, 11, 12, 22 }; + ICEShortSeq* arr = [ICEShortSeq dataWithBytes:buf length:sizeof(buf)]; + + out = [ICEUtil createOutputStream:communicator]; + [ICEShortSeqHelper write:arr stream:out]; + data = [out finished]; + in = [ICEUtil createInputStream:communicator data:data]; + ICEShortSeq* arr2 = [ICEShortSeqHelper read:in]; + test([arr2 isEqual:arr]); + + TestStreamMutableShortSS* arrS = [TestStreamMutableShortSS array]; + [arrS addObject:arr]; + [arrS addObject:[ICEShortSeq data]]; + [arrS addObject:arr]; + + out = [ICEUtil createOutputStream:communicator]; + [TestStreamShortSSHelper write:arrS stream:out]; + data = [out finished]; + + in = [ICEUtil createInputStream:communicator data:data]; + TestStreamShortSS* arr2S = [TestStreamShortSSHelper read:in]; + test([arr2S isEqual:arrS]); + } + + { + ICEInt buf[] = { 1, 11, 12, 22 }; + ICEIntSeq* arr = [ICEIntSeq dataWithBytes:buf length:sizeof(buf)]; + + out = [ICEUtil createOutputStream:communicator]; + [ICEIntSeqHelper write:arr stream:out]; + data = [out finished]; + in = [ICEUtil createInputStream:communicator data:data]; + ICEIntSeq* arr2 = [ICEIntSeqHelper read:in]; + test([arr2 isEqual:arr]); + + TestStreamMutableIntSS* arrS = [TestStreamMutableIntSS array]; + [arrS addObject:arr]; + [arrS addObject:[ICEIntSeq data]]; + [arrS addObject:arr]; + + out = [ICEUtil createOutputStream:communicator]; + [TestStreamIntSSHelper write:arrS stream:out]; + data = [out finished]; + + in = [ICEUtil createInputStream:communicator data:data]; + TestStreamIntSS* arr2S = [TestStreamIntSSHelper read:in]; + test([arr2S isEqual:arrS]); + } + + { + ICELong buf[] = { 1, 11, 12, 22 }; + ICELongSeq* arr = [ICELongSeq dataWithBytes:buf length:sizeof(buf)]; + + out = [ICEUtil createOutputStream:communicator]; + [ICELongSeqHelper write:arr stream:out]; + data = [out finished]; + in = [ICEUtil createInputStream:communicator data:data]; + ICELongSeq* arr2 = [ICELongSeqHelper read:in]; + test([arr2 isEqual:arr]); + + TestStreamMutableLongSS* arrS = [TestStreamMutableLongSS array]; + [arrS addObject:arr]; + [arrS addObject:[ICELongSeq data]]; + [arrS addObject:arr]; + + out = [ICEUtil createOutputStream:communicator]; + [TestStreamLongSSHelper write:arrS stream:out]; + data = [out finished]; + + in = [ICEUtil createInputStream:communicator data:data]; + TestStreamLongSS* arr2S = [TestStreamLongSSHelper read:in]; + test([arr2S isEqual:arrS]); + } + + { + ICEFloat buf[] = { 1, 2, 3, 4 }; + ICEFloatSeq* arr = [ICEFloatSeq dataWithBytes:buf length:sizeof(buf)]; + + out = [ICEUtil createOutputStream:communicator]; + [ICEFloatSeqHelper write:arr stream:out]; + data = [out finished]; + in = [ICEUtil createInputStream:communicator data:data]; + ICEFloatSeq* arr2 = [ICEFloatSeqHelper read:in]; + test([arr2 isEqual:arr]); + + TestStreamMutableFloatSS* arrS = [TestStreamMutableFloatSS array]; + [arrS addObject:arr]; + [arrS addObject:[ICEFloatSeq data]]; + [arrS addObject:arr]; + + out = [ICEUtil createOutputStream:communicator]; + [TestStreamFloatSSHelper write:arrS stream:out]; + data = [out finished]; + + in = [ICEUtil createInputStream:communicator data:data]; + TestStreamFloatSS* arr2S = [TestStreamFloatSSHelper read:in]; + test([arr2S isEqual:arrS]); + } + + { + ICEDouble buf[] = { 1, 2, 3, 4 }; + ICEDoubleSeq* arr = [ICEDoubleSeq dataWithBytes:buf length:sizeof(buf)]; + + out = [ICEUtil createOutputStream:communicator]; + [ICEDoubleSeqHelper write:arr stream:out]; + data = [out finished]; + in = [ICEUtil createInputStream:communicator data:data]; + ICEDoubleSeq* arr2 = [ICEDoubleSeqHelper read:in]; + test([arr2 isEqual:arr]); + + TestStreamMutableDoubleSS* arrS = [TestStreamMutableDoubleSS array]; + [arrS addObject:arr]; + [arrS addObject:[ICEDoubleSeq data]]; + [arrS addObject:arr]; + + out = [ICEUtil createOutputStream:communicator]; + [TestStreamDoubleSSHelper write:arrS stream:out]; + data = [out finished]; + + in = [ICEUtil createInputStream:communicator data:data]; + TestStreamDoubleSS* arr2S = [TestStreamDoubleSSHelper read:in]; + test([arr2S isEqual:arrS]); + } + + { + ICEMutableStringSeq* arr = [ICEMutableStringSeq array]; + [arr addObject:@"string1"]; + [arr addObject:@"string2"]; + [arr addObject:@"string3"]; + [arr addObject:@"string4"]; + out = [ICEUtil createOutputStream:communicator]; + [ICEStringSeqHelper write:arr stream:out]; + data = [out finished]; + in = [ICEUtil createInputStream:communicator data:data]; + ICEStringSeq* arr2 = [ICEStringSeqHelper read:in]; + test([arr2 isEqual:arr]); + + TestStreamMutableStringSS* arrS = [TestStreamMutableStringSS array]; + [arrS addObject:arr]; + [arrS addObject:[ICEStringSeq array]]; + [arrS addObject:arr]; + + out = [ICEUtil createOutputStream:communicator]; + [TestStreamStringSSHelper write:arrS stream:out]; + data = [out finished]; + + in = [ICEUtil createInputStream:communicator data:data]; + TestStreamStringSS* arr2S = [TestStreamStringSSHelper read:in]; + test([arr2S isEqual:arrS]); + } + + { + TestStreamMyEnum buf[] = { TestStreamenum3, TestStreamenum2, TestStreamenum1, TestStreamenum2 }; + TestStreamMutableMyEnumS* arr = [TestStreamMutableMyEnumS dataWithBytes:buf length:sizeof(buf)]; + + out = [ICEUtil createOutputStream:communicator]; + [TestStreamMyEnumSHelper write:arr stream:out]; + data = [out finished]; + in = [ICEUtil createInputStream:communicator data:data]; + TestStreamMyEnumS* arr2 = [TestStreamMyEnumSHelper read:in]; + test([arr2 isEqual:arr]); + + TestStreamMutableMyEnumSS* arrS = [TestStreamMutableMyEnumSS array]; + [arrS addObject:arr]; + [arrS addObject:[TestStreamMyEnumS data]]; + [arrS addObject:arr]; + + out = [ICEUtil createOutputStream:communicator]; + [TestStreamMyEnumSSHelper write:arrS stream:out]; + data = [out finished]; + + in = [ICEUtil createInputStream:communicator data:data]; + TestStreamMyEnumSS* arr2S = [TestStreamMyEnumSSHelper read:in]; + test([arr2S isEqual:arrS]); + } + + { + TestStreamMutableSmallStructS* arr = [TestStreamMutableSmallStructS array]; + for(int i = 0; i < 4; ++i) + { + TestStreamSmallStruct* s = [TestStreamSmallStruct smallStruct]; + s.bo = YES; + s.by = 1; + s.sh = 2; + s.i = 3; + s.l = 4; + s.f = 5.0; + s.d = 6.0; + s.str = @"7"; + s.e = TestStreamenum2; + s.p = [TestStreamMyClassPrx uncheckedCast:[communicator stringToProxy:@"test:default"]]; + [arr addObject:s]; + } + out = [ICEUtil createOutputStream:communicator]; + [TestStreamSmallStructSHelper write:arr stream:out]; + [out writePendingObjects]; + data = [out finished]; + in = [ICEUtil createInputStream:communicator data:data]; + TestStreamSmallStructS* arr2 = [TestStreamSmallStructSHelper read:in]; + [in readPendingObjects]; + test([arr2 count] == [arr count]); + for(int j = 0; j < [arr2 count]; ++j) + { + test([[arr objectAtIndex:j] isEqual:[arr2 objectAtIndex:j]]); + } + + TestStreamMutableSmallStructSS* arrS = [TestStreamMutableSmallStructSS array]; + [arrS addObject:arr]; + [arrS addObject:[TestStreamSmallStructS array]]; + [arrS addObject:arr]; + + out = [ICEUtil createOutputStream:communicator]; + [TestStreamSmallStructSSHelper write:arrS stream:out]; + data = [out finished]; + + in = [ICEUtil createInputStream:communicator data:data]; + TestStreamSmallStructSS* arr2S = [TestStreamSmallStructSSHelper read:in]; + test([arr2S isEqual:arrS]); + } + + { + TestStreamMutableMyClassS* arr = [TestStreamMutableMyClassS array]; + for(int i = 0; i < 4; ++i) + { + TestStreamMyClass* c = [TestStreamMyClass myClass]; + c.c = c; + c.o = c; + c.s = [TestStreamSmallStruct smallStruct]; + c.s.e = TestStreamenum2; + + BOOL boolS[] = { YES, NO, YES, NO }; + c.seq1 = [NSMutableData dataWithBytes:boolS length:sizeof(boolS)]; + + ICEByte byteS[] = { 1, 2, 3, 4 }; + c.seq2 = [NSMutableData dataWithBytes:byteS length:sizeof(byteS)]; + + ICEShort shortS[] = { 1, 2, 3, 4 }; + c.seq3 = [NSMutableData dataWithBytes:shortS length:sizeof(shortS)]; + + ICEInt intS[] = { 1, 2, 3, 4 }; + c.seq4 = [NSMutableData dataWithBytes:intS length:sizeof(intS)]; + + ICELong longS[] = { 1, 2, 3, 4 }; + c.seq5 = [NSMutableData dataWithBytes:longS length:sizeof(longS)]; + + ICEFloat floatS[] = { 1, 2, 3, 4 }; + c.seq6 = [NSMutableData dataWithBytes:floatS length:sizeof(floatS)]; + + ICEDouble doubleS[] = { 1, 2, 3, 4 }; + c.seq7 = [NSMutableData dataWithBytes:doubleS length:sizeof(doubleS)]; + + c.seq8 = [ICEMutableStringSeq array]; + [(ICEMutableStringSeq*)c.seq8 addObject:@"string1"]; + [(ICEMutableStringSeq*)c.seq8 addObject:@"string2"]; + [(ICEMutableStringSeq*)c.seq8 addObject:@"string3"]; + [(ICEMutableStringSeq*)c.seq8 addObject:@"string4"]; + + TestStreamMyEnum enumS[] = { TestStreamenum3, TestStreamenum2, TestStreamenum1 }; + c.seq9 = [NSMutableData dataWithBytes:enumS length:sizeof(enumS)]; + + c.d = [NSDictionary dictionaryWithObject:[TestStreamMyClass myClass] forKey:@"hi"]; + [arr addObject:c]; + } + out = [ICEUtil createOutputStream:communicator]; + [TestStreamMyClassSHelper write:arr stream:out]; + [out writePendingObjects]; + data = [out finished]; + in = [ICEUtil createInputStream:communicator data:data]; + TestStreamMyClassS* arr2 = [TestStreamMyClassSHelper read:in]; + [in readPendingObjects]; + test([arr2 count] > 0); + test([arr2 count] == [arr count]); + for(int j = 0; j < [arr2 count]; ++j) + { + TestStreamMyClass* e = [arr2 objectAtIndex:j]; + TestStreamMyClass* f = [arr objectAtIndex:j]; + test(e); + test(e.c == e); + test(e.o == e); + test(e.s.e == TestStreamenum2); + test([e.seq1 isEqual:f.seq1]); + test([e.seq2 isEqual:f.seq2]); + test([e.seq3 isEqual:f.seq3]); + test([e.seq4 isEqual:f.seq4]); + test([e.seq5 isEqual:f.seq5]); + test([e.seq6 isEqual:f.seq6]); + test([e.seq7 isEqual:f.seq7]); + test([e.seq8 isEqual:f.seq8]); + test([e.seq9 isEqual:f.seq9]); + test([e.d objectForKey:@"hi"] != nil); + + e.c = nil; + e.o = nil; + f.c = nil; + f.o = nil; + } + + TestStreamMutableMyClassSS* arrS = [TestStreamMutableMyClassSS array]; + [arrS addObject:arr]; + [arrS addObject:[TestStreamMyClassS array]]; + [arrS addObject:arr]; + + out = [ICEUtil createOutputStream:communicator]; + [TestStreamMyClassSSHelper write:arrS stream:out]; + data = [out finished]; + + in = [ICEUtil createInputStream:communicator data:data]; + TestStreamMyClassSS* arr2S = [TestStreamMyClassSSHelper read:in]; + test([arr2S count] == [arrS count]); + } + + { + TestStreamMyInterface ICE_AUTORELEASING_QUALIFIER * i = [TestStreamMyInterface new]; + out = [ICEUtil createOutputStream:communicator]; + [TestStreamMyInterfaceHelper write:i stream:out]; + [out writePendingObjects]; + data = [out finished]; + in = [ICEUtil createInputStream:communicator data:data]; + i = nil; + [TestStreamMyInterfaceHelper read:&i stream:in]; + [in readPendingObjects]; + test(i != nil); + } + + // + // ObjectWriter/ObjectReader not supported. + // + // { + // out = [ICEUtil createOutputStream:communicator]; + // TestStreamMyClass* obj = [TestStreamMyClass myClass]; + // obj.s.e = TestStreamenum2; + // TestObjectWriterPtr writer = new TestObjectWriter:obj]; + // [out writeObject:writer]; + // [out writePendingObjects]; + // data = [out finished]; + // test([writer called); + // } + + // { + // out = [ICEUtil createOutputStream:communicator]; + // TestStreamMyClassPtr obj = new TestStreamMyClass; + // obj->s.e = TestStreamenum2; + // TestObjectWriterPtr writer = new TestObjectWriter:obj]; + // [out writeObject:writer]; + // [out writePendingObjects]; + // data = [out finished]; + // test([writer called]); + // [factoryWrapper setFactory:new TestObjectFactory]; + // in = [ICEUtil createInputStream:communicator data:data]; + // TestReadObjectCallbackPtr cb = new TestReadObjectCallback; + // [in readObject:cb]; + // [in readPendingObjects]; + // test([cb obj]); + // TestObjectReaderPtr reader = TestObjectReaderPtr::dynamicCast(cb->obj); + // test(reader); + // test([reader called]); + // test([reader obj]); + // test([reader obj]->s.e == TestStreamenum2); + // [factoryWrapper setFactory:0]; + // } + + { + out = [ICEUtil createOutputStream:communicator]; + TestStreamMyException* ex = [TestStreamMyException myException]; + TestStreamMyClass* c = [TestStreamMyClass myClass]; + c.c = c; + c.o = c; + c.s = [TestStreamSmallStruct smallStruct]; + c.s.e = TestStreamenum2; + + BOOL boolS[] = { YES, NO, YES, NO }; + c.seq1 = [NSMutableData dataWithBytes:boolS length:sizeof(boolS)]; + + ICEByte byteS[] = { 1, 2, 3, 4 }; + c.seq2 = [NSMutableData dataWithBytes:byteS length:sizeof(byteS)]; + + ICEShort shortS[] = { 1, 2, 3, 4 }; + c.seq3 = [NSMutableData dataWithBytes:shortS length:sizeof(shortS)]; + + ICEInt intS[] = { 1, 2, 3, 4 }; + c.seq4 = [NSMutableData dataWithBytes:intS length:sizeof(intS)]; + + ICELong longS[] = { 1, 2, 3, 4 }; + c.seq5 = [NSMutableData dataWithBytes:longS length:sizeof(longS)]; + + ICEFloat floatS[] = { 1, 2, 3, 4 }; + c.seq6 = [NSMutableData dataWithBytes:floatS length:sizeof(floatS)]; + + ICEDouble doubleS[] = { 1, 2, 3, 4 }; + c.seq7 = [NSMutableData dataWithBytes:doubleS length:sizeof(doubleS)]; + + c.seq8 = [ICEMutableStringSeq array]; + [(ICEMutableStringSeq*)c.seq8 addObject:@"string1"]; + [(ICEMutableStringSeq*)c.seq8 addObject:@"string2"]; + [(ICEMutableStringSeq*)c.seq8 addObject:@"string3"]; + [(ICEMutableStringSeq*)c.seq8 addObject:@"string4"]; + + TestStreamMyEnum enumS[] = { TestStreamenum3, TestStreamenum2, TestStreamenum1 }; + c.seq9 = [NSMutableData dataWithBytes:enumS length:sizeof(enumS)]; + + c.d = [NSDictionary dictionaryWithObject:[TestStreamMyClass myClass] forKey:@"hi"]; + + ex.c = c; + + [out writeException:ex]; + data = [out finished]; + + in = [ICEUtil createInputStream:communicator data:data]; + @try + { + [in throwException]; + test(NO); + } + @catch(TestStreamMyException* ex1) + { + test(ex1.c); + test(ex1.c.c == ex1.c); + test(ex1.c.o == ex1.c); + test(ex1.c.s.e == TestStreamenum2); + test([ex1.c.seq1 isEqual:c.seq1]); + test([ex1.c.seq2 isEqual:c.seq2]); + test([ex1.c.seq3 isEqual:c.seq3]); + test([ex1.c.seq4 isEqual:c.seq4]); + test([ex1.c.seq5 isEqual:c.seq5]); + test([ex1.c.seq6 isEqual:c.seq6]); + test([ex1.c.seq7 isEqual:c.seq7]); + test([ex1.c.seq8 isEqual:c.seq8]); + test([ex1.c.seq9 isEqual:c.seq9]); + test([ex1.c.d objectForKey:@"hi"] != nil); + + ex1.c.c = nil; + ex1.c.o = nil; + c.c = nil; + c.o = nil; + } + } + + { + TestStreamMutableByteBoolD* dict = [TestStreamMutableByteBoolD dictionary]; + [dict setObject:@YES forKey:@(0x04)]; + [dict setObject:@NO forKey:@(0x01)]; + out = [ICEUtil createOutputStream:communicator]; + [TestStreamByteBoolDHelper write:dict stream:out]; + data = [out finished]; + in = [ICEUtil createInputStream:communicator data:data]; + TestStreamByteBoolD* dict2 = [TestStreamByteBoolDHelper read:in]; + test([dict2 isEqual:dict]); + } + + { + TestStreamMutableShortIntD* dict = [TestStreamMutableShortIntD dictionary]; + [dict setObject:@9 forKey:@1]; + [dict setObject:@8 forKey:@4]; + out = [ICEUtil createOutputStream:communicator]; + [TestStreamShortIntDHelper write:dict stream:out]; + data = [out finished]; + in = [ICEUtil createInputStream:communicator data:data]; + TestStreamShortIntD* dict2 = [TestStreamShortIntDHelper read:in]; + test([dict2 isEqual:dict]); + } + + { + TestStreamMutableLongFloatD* dict = [TestStreamMutableLongFloatD dictionary]; + [dict setObject:@0.51f forKey:@123809828]; + [dict setObject:@0.56f forKey:@123809829]; + out = [ICEUtil createOutputStream:communicator]; + [TestStreamLongFloatDHelper write:dict stream:out]; + data = [out finished]; + in = [ICEUtil createInputStream:communicator data:data]; + TestStreamLongFloatD* dict2 = [TestStreamLongFloatDHelper read:in]; + test([dict2 isEqual:dict]); + } + + { + TestStreamMutableStringStringD* dict = [TestStreamMutableStringStringD dictionary]; + [dict setObject:@"value1" forKey:@"key1"]; + [dict setObject:@"value2" forKey:@"key2"]; + out = [ICEUtil createOutputStream:communicator]; + [TestStreamStringStringDHelper write:dict stream:out]; + data = [out finished]; + in = [ICEUtil createInputStream:communicator data:data]; + TestStreamStringStringD* dict2 = [TestStreamStringStringDHelper read:in]; + test([dict2 isEqual:dict]); + } + + { + TestStreamMutableStringMyClassD* dict = [TestStreamMutableStringMyClassD dictionary]; + TestStreamMyClass* c = [TestStreamMyClass myClass]; + c.s = [TestStreamSmallStruct smallStruct]; + c.s.e = TestStreamenum2; + [dict setObject:c forKey:@"key1"]; + c = [TestStreamMyClass myClass]; + c.s = [TestStreamSmallStruct smallStruct]; + c.s.e = TestStreamenum3; + [dict setObject:c forKey:@"key2"]; + out = [ICEUtil createOutputStream:communicator]; + [TestStreamStringMyClassDHelper write:dict stream:out]; + [out writePendingObjects]; + data = [out finished]; + in = [ICEUtil createInputStream:communicator data:data]; + TestStreamStringMyClassD* dict2 = [TestStreamStringMyClassDHelper read:in]; + [in readPendingObjects]; + test([dict2 count] == [dict count]); + test([dict2 objectForKey:@"key1"] != nil && + ((TestStreamMyClass*)[dict2 objectForKey:@"key1"]).s.e == TestStreamenum2); + test([dict2 objectForKey:@"key2"] != nil && + ((TestStreamMyClass*)[dict2 objectForKey:@"key2"]).s.e == TestStreamenum3); + + } + + { + out = [ICEUtil createOutputStream:communicator]; + [TestStreamSubNestedEnumHelper write:@(TestStreamSubnestedEnum3) stream:out]; + data = [out finished]; + in = [ICEUtil createInputStream:communicator data:data]; + id e = [TestStreamSubNestedEnumHelper read:in]; + test([e isEqual:@(TestStreamSubnestedEnum3)]); + } + + { + out = [ICEUtil createOutputStream:communicator]; + TestStreamSubNestedStruct* s = [TestStreamSubNestedStruct nestedStruct]; + s.bo = YES; + s.by = 1; + s.sh = 2; + s.i = 3; + s.l = 4; + s.f = 5.0; + s.d = 6.0; + s.str = @"7"; + s.e = TestStreamSubnestedEnum2; + [TestStreamSubNestedStructHelper write:s stream:out]; + data = [out finished]; + in = [ICEUtil createInputStream:communicator data:data]; + TestStreamSubNestedStruct* s2 = [TestStreamSubNestedStructHelper read:in]; + test([s2 isEqual:s]); + } + + { + out = [ICEUtil createOutputStream:communicator]; + TestStreamSubNestedClassStruct* s = [TestStreamSubNestedClassStruct nestedClassStruct]; + s.i = 10; + [TestStreamSubNestedClassStructHelper write:s stream:out]; + data = [out finished]; + in = [ICEUtil createInputStream:communicator data:data]; + TestStreamSubNestedClassStruct* s2 = [TestStreamSubNestedClassStructHelper read:in]; + test(s2.i == s.i); + } + + { + out = [ICEUtil createOutputStream:communicator]; + TestStreamSubNestedException* ex = [TestStreamSubNestedException nestedException]; + ex.str = @"str"; + + [out writeException:ex]; + data = [out finished]; + + in = [ICEUtil createInputStream:communicator data:data]; + @try + { + [in throwException]; + test(NO); + } + @catch(TestStreamSubNestedException* ex1) + { + test([ex1.str isEqualToString:ex.str]); + } + } + + { + out = [ICEUtil createOutputStream:communicator]; + [TestStream2Sub2NestedEnum2Helper write:@(TestStream2Sub2nestedEnum4) stream:out]; + data = [out finished]; + in = [ICEUtil createInputStream:communicator data:data]; + id e = [TestStream2Sub2NestedEnum2Helper read:in]; + test([e isEqual:@(TestStream2Sub2nestedEnum4)]); + } + + { + out = [ICEUtil createOutputStream:communicator]; + TestStream2Sub2NestedStruct2* s = [TestStream2Sub2NestedStruct2 nestedStruct2]; + s.bo = YES; + s.by = 1; + s.sh = 2; + s.i = 3; + s.l = 4; + s.f = 5.0; + s.d = 6.0; + s.str = @"7"; + s.e = TestStream2Sub2nestedEnum5; + [TestStream2Sub2NestedStruct2Helper write:s stream:out]; + data = [out finished]; + in = [ICEUtil createInputStream:communicator data:data]; + TestStream2Sub2NestedStruct2* s2 = [TestStream2Sub2NestedStruct2Helper read:in]; + test([s2 isEqual:s]); + } + + { + out = [ICEUtil createOutputStream:communicator]; + TestStream2Sub2NestedClassStruct2* s = [TestStream2Sub2NestedClassStruct2 nestedClassStruct2]; + s.i = 10; + [TestStream2Sub2NestedClassStruct2Helper write:s stream:out]; + data = [out finished]; + in = [ICEUtil createInputStream:communicator data:data]; + TestStream2Sub2NestedClassStruct2* s2 = [TestStream2Sub2NestedClassStruct2Helper read:in]; + test(s2.i == s.i); + } + + { + out = [ICEUtil createOutputStream:communicator]; + TestStream2Sub2NestedException2* ex = [TestStream2Sub2NestedException2 nestedException2]; + ex.str = @"str"; + + [out writeException:ex]; + data = [out finished]; + + in = [ICEUtil createInputStream:communicator data:data]; + @try + { + [in throwException]; + test(NO); + } + @catch(TestStream2Sub2NestedException2* ex1) + { + test([ex1.str isEqualToString:ex.str]); + } + } + + tprintf("ok\n"); + return 0; +} + +#if TARGET_OS_IPHONE +# define main streamClient +#endif + +int +main(int argc, char* argv[]) +{ + int status; + @autoreleasepool + { + id<ICECommunicator> communicator = nil; + @try + { + + ICEInitializationData* initData = [ICEInitializationData initializationData]; + initData.properties = defaultClientProperties(&argc, argv); +#if TARGET_OS_IPHONE + initData.prefixTable__ = [NSDictionary dictionaryWithObjectsAndKeys: + @"TestStream", @"::Test", + @"TestStreamSub", @"::Test::Sub", + @"TestStream2", @"::Test2", + @"TestStream2Sub2", @"::Test2::Sub2", + nil]; +#endif + communicator = [ICEUtil createCommunicator:&argc argv:argv initData:initData]; + status = run(communicator); + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + @catch(TestFailedException* ex) + { + status = EXIT_FAILURE; + } + + if(communicator) + { + @try + { + [communicator destroy]; + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + } + } + return status; +} diff --git a/objective-c/test/Ice/stream/Makefile b/objective-c/test/Ice/stream/Makefile new file mode 100644 index 00000000000..18b89a91aab --- /dev/null +++ b/objective-c/test/Ice/stream/Makefile @@ -0,0 +1,28 @@ +# ********************************************************************** +# +# Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +# +# This copy of Ice is licensed to you under the terms described in the +# ICE_LICENSE file included in this distribution. +# +# ********************************************************************** + +top_srcdir = ../../.. + +CLIENT = client + +TARGETS = $(CLIENT) + +SLICE_OBJS = StreamTest.o + +COBJS = Client.o + +OBJS = $(COBJS) $(SLICE_OBJS) + +include $(top_srcdir)/config/Make.rules + +CPPFLAGS := -I. -I.. -I../../include $(CPPFLAGS) + +$(CLIENT): $(COBJS) $(SLICE_OBJS) + rm -f $@ + $(CXX) $(LDFLAGS) $(LDEXEFLAGS) -o $@ $(COBJS) $(SLICE_OBJS) $(TEST_LIBS) diff --git a/objective-c/test/Ice/stream/StreamTest.ice b/objective-c/test/Ice/stream/StreamTest.ice new file mode 100644 index 00000000000..539af0002b2 --- /dev/null +++ b/objective-c/test/Ice/stream/StreamTest.ice @@ -0,0 +1,175 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#pragma once + +#include <Ice/BuiltinSequences.ice> + +["objc:prefix:TestStream"] +module Test +{ + +enum MyEnum +{ + enum1, + enum2, + enum3 +}; + +class MyClass; + +["cpp:comparable"] struct SmallStruct +{ + bool bo; + byte by; + short sh; + int i; + long l; + float f; + double d; + string str; + MyEnum e; + MyClass* p; +}; + +["cpp:class"] struct ClassStruct +{ + int i; +}; + +class OptionalClass +{ + bool bo; + byte by; + optional(1) short sh; + optional(2) int i; +}; + +sequence<MyEnum> MyEnumS; +sequence<SmallStruct> SmallStructS; +sequence<MyClass> MyClassS; + +sequence<Ice::BoolSeq> BoolSS; +sequence<Ice::ByteSeq> ByteSS; +sequence<Ice::ShortSeq> ShortSS; +sequence<Ice::IntSeq> IntSS; +sequence<Ice::LongSeq> LongSS; +sequence<Ice::FloatSeq> FloatSS; +sequence<Ice::DoubleSeq> DoubleSS; +sequence<Ice::StringSeq> StringSS; +sequence<MyEnumS> MyEnumSS; +sequence<SmallStructS> SmallStructSS; +sequence<MyClassS> MyClassSS; + +dictionary<byte, bool> ByteBoolD; +dictionary<short, int> ShortIntD; +dictionary<long, float> LongFloatD; +dictionary<string, string> StringStringD; +dictionary<string, MyClass> StringMyClassD; + +class MyClass +{ + MyClass c; + Object o; + SmallStruct s; + Ice::BoolSeq seq1; + Ice::ByteSeq seq2; + Ice::ShortSeq seq3; + Ice::IntSeq seq4; + Ice::LongSeq seq5; + Ice::FloatSeq seq6; + Ice::DoubleSeq seq7; + Ice::StringSeq seq8; + MyEnumS seq9; + MyClassS seq10; + StringMyClassD d; +}; + +interface MyInterface +{ +}; + +exception MyException +{ + MyClass c; +}; + +["objc:prefix:TestStreamSub"] +module Sub +{ + enum NestedEnum + { + nestedEnum1, + nestedEnum2, + nestedEnum3 + }; + + ["cpp:comparable"] struct NestedStruct + { + bool bo; + byte by; + short sh; + int i; + long l; + float f; + double d; + string str; + NestedEnum e; + }; + + ["cpp:class"] struct NestedClassStruct + { + int i; + }; + + exception NestedException + { + string str; + }; +}; +}; + +["objc:prefix:TestStream2"] +module Test2 +{ +["objc:prefix:TestStream2Sub2"] +module Sub2 +{ + enum NestedEnum2 + { + nestedEnum4, + nestedEnum5, + nestedEnum6 + }; + + ["cpp:comparable"] struct NestedStruct2 + { + bool bo; + byte by; + short sh; + int i; + long l; + float f; + double d; + string str; + NestedEnum2 e; + }; + + ["cpp:class"] struct NestedClassStruct2 + { + int i; + }; + + exception NestedException2 + { + string str; + }; +}; +}; + diff --git a/objective-c/test/Ice/stream/run.py b/objective-c/test/Ice/stream/run.py new file mode 100755 index 00000000000..365a6517aa2 --- /dev/null +++ b/objective-c/test/Ice/stream/run.py @@ -0,0 +1,29 @@ +#!/usr/bin/env python +# ********************************************************************** +# +# Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +# +# This copy of Ice is licensed to you under the terms described in the +# ICE_LICENSE file included in this distribution. +# +# ********************************************************************** + +import os, sys + +path = [ ".", "..", "../..", "../../..", "../../../..", "../../../../.." ] +head = os.path.dirname(sys.argv[0]) +if len(head) > 0: + path = [os.path.join(head, p) for p in path] +path = [os.path.abspath(p) for p in path if os.path.exists(os.path.join(p, "scripts", "TestUtil.py")) ] +if len(path) == 0: + raise RuntimeError("can't find toplevel directory!") +sys.path.append(os.path.join(path[0], "scripts")) +import TestUtil + +client = os.path.join(os.getcwd(), "client") + +print("Running test with default encoding...") +TestUtil.simpleTest(client) + +print("Running test with 1.0 encoding...") +TestUtil.simpleTest(client, "--Ice.Default.EncodingVersion=1.0") diff --git a/objective-c/test/Ice/timeout/.gitignore b/objective-c/test/Ice/timeout/.gitignore new file mode 100644 index 00000000000..1c18b9822c2 --- /dev/null +++ b/objective-c/test/Ice/timeout/.gitignore @@ -0,0 +1,8 @@ +// Generated by makegitignore.py + +// IMPORTANT: Do not edit this file -- any edits made here will be lost! +client +server +.depend +TimeoutTest.m +TimeoutTest.h diff --git a/objective-c/test/Ice/timeout/AllTests.m b/objective-c/test/Ice/timeout/AllTests.m new file mode 100644 index 00000000000..bd686cb1c22 --- /dev/null +++ b/objective-c/test/Ice/timeout/AllTests.m @@ -0,0 +1,354 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <TestCommon.h> +#import <TimeoutTest.h> + +#import <Foundation/Foundation.h> + +@interface TestTimeoutCallback : NSObject +{ + BOOL called; + NSCondition* cond; +} +-(void) check; +-(void) called; +@end + +@implementation TestTimeoutCallback +-(id) init +{ + self = [super init]; + if(!self) + { + return nil; + } + cond = [[NSCondition alloc] init]; + return self; +} + +#if defined(__clang__) && !__has_feature(objc_arc) +-(void) dealloc +{ + [cond release]; + [super dealloc]; +} +#endif + +-(void) check +{ + [cond lock]; + while(!called) + { + [cond wait]; + } + called = NO; + [cond unlock]; +} +-(void) called +{ + [cond lock]; + called = YES; + [cond signal]; + [cond unlock]; +} +-(void) response +{ + [self called]; +} +-(void) exception:(ICEException*)ex +{ + test(NO); +} +-(void) responseEx +{ + test(NO); +} +-(void) exceptionEx:(ICEException*)ex +{ + test([ex isKindOfClass:[ICEInvocationTimeoutException class]]); + [self called]; +} +@end + +id<TestTimeoutTimeoutPrx> +timeoutAllTests(id<ICECommunicator> communicator) +{ + NSString* sref = @"timeout:default -p 12010"; + id<ICEObjectPrx> obj = [communicator stringToProxy:sref]; + test(obj); + + id<TestTimeoutTimeoutPrx> timeout = [TestTimeoutTimeoutPrx checkedCast:obj]; + test(timeout); + + tprintf("testing connect timeout... "); + { + // + // Expect ConnectTimeoutException. + // + id<TestTimeoutTimeoutPrx> to = [TestTimeoutTimeoutPrx uncheckedCast:[obj ice_timeout:500]]; + [to holdAdapter:1000]; + [[to ice_getConnection] close:YES]; // Force a reconnect. + @try + { + [to op]; + test(NO); + } + @catch(ICEConnectTimeoutException*) + { + // Expected. + } + } + { + // + // Expect success. + // + [timeout op]; // Ensure adapter is active. + id<TestTimeoutTimeoutPrx> to = [TestTimeoutTimeoutPrx uncheckedCast:[obj ice_timeout:1000]]; + [to holdAdapter:500]; + [[to ice_getConnection] close:YES]; // Force a reconnect. + @try + { + [to op]; + } + @catch(ICEConnectTimeoutException*) + { + test(NO); + } + } + tprintf("ok\n"); + + // The sequence needs to be large enough to fill the write/recv buffers + TestTimeoutByteSeq* seq = [TestTimeoutMutableByteSeq dataWithLength:2000000]; + + tprintf("testing connection timeout... "); + { + // + // Expect TimeoutException. + // + id<TestTimeoutTimeoutPrx> to = [TestTimeoutTimeoutPrx uncheckedCast:[obj ice_timeout:100]]; + [to holdAdapter:500]; + @try + { + [to sendData:seq]; + test(NO); + } + @catch(ICETimeoutException*) + { + // Expected. + } + } + { + // + // Expect success. + // + [timeout op]; // Ensure adapter is active. + id<TestTimeoutTimeoutPrx> to = [TestTimeoutTimeoutPrx uncheckedCast:[obj ice_timeout:1000]]; + [to holdAdapter:500]; + @try + { + TestTimeoutByteSeq* seq = [TestTimeoutMutableByteSeq dataWithLength:1000000]; + [to sendData:seq]; + } + @catch(ICETimeoutException*) + { + test(NO); + } + } + tprintf("ok\n"); + + tprintf("testing invocation timeout... "); + { + id<ICEConnection> connection = [obj ice_getConnection]; + id<TestTimeoutTimeoutPrx> to = [TestTimeoutTimeoutPrx uncheckedCast:[obj ice_invocationTimeout:100]]; + test(connection == [to ice_getConnection]); + @try + { + [to sleep:750]; + test(NO); + } + @catch(ICEInvocationTimeoutException*) + { + } + [obj ice_ping]; + to = [TestTimeoutTimeoutPrx uncheckedCast:[obj ice_invocationTimeout:500]]; + test(connection == [to ice_getConnection]); + @try + { + [to sleep:250]; + } + @catch(ICEInvocationTimeoutException*) + { + test(NO); + } + test(connection == [to ice_getConnection]); + } + { + // + // Expect InvocationTimeoutException. + // + id<TestTimeoutTimeoutPrx> to = [TestTimeoutTimeoutPrx uncheckedCast:[obj ice_invocationTimeout:100]]; + TestTimeoutCallback* cb = [[TestTimeoutCallback alloc] init]; + [to begin_sleep:750 response:^ { [cb responseEx]; } exception:^(ICEException* ex) { [cb exceptionEx:ex]; }]; + [cb check]; + [obj ice_ping]; + } + { + // + // Expect Success. + // + id<TestTimeoutTimeoutPrx> to = [TestTimeoutTimeoutPrx uncheckedCast:[obj ice_invocationTimeout:500]]; + TestTimeoutCallback* cb = [[TestTimeoutCallback alloc] init]; + [to begin_sleep:250 response:^ { [cb response]; } exception:^(ICEException* ex) { [cb exception:ex]; }]; + [cb check]; + } + { + // + // Backward compatible connection timeouts + // + id<TestTimeoutTimeoutPrx> to = + [TestTimeoutTimeoutPrx uncheckedCast:[[obj ice_invocationTimeout:-2] ice_timeout:100]]; + id<ICEConnection> con; + @try + { + con = [to ice_getConnection]; + [to sleep:250]; + test(NO); + } + @catch(ICETimeoutException*) + { + @try + { + [con getInfo]; + test(NO); + } + @catch(ICETimeoutException*) + { + // Connection got closed as well. + } + } + [obj ice_ping]; + + @try + { + con = [to ice_getConnection]; + [to end_sleep:[to begin_sleep:750]]; + test(NO); + } + @catch(ICETimeoutException*) + { + @try + { + [con getInfo]; + test(NO); + } + @catch(ICETimeoutException*) + { + // Connection got closed as well. + } + } + [obj ice_ping]; + } + tprintf("ok\n"); + + tprintf("testing timeout overrides... "); + { + // + // TestTimeout Ice.Override.Timeout. This property overrides all + // endpoint timeouts. + // + ICEInitializationData* initData = [ICEInitializationData initializationData]; + [initData setProperties:[[communicator getProperties] clone]]; + [[initData properties] setProperty:@"Ice.Override.Timeout" value:@"100"]; + id<ICECommunicator> comm = [ICEUtil createCommunicator:initData]; + id<TestTimeoutTimeoutPrx> to = [TestTimeoutTimeoutPrx checkedCast:[comm stringToProxy:sref]]; + [timeout holdAdapter:500]; + @try + { + [to sendData:seq]; + test(NO); + } + @catch(ICETimeoutException*) + { + // Expected. + } + // + // Calling ice_timeout() should have no effect. + // + [timeout op]; // Ensure adapter is active. + to = [TestTimeoutTimeoutPrx checkedCast:[to ice_timeout:1000]]; + [timeout holdAdapter:500]; + @try + { + [to sendData:seq]; + test(NO); + } + @catch(ICETimeoutException*) + { + // Expected. + } + [comm destroy]; + } + { + // + // TestTimeout Ice.Override.ConnectTimeout. + // + ICEInitializationData* initData = [ICEInitializationData initializationData]; + [initData setProperties:[[communicator getProperties] clone]]; + [[initData properties] setProperty:@"Ice.Override.ConnectTimeout" value:@"250"]; + id<ICECommunicator> comm = [ICEUtil createCommunicator:initData]; + [timeout holdAdapter:750]; + id<TestTimeoutTimeoutPrx> to = [TestTimeoutTimeoutPrx uncheckedCast:[comm stringToProxy:sref]]; + @try + { + [to op]; + test(NO); + } + @catch(ICEConnectTimeoutException*) + { + // Expected. + } + // + // Calling ice_timeout() should have no effect on the connect timeout. + // + [timeout op]; // Ensure adapter is active. + [timeout holdAdapter:750]; + to = [TestTimeoutTimeoutPrx uncheckedCast:[to ice_timeout:1000]]; + @try + { + [to op]; + test(NO); + } + @catch(ICEConnectTimeoutException*) + { + // Expected. + } + // + // Verify that timeout set via ice_timeout() is still used for requests. + // + [timeout op]; // Ensure adapter is active. + to = [TestTimeoutTimeoutPrx uncheckedCast:[to ice_timeout:100]]; + [to ice_getConnection]; // Establish connection + [timeout holdAdapter:750]; + @try + { + [to sendData:seq]; + test(NO); + } + @catch(ICETimeoutException*) + { + // Expected. + } + [comm destroy]; + } + tprintf("ok\n"); + + return timeout; +} diff --git a/objective-c/test/Ice/timeout/Client.m b/objective-c/test/Ice/timeout/Client.m new file mode 100644 index 00000000000..fcebbd09aa8 --- /dev/null +++ b/objective-c/test/Ice/timeout/Client.m @@ -0,0 +1,87 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <TestCommon.h> +#import <TimeoutTest.h> + +static int +run(id<ICECommunicator> communicator) +{ + id<TestTimeoutTimeoutPrx> timeoutAllTests(id<ICECommunicator>); + id<TestTimeoutTimeoutPrx> timeout = timeoutAllTests(communicator); + [timeout shutdown]; + return EXIT_SUCCESS; +} + +#if TARGET_OS_IPHONE +# define main timeoutClient +#endif + +int +main(int argc, char* argv[]) +{ + int status; + @autoreleasepool + { + id<ICECommunicator> communicator = nil; + @try + { + ICEInitializationData* initData = [ICEInitializationData initializationData]; + initData.properties = defaultClientProperties(&argc, argv); + + // + // For this test, we want to disable retries. + // + [initData.properties setProperty:@"Ice.RetryIntervals" value:@"-1"]; + + // + // COMPILERFIX: Disable connect timeout introduced for + // workaround to iOS device hangs when using SSL + // + [initData.properties setProperty:@"Ice.Override.ConnectTimeout" value:@""]; + + // + // This test kills connections, so we don't want warnings. + // + [initData.properties setProperty:@"Ice.Warn.Connections" value:@"0"]; +#if TARGET_OS_IPHONE + initData.prefixTable__ = [NSDictionary dictionaryWithObjectsAndKeys: + @"TestTimeout", @"::Test", + nil]; +#endif + + communicator = [ICEUtil createCommunicator:&argc argv:argv initData:initData]; + status = run(communicator); + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + @catch(TestFailedException* ex) + { + status = EXIT_FAILURE; + } + + if(communicator) + { + @try + { + [communicator destroy]; + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + } + } + return status; +} diff --git a/objective-c/test/Ice/timeout/Makefile b/objective-c/test/Ice/timeout/Makefile new file mode 100644 index 00000000000..9e6ba54dad3 --- /dev/null +++ b/objective-c/test/Ice/timeout/Makefile @@ -0,0 +1,37 @@ +# ********************************************************************** +# +# Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +# +# This copy of Ice is licensed to you under the terms described in the +# ICE_LICENSE file included in this distribution. +# +# ********************************************************************** + +top_srcdir = ../../.. + +CLIENT = client +SERVER = server + +TARGETS = $(CLIENT) $(SERVER) + +SLICE_OBJS = TimeoutTest.o + +COBJS = Client.o \ + AllTests.o + +SOBJS = TestI.o \ + Server.o + +OBJS = $(COBJS) $(SOBJS) $(SLICE_OBJS) + +include $(top_srcdir)/config/Make.rules + +CPPFLAGS := -I. -I.. -I../../include $(CPPFLAGS) + +$(CLIENT): $(COBJS) $(SLICE_OBJS) + rm -f $@ + $(CXX) $(LDFLAGS) $(LDEXEFLAGS) -o $@ $(COBJS) $(SLICE_OBJS) $(TEST_LIBS) + +$(SERVER): $(SOBJS) $(SLICE_OBJS) + rm -f $@ + $(CXX) $(LDFLAGS) $(LDEXEFLAGS) -o $@ $(SOBJS) $(SLICE_OBJS) $(TEST_LIBS) diff --git a/objective-c/test/Ice/timeout/Server.m b/objective-c/test/Ice/timeout/Server.m new file mode 100644 index 00000000000..2922e85d83f --- /dev/null +++ b/objective-c/test/Ice/timeout/Server.m @@ -0,0 +1,84 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <timeout/TestI.h> +#import <TestCommon.h> + +static int +run(id<ICECommunicator> communicator) +{ + [[communicator getProperties] setProperty:@"TestAdapter.Endpoints" value:@"default -p 12010:udp"]; + id<ICEObjectAdapter> adapter = [communicator createObjectAdapter:@"TestAdapter"]; + ICEObject* object = [TimeoutI timeout]; + [adapter add:object identity:[communicator stringToIdentity:@"timeout"]]; + [adapter activate]; + + serverReady(communicator); + + [communicator waitForShutdown]; + return EXIT_SUCCESS; +} + +#if TARGET_OS_IPHONE +# define main timeoutServer +#endif + +int +main(int argc, char* argv[]) +{ + int status; + @autoreleasepool + { + id<ICECommunicator> communicator = nil; + @try + { + ICEInitializationData* initData = [ICEInitializationData initializationData]; + initData.properties = defaultServerProperties(&argc, argv); + + // + // COMPILERFIX: Disable connect timeout introduced for + // workaround to iOS device hangs when using SSL + // + [initData.properties setProperty:@"Ice.Override.ConnectTimeout" value:@""]; + + // + // This test kills connections, so we don't want warnings. + // + [initData.properties setProperty:@"Ice.Warn.Connections" value:@"0"]; +#if TARGET_OS_IPHONE + initData.prefixTable__ = [NSDictionary dictionaryWithObjectsAndKeys: + @"TestTimeout", @"::Test", + nil]; +#endif + + communicator = [ICEUtil createCommunicator:&argc argv:argv initData:initData]; + status = run(communicator); + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + + if(communicator) + { + @try + { + [communicator destroy]; + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + } + } + return status; +} diff --git a/objective-c/test/Ice/timeout/TestI.h b/objective-c/test/Ice/timeout/TestI.h new file mode 100644 index 00000000000..a9b7a2f6372 --- /dev/null +++ b/objective-c/test/Ice/timeout/TestI.h @@ -0,0 +1,18 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <TimeoutTest.h> + +@interface TimeoutI : TestTimeoutTimeout<TestTimeoutTimeout> +-(void) op:(ICECurrent *)current; +-(void) sendData:(TestTimeoutMutableByteSeq *)seq current:(ICECurrent *)current; +-(void) sleep:(ICEInt)to current:(ICECurrent *)current; +-(void) holdAdapter:(ICEInt)to current:(ICECurrent *)current; +-(void) shutdown:(ICECurrent *)current; +@end diff --git a/objective-c/test/Ice/timeout/TestI.m b/objective-c/test/Ice/timeout/TestI.m new file mode 100644 index 00000000000..29d83e987a4 --- /dev/null +++ b/objective-c/test/Ice/timeout/TestI.m @@ -0,0 +1,86 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <timeout/TestI.h> +#import <objc/Ice.h> + +#import <Foundation/NSThread.h> + +@interface ActivateAdapterThread : NSThread +{ + id<ICEObjectAdapter> adapter_; + int timeout_; +} +-(id) init:(id<ICEObjectAdapter>)adapter timeout:(int)timeout; ++(id) activateAdapterThread:(id<ICEObjectAdapter>)adapter timeout:(int)timeout; +-(void) main; +#if defined(__clang__) && !__has_feature(objc_arc) +-(void) dealloc; +#endif +@end + +@implementation ActivateAdapterThread +-(id) init:(id<ICEObjectAdapter>)adapter timeout:(int)timeout +{ + self = [super init]; + if(!self) + { + return nil; + } + adapter_ = ICE_RETAIN(adapter); + timeout_ = timeout; + return self; +} + ++(id) activateAdapterThread:(id<ICEObjectAdapter>)adapter timeout:(int)timeout +{ + return ICE_AUTORELEASE([[self alloc] init:adapter timeout:timeout]); +} +-(void) main +{ + [NSThread sleepForTimeInterval:timeout_ / 1000.0]; + [adapter_ activate]; +} + +#if defined(__clang__) && !__has_feature(objc_arc) +-(void) dealloc +{ + [adapter_ release]; + [super dealloc]; +} +#endif + +@end + +@implementation TimeoutI +-(void) op:(ICECurrent*)current +{ +} + +-(void) sendData:(TestTimeoutMutableByteSeq*)seq current:(ICECurrent*)current +{ +} + +-(void) sleep:(ICEInt)to current:(ICECurrent*)current +{ + [NSThread sleepForTimeInterval:to / 1000.0]; +} + +-(void) holdAdapter:(ICEInt)to current:(ICECurrent*)current +{ + [current.adapter hold]; + ActivateAdapterThread* thread = [ActivateAdapterThread activateAdapterThread:current.adapter timeout:to]; + [thread start]; +} + +-(void) shutdown:(ICECurrent*)current +{ + [[current.adapter getCommunicator] shutdown]; +} +@end diff --git a/objective-c/test/Ice/timeout/TimeoutTest.ice b/objective-c/test/Ice/timeout/TimeoutTest.ice new file mode 100644 index 00000000000..de22e5a132d --- /dev/null +++ b/objective-c/test/Ice/timeout/TimeoutTest.ice @@ -0,0 +1,29 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#pragma once + +["objc:prefix:TestTimeout"] +module Test +{ + +sequence<byte> ByteSeq; + +interface Timeout +{ + void op(); + void sendData(ByteSeq seq); + void sleep(int to); + + void holdAdapter(int to); + + void shutdown(); +}; + +}; diff --git a/objective-c/test/Ice/timeout/run.py b/objective-c/test/Ice/timeout/run.py new file mode 100755 index 00000000000..ce8c5dd4b18 --- /dev/null +++ b/objective-c/test/Ice/timeout/run.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python +# ********************************************************************** +# +# Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +# +# This copy of Ice is licensed to you under the terms described in the +# ICE_LICENSE file included in this distribution. +# +# ********************************************************************** + +import os, sys + +path = [ ".", "..", "../..", "../../..", "../../../..", "../../../../.." ] +head = os.path.dirname(sys.argv[0]) +if len(head) > 0: + path = [os.path.join(head, p) for p in path] +path = [os.path.abspath(p) for p in path if os.path.exists(os.path.join(p, "scripts", "TestUtil.py")) ] +if len(path) == 0: + raise RuntimeError("can't find toplevel directory!") +sys.path.append(os.path.join(path[0], "scripts")) +import TestUtil + +TestUtil.clientServerTest() diff --git a/objective-c/test/Makefile b/objective-c/test/Makefile new file mode 100644 index 00000000000..9649b07ca0e --- /dev/null +++ b/objective-c/test/Makefile @@ -0,0 +1,21 @@ +# ********************************************************************** +# +# Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +# +# This copy of Ice is licensed to you under the terms described in the +# ICE_LICENSE file included in this distribution. +# +# ********************************************************************** + +top_srcdir = .. + +include $(top_srcdir)/config/Make.rules + +SUBDIRS = Common Slice Ice + +$(EVERYTHING):: + @for subdir in $(SUBDIRS); \ + do \ + echo "making $@ in $$subdir"; \ + ( cd $$subdir && $(MAKE) $@ ) || exit 1; \ + done diff --git a/objective-c/test/Slice/Makefile b/objective-c/test/Slice/Makefile new file mode 100644 index 00000000000..70984bbb015 --- /dev/null +++ b/objective-c/test/Slice/Makefile @@ -0,0 +1,21 @@ +# ********************************************************************** +# +# Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +# +# This copy of Ice is licensed to you under the terms described in the +# ICE_LICENSE file included in this distribution. +# +# ********************************************************************** + +top_srcdir = ../.. + +include $(top_srcdir)/config/Make.rules + +SUBDIRS = keyword + +$(EVERYTHING):: + @for subdir in $(SUBDIRS); \ + do \ + echo "making $@ in $$subdir"; \ + ( cd $$subdir && $(MAKE) $@ ) || exit 1; \ + done diff --git a/objective-c/test/Slice/keyword/.gitignore b/objective-c/test/Slice/keyword/.gitignore new file mode 100644 index 00000000000..f5c78eb09c4 --- /dev/null +++ b/objective-c/test/Slice/keyword/.gitignore @@ -0,0 +1,9 @@ +// Generated by makegitignore.py + +// IMPORTANT: Do not edit this file -- any edits made here will be lost! +client +.depend +Key.m +Inherit.m +Key.h +Inherit.h diff --git a/objective-c/test/Slice/keyword/Client.m b/objective-c/test/Slice/keyword/Client.m new file mode 100644 index 00000000000..d58e18ecdc6 --- /dev/null +++ b/objective-c/test/Slice/keyword/Client.m @@ -0,0 +1,216 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <objc/Ice.h> +#import <TestCommon.h> +#import <Key.h> +#import <Inherit.h> + +// Verify that the expected symbols are present +@interface andbreakI : andbreak<andbreak> +@end + +@interface andcharI : andchar<andchar> +@end + +@interface andswitchI : andswitch<andswitch> +@end + +@interface anddoI : anddo<anddo> +@end + +@interface andfriendI : ICELocalObject<andfriend> +@end + +// +// This section of the test is present to ensure that the C++ types +// are named correctly. It is not expected to run. +// +static void +testSymbols() +{ + andbreakPrx* prx1 = 0; + [prx1 case_:0 try:0]; + test(prx1 == 0); + + andcharPrx* prx2 = 0; + [prx2 explicit]; + test(prx2 == 0); + + andswitchPrx* prx3 = 0; + [prx3 foo:0 volatile:0]; + [prx3 foo2:0 y:0 nil2:0]; + [prx3 foo3:0 nil_:0]; + test(prx3 == 0); + + anddoPrx* prx4 = 0; + test(prx4 == 0); + + anddoPrx* prx5 = 0; + test(prx5 == 0); + + andcontinue c1 = andasm; + test(c1 == andasm); + + andauto* cl1 = 0; + test(cl1 == 0); + + anddelete* cl2 = 0; + test(cl2 == 0); + + andswitch* cl3 = 0; + test(cl3.if_ == 0); + test(cl3 == 0); + + anddo* cl4 = 0; + test(cl4 == 0); + + andreturn* ex1 = 0; + test(ex1.signed_ == 0); + test(ex1 == 0); + + andsizeof* ex2 = 0; + test(ex2.signed_ == 0); + test(ex2.static_ == 0); + test(ex2 == 0); + + test(andtemplate == 0); + test(andthis == 0); + test(andthrow == 0); + test(andtypedef == 0); + test(andtypeid == 0); + test(andtypename == 0); + test(andunion == 0); + test(andunsigned == 0); + test(andusing == 0); + test(andvirtual == 0); + test(andwhile == 0); + test(andxor == 0); + + TestStruct1* ds1 = 0; + test(ds1.retainCount_ == 0); + + TestException1 *dex1 = 0; + test(dex1.isa_ == 0); + test(dex1.reason_ == 0); + test(dex1.raise_ == 0); + test(dex1.name_ == 0); + test(dex1.callStackReturnAddresses_ == 0); + test(dex1.userInfo_ == 0); + test(dex1.reserved_ == 0); + + TestClass1* dcl1 = 0; + test(dcl1.reason == 0); + test(dcl1.autorelease_ == 0); + test(dcl1.isa_ == 0); + test(dcl1.classForCoder_ == 0); + test(dcl1.copy_ == 0); + test(dcl1.dealloc_ == 0); + test(dcl1.description_ == 0); + test(dcl1.hash_ == 0); + test(dcl1.init_ == 0); + test(dcl1.isProxy_ == 0); + test(dcl1.mutableCopy_ == 0); + test(dcl1.release_ == 0); + test(dcl1.retain_ == 0); + test(dcl1.retainCount_ == 0); + test(dcl1.self_ == 0); + test(dcl1.superclass_ == 0); + test(dcl1.zone_ == 0); + + TestIntf1Prx* dif1 = 0; + [dif1 reason]; + [dif1 isa_]; + [dif1 autorelease_]; + [dif1 classForCoder_]; + [dif1 copy_]; + [dif1 dealloc_]; + [dif1 description_]; + [dif1 hash_]; + [dif1 init_]; + [dif1 isProxy_]; + [dif1 mutableCopy_]; + [dif1 release_]; + [dif1 retain_]; + [dif1 retainCount_]; + [dif1 self_]; + [dif1 superclass_]; + [dif1 zone_]; + + TestIntf2Prx* dif2 = 0; + [dif2 reason:0]; + [dif2 isa:0]; + [dif2 autorelease:0]; + [dif2 classForCoder:0]; + [dif2 copy:0]; + [dif2 dealloc:0]; + [dif2 description:0]; + [dif2 hash:0]; + [dif2 init:0]; + [dif2 isProxy:0]; + [dif2 mutableCopy:0]; + [dif2 release:0]; + [dif2 retain:0]; + [dif2 retainCount:0]; + [dif2 self_:0]; + [dif2 superclass:0]; + [dif2 zone:0]; +} + +static int +run(id<ICECommunicator> communicator) +{ + if(0) + { + testSymbols(); + } + return 0; +} + +int +main(int argc, char* argv[]) +{ + int status; + @autoreleasepool + { + id<ICECommunicator> communicator = nil; + + @try + { + ICEInitializationData* initData = [ICEInitializationData initializationData]; + initData.properties = defaultClientProperties(&argc, argv); + communicator = [ICEUtil createCommunicator:&argc argv:argv initData:initData]; + status = run(communicator); + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + @catch(TestFailedException* ex) + { + status = EXIT_FAILURE; + } + + if(communicator) + { + @try + { + [communicator destroy]; + } + @catch(ICEException* ex) + { + tprintf("%@\n", ex); + status = EXIT_FAILURE; + } + } + } + return status; +} + diff --git a/objective-c/test/Slice/keyword/Inherit.ice b/objective-c/test/Slice/keyword/Inherit.ice new file mode 100644 index 00000000000..6d5f327cd2a --- /dev/null +++ b/objective-c/test/Slice/keyword/Inherit.ice @@ -0,0 +1,95 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +// Test overridding interherited names +module Test +{ + +struct Struct1 +{ + int isa; + int retainCount; +}; + +exception Exception1 +{ + int isa; + int reason; + int raise; + int name; + int callStackReturnAddresses; + int userInfo; + int reserved; +}; + +class Class1 +{ + int reason; + + int isa; + int autorelease; + int classForCoder; + int copy; + int dealloc; + int description; + int hash; + int init; + int isProxy; + int mutableCopy; + int release; + int retain; + int retainCount; + int self; + int superclass; + int zone; +}; + +interface Intf1 +{ + void isa(); + void reason(); + void autorelease(); + void classForCoder(); + void copy(); + void dealloc(); + void description(); + void hash(); + void init(); + void isProxy(); + void mutableCopy(); + void release(); + void retain(); + void retainCount(); + void self(); + void superclass(); + void zone(); +}; + +interface Intf2 +{ + void isa(int a); + void reason(int a); + void autorelease(int a); + void classForCoder(int a); + void copy(int a); + void dealloc(int a); + void description(int a); + void hash(int a); + void init(int a); + void isProxy(int a); + void mutableCopy(int a); + void release(int a); + void retain(int a); + void retainCount(int a); + void self(int a); + void superclass(int a); + void zone(int a); +}; + +}; diff --git a/objective-c/test/Slice/keyword/Key.ice b/objective-c/test/Slice/keyword/Key.ice new file mode 100644 index 00000000000..dbb63daacf0 --- /dev/null +++ b/objective-c/test/Slice/keyword/Key.ice @@ -0,0 +1,88 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +module and +{ + +enum continue +{ + asm +}; + +struct auto +{ + int default; +}; + +["cpp:class"] struct delete +{ + string else; +}; + +interface break +{ + void case(int catch, out int try); +}; + +interface char +{ + void explicit(); +}; + +class switch +{ + int if; + void foo(char* export, out int volatile); + void foo2(char* export, ["objc:param:y"] int YES, out ["objc:param:nil2"] int nil); + void foo3(char* export, out int nil); +}; + +class do extends switch implements char, break +{ +}; + +sequence<auto> extern; + +dictionary<string,auto> for; + +exception return +{ + int signed; +}; + +exception sizeof extends return +{ + int static; + int switch; +}; + +local interface friend +{ + auto goto(continue if, auto d, delete inline, switch private, do mutable, break* namespace, + char* new, switch* not, do* operator, int or, int protected, int public, int register) + throws return, sizeof; + + void objc(int bycopy, int byref, int id, int IMP, int in, int inout, int nil, int NO, int oneway, + int SEL, int super, int YES); +}; + +const int template = 0; +const int this = 0; +const int throw = 0; +const int typedef = 0; +const int typeid = 0; +const int typename = 0; +const int union = 0; +const int unsigned = 0; +const int using = 0; +const int virtual = 0; +const int while = 0; +const int xor = 0; + +}; diff --git a/objective-c/test/Slice/keyword/Makefile b/objective-c/test/Slice/keyword/Makefile new file mode 100644 index 00000000000..9b10c64c182 --- /dev/null +++ b/objective-c/test/Slice/keyword/Makefile @@ -0,0 +1,27 @@ +# ********************************************************************** +# +# Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +# +# This copy of Ice is licensed to you under the terms described in the +# ICE_LICENSE file included in this distribution. +# +# ********************************************************************** + +top_srcdir = ../../.. + +CLIENT = client + +TARGETS = $(CLIENT) + +SLICE_OBJS = Key.o Inherit.o + +OBJS = $(SLICE_OBJS) \ + Client.o + +include $(top_srcdir)/config/Make.rules + +CPPFLAGS := -I. -I.. -I../../include $(CPPFLAGS) + +$(CLIENT): $(OBJS) + rm -f $@ + $(CXX) $(LDFLAGS) $(LDEXEFLAGS) -o $@ $(OBJS) $(TEST_LIBS) diff --git a/objective-c/test/Slice/keyword/run.py b/objective-c/test/Slice/keyword/run.py new file mode 100755 index 00000000000..fde45700ed2 --- /dev/null +++ b/objective-c/test/Slice/keyword/run.py @@ -0,0 +1,25 @@ +#!/usr/bin/env python +# ********************************************************************** +# +# Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +# +# This copy of Ice is licensed to you under the terms described in the +# ICE_LICENSE file included in this distribution. +# +# ********************************************************************** + +import os, sys + +path = [ ".", "..", "../..", "../../..", "../../../.." ] +head = os.path.dirname(sys.argv[0]) +if len(head) > 0: + path = [os.path.join(head, p) for p in path] +path = [os.path.abspath(p) for p in path if os.path.exists(os.path.join(p, "scripts", "TestUtil.py")) ] +if len(path) == 0: + raise RuntimeError("can't find toplevel directory!") +sys.path.append(os.path.join(path[0], "scripts")) +import TestUtil + +client = os.path.join(os.getcwd(), "client") + +TestUtil.simpleTest(client) diff --git a/objective-c/test/include/TestCommon.h b/objective-c/test/include/TestCommon.h new file mode 100644 index 00000000000..1d4b722dcbe --- /dev/null +++ b/objective-c/test/include/TestCommon.h @@ -0,0 +1,44 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#import <Foundation/NSObject.h> +#import <Foundation/NSException.h> +#import <objc/Ice/Config.h> + +#ifndef TEST_API +# ifdef TEST_API_EXPORTS +# define TEST_API ICE_DECLSPEC_EXPORT +# else +# define TEST_API ICE_DECLSPEC_IMPORT +# endif +#endif + +TEST_API @interface TestFailedException : NSException +@end + +#if TARGET_OS_IPHONE +TEST_API void TestCommonInit(id, SEL); +TEST_API void TestCommonTestInit(id, SEL, NSString*, BOOL, BOOL); +#endif + +@protocol ICECommunicator; +@protocol ICEProperties; + +TEST_API id<ICEProperties> defaultServerProperties(); +TEST_API id<ICEProperties> defaultClientProperties(); + +TEST_API void serverReady(id<ICECommunicator>); + +TEST_API void serverStop(); + +TEST_API void tprintf(const char* fmt, ...); + +TEST_API void testFailed(const char*, const char*, unsigned int); + +#define test(ex) ((ex) ? ((void)0) : testFailed(#ex, __FILE__, __LINE__)) |