1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281
|
//
// Copyright (c) ZeroC, Inc. All rights reserved.
//
#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>
#import <Foundation/NSLock.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 NSLock* mutex = nil;
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.CAs", @"cacert.der",
@"IceSSL.CheckCertName", @"0",
@"IceSSL.CertFile", @"server.p12",
@"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 = [ICEUtil argsToStringSeq:*argc argv:argv];
args = [properties parseIceCommandLineOptions:args];
args = [properties parseCommandLineOptions:@"Test" options:args];
[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.CAs", @"cacert.der",
@"IceSSL.CertFile", @"client.p12",
@"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 = [ICEUtil argsToStringSeq:*argc argv:argv];
args = [properties parseIceCommandLineOptions:args];
args = [properties parseCommandLineOptions:@"Test" options:args];
[ICEUtil stringSeqToArgs:args argc:argc argv:argv];
return properties;
}
NSString*
getTestEndpoint(id<ICECommunicator> com, int num)
{
id<ICEProperties> properties = [com getProperties];
NSString* protocol = [properties getPropertyWithDefault:@"Ice.Default.Protocol" value:@"default"];
int basePort = [properties getPropertyAsIntWithDefault:@"Test.BasePort" value:12010];
return [NSString stringWithFormat:@"%@ -p %d", protocol, basePort + num];
}
#if TARGET_OS_IPHONE
void
TestCommonSetOutput(id target, SEL output)
{
if(mutex == nil)
{
mutex = [NSLock new];
}
[mutex lock];
if(target != nil)
{
outputTarget = ICE_RETAIN(target);
outputSelector = output;
}
else
{
ICE_RELEASE(outputTarget);
outputTarget = nil;
outputSelector = nil;
}
[mutex unlock];
}
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()
{
@try
{
[communicator shutdown];
}
@catch(ICECommunicatorDestroyedException* ex)
{
// Ignore, it's possible the test shutdown the server explicitly already.
}
}
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);
[mutex lock];
if(outputTarget != nil)
{
[outputTarget performSelectorOnMainThread:outputSelector withObject:s waitUntilDone:NO];
}
[mutex unlock];
}
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>__unused 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
|