1% 2% Copyright (c) ZeroC, Inc. All rights reserved. 3% 4 5classdef AllTests 6 methods(Static) 7 function r = allTests(helper) 8 import Test.*; 9 10 communicator = helper.communicator(); 11 12 fprintf('testing stringToProxy... '); 13 14 % 15 % Test nil proxies. 16 % 17 p = communicator.stringToProxy(''); 18 assert(isempty(p)); 19 p = communicator.propertyToProxy('bogus'); 20 assert(isempty(p)); 21 22 ref = ['test:', helper.getTestEndpoint()]; 23 base = communicator.stringToProxy(ref); 24 assert(~isempty(base)); 25 26 b1 = communicator.stringToProxy('test'); 27 assert(strcmp(b1.ice_getIdentity().name, 'test') && isempty(b1.ice_getIdentity().category) && ... 28 isempty(b1.ice_getAdapterId()) && isempty(b1.ice_getFacet())); 29 b1 = communicator.stringToProxy('test '); 30 assert(strcmp(b1.ice_getIdentity().name, 'test') && isempty(b1.ice_getIdentity().category) && ... 31 isempty(b1.ice_getFacet())); 32 b1 = communicator.stringToProxy(' test '); 33 assert(strcmp(b1.ice_getIdentity().name, 'test') && isempty(b1.ice_getIdentity().category) && ... 34 isempty(b1.ice_getFacet())); 35 b1 = communicator.stringToProxy(' test'); 36 assert(strcmp(b1.ice_getIdentity().name, 'test') && isempty(b1.ice_getIdentity().category) && ... 37 isempty(b1.ice_getFacet())); 38 b1 = communicator.stringToProxy('''test -f facet'''); 39 assert(strcmp(b1.ice_getIdentity().name, 'test -f facet') && isempty(b1.ice_getIdentity().category) && ... 40 isempty(b1.ice_getFacet())); 41 try 42 b1 = communicator.stringToProxy('"test -f facet'''); 43 assert(false); 44 catch ex 45 assert(isa(ex, 'Ice.ProxyParseException')); 46 end 47 b1 = communicator.stringToProxy('"test -f facet"'); 48 assert(strcmp(b1.ice_getIdentity().name, 'test -f facet') && isempty(b1.ice_getIdentity().category) && ... 49 isempty(b1.ice_getFacet())); 50 b1 = communicator.stringToProxy('"test -f facet@test"'); 51 assert(strcmp(b1.ice_getIdentity().name, 'test -f facet@test') && ... 52 isempty(b1.ice_getIdentity().category) && isempty(b1.ice_getFacet())); 53 b1 = communicator.stringToProxy('"test -f facet@test @test"'); 54 assert(strcmp(b1.ice_getIdentity().name, 'test -f facet@test @test') && ... 55 isempty(b1.ice_getIdentity().category) && isempty(b1.ice_getFacet())); 56 try 57 b1 = communicator.stringToProxy('test test'); 58 assert(false); 59 catch ex 60 assert(isa(ex, 'Ice.ProxyParseException')); 61 end 62 b1 = communicator.stringToProxy('test\040test'); 63 assert(strcmp(b1.ice_getIdentity().name, 'test test') && isempty(b1.ice_getIdentity().category)); 64 try 65 b1 = communicator.stringToProxy('test\777'); 66 assert(false); 67 catch ex 68 assert(isa(ex, 'Ice.IdentityParseException')); 69 end 70 b1 = communicator.stringToProxy('test\40test'); 71 assert(strcmp(b1.ice_getIdentity().name, 'test test')); 72 73 % Test some octal and hex corner cases. 74 b1 = communicator.stringToProxy('test\4test'); 75 assert(strcmp(b1.ice_getIdentity().name, sprintf('test\4test'))); 76 b1 = communicator.stringToProxy('test\04test'); 77 assert(strcmp(b1.ice_getIdentity().name, sprintf('test\4test'))); 78 b1 = communicator.stringToProxy('test\004test'); 79 assert(strcmp(b1.ice_getIdentity().name, sprintf('test\4test'))); 80 % 81 % In other languages this test is written as: 82 % 83 % b1 = communicator.stringToProxy('test\1114test') 84 % 85 % But the MATLAB parser consumes all of the octal digits. 86 % 87 b1 = communicator.stringToProxy('test\111\064test'); 88 assert(strcmp(b1.ice_getIdentity().name, sprintf('test\111\064test'))); 89 90 b1 = communicator.stringToProxy('test\b\f\n\r\t''"\test'); 91 assert(strcmp(b1.ice_getIdentity().name, sprintf('test\b\f\n\r\t''"\test')) && ... 92 isempty(b1.ice_getIdentity().category)); 93 94 b1 = communicator.stringToProxy('category/test'); 95 assert(strcmp(b1.ice_getIdentity().name, 'test') && ... 96 strcmp(b1.ice_getIdentity().category, 'category') && isempty(b1.ice_getAdapterId())); 97 98 b1 = communicator.stringToProxy('test@adapter'); 99 assert(strcmp(b1.ice_getIdentity().name, 'test') && isempty(b1.ice_getIdentity().category) && ... 100 strcmp(b1.ice_getAdapterId(), 'adapter')); 101 try 102 b1 = communicator.stringToProxy('id@adapter test'); 103 assert(false); 104 catch ex 105 assert(isa(ex, 'Ice.ProxyParseException')); 106 end 107 b1 = communicator.stringToProxy('category/test@adapter'); 108 assert(strcmp(b1.ice_getIdentity().name, 'test') && ... 109 strcmp(b1.ice_getIdentity().category, 'category') && strcmp(b1.ice_getAdapterId(), 'adapter')); 110 b1 = communicator.stringToProxy('category/test@adapter:tcp'); 111 assert(strcmp(b1.ice_getIdentity().name, 'test') && ... 112 strcmp(b1.ice_getIdentity().category, 'category') && strcmp(b1.ice_getAdapterId(), 'adapter:tcp')); 113 b1 = communicator.stringToProxy('''category 1/test''@adapter'); 114 assert(strcmp(b1.ice_getIdentity().name, 'test') && ... 115 strcmp(b1.ice_getIdentity().category, 'category 1') && ... 116 strcmp(b1.ice_getAdapterId(), 'adapter')); 117 b1 = communicator.stringToProxy('''category/test 1''@adapter'); 118 assert(strcmp(b1.ice_getIdentity().name, 'test 1') && ... 119 strcmp(b1.ice_getIdentity().category, 'category') && ... 120 strcmp(b1.ice_getAdapterId(), 'adapter')); 121 b1 = communicator.stringToProxy('''category/test''@''adapter 1'''); 122 assert(strcmp(b1.ice_getIdentity().name, 'test') && ... 123 strcmp(b1.ice_getIdentity().category, 'category') && ... 124 strcmp(b1.ice_getAdapterId(), 'adapter 1')); 125 b1 = communicator.stringToProxy('"category \/test@foo/test"@adapter'); 126 assert(strcmp(b1.ice_getIdentity().name, 'test') && ... 127 strcmp(b1.ice_getIdentity().category, 'category /test@foo') && ... 128 strcmp(b1.ice_getAdapterId(), 'adapter')); 129 b1 = communicator.stringToProxy('"category \/test@foo/test"@"adapter:tcp"'); 130 assert(strcmp(b1.ice_getIdentity().name, 'test') && ... 131 strcmp(b1.ice_getIdentity().category, 'category /test@foo') && ... 132 strcmp(b1.ice_getAdapterId(), 'adapter:tcp')); 133 134 b1 = communicator.stringToProxy('id -f facet'); 135 assert(strcmp(b1.ice_getIdentity().name, 'id') && isempty(b1.ice_getIdentity().category) && ... 136 strcmp(b1.ice_getFacet(), 'facet')); 137 b1 = communicator.stringToProxy('id -f ''facet x'''); 138 assert(strcmp(b1.ice_getIdentity().name, 'id') && isempty(b1.ice_getIdentity().category) && ... 139 strcmp(b1.ice_getFacet(), 'facet x')); 140 b1 = communicator.stringToProxy('id -f "facet x"'); 141 assert(strcmp(b1.ice_getIdentity().name, 'id') && isempty(b1.ice_getIdentity().category) && ... 142 strcmp(b1.ice_getFacet(), 'facet x')); 143 try 144 b1 = communicator.stringToProxy('id -f "facet x'); 145 assert(false); 146 catch ex 147 assert(isa(ex, 'Ice.ProxyParseException')); 148 end 149 try 150 b1 = communicator.stringToProxy('id -f ''facet x'); 151 assert(false); 152 catch ex 153 assert(isa(ex, 'Ice.ProxyParseException')); 154 end 155 b1 = communicator.stringToProxy('test -f facet:tcp'); 156 assert(strcmp(b1.ice_getIdentity().name, 'test') && isempty(b1.ice_getIdentity().category) && ... 157 strcmp(b1.ice_getFacet(), 'facet') && isempty(b1.ice_getAdapterId())); 158 b1 = communicator.stringToProxy('test -f "facet:tcp"'); 159 assert(strcmp(b1.ice_getIdentity().name, 'test') && isempty(b1.ice_getIdentity().category) && ... 160 strcmp(b1.ice_getFacet(), 'facet:tcp') && isempty(b1.ice_getAdapterId())); 161 b1 = communicator.stringToProxy('test -f facet@test'); 162 assert(strcmp(b1.ice_getIdentity().name, 'test') && isempty(b1.ice_getIdentity().category) && ... 163 strcmp(b1.ice_getFacet(), 'facet') && strcmp(b1.ice_getAdapterId(), 'test')); 164 b1 = communicator.stringToProxy('test -f ''facet@test'''); 165 assert(strcmp(b1.ice_getIdentity().name, 'test') && isempty(b1.ice_getIdentity().category) && ... 166 strcmp(b1.ice_getFacet(), 'facet@test') && isempty(b1.ice_getAdapterId())); 167 b1 = communicator.stringToProxy('test -f ''facet@test''@test'); 168 assert(strcmp(b1.ice_getIdentity().name, 'test') && isempty(b1.ice_getIdentity().category) && ... 169 strcmp(b1.ice_getFacet(), 'facet@test') && strcmp(b1.ice_getAdapterId(), 'test')); 170 try 171 b1 = communicator.stringToProxy('test -f facet@test @test'); 172 assert(false); 173 catch ex 174 assert(isa(ex, 'Ice.ProxyParseException')); 175 end 176 b1 = communicator.stringToProxy('test'); 177 assert(b1.ice_isTwoway()); 178 b1 = communicator.stringToProxy('test -t'); 179 assert(b1.ice_isTwoway()); 180 b1 = communicator.stringToProxy('test -o'); 181 assert(b1.ice_isOneway()); 182 b1 = communicator.stringToProxy('test -O'); 183 assert(b1.ice_isBatchOneway()); 184 b1 = communicator.stringToProxy('test -d'); 185 assert(b1.ice_isDatagram()); 186 b1 = communicator.stringToProxy('test -D'); 187 assert(b1.ice_isBatchDatagram()); 188 b1 = communicator.stringToProxy('test'); 189 assert(~b1.ice_isSecure()); 190 b1 = communicator.stringToProxy('test -s'); 191 assert(b1.ice_isSecure()); 192 193 try 194 b1 = communicator.stringToProxy('test:tcp@adapterId'); 195 assert(false); 196 catch ex 197 assert(isa(ex, 'Ice.EndpointParseException')); 198 end 199 % This is an unknown endpoint warning, not a parse exception. 200 % 201 %try 202 % b1 = communicator.stringToProxy('test -f the:facet:tcp'); 203 % assert(false); 204 %catch ex 205 % assert(isa(ex, 'Ice.EndpointParseException')); 206 %end 207 try 208 b1 = communicator.stringToProxy('test::tcp'); 209 assert(false); 210 catch ex 211 assert(isa(ex, 'Ice.EndpointParseException')); 212 end 213 fprintf('ok\n'); 214 215 fprintf('testing propertyToProxy... '); 216 prop = communicator.getProperties(); 217 propertyPrefix = 'Foo.Proxy'; 218 prop.setProperty(propertyPrefix, 'test:default -p 12010'); 219 b1 = communicator.propertyToProxy(propertyPrefix); 220 assert(strcmp(b1.ice_getIdentity().name, 'test') && isempty(b1.ice_getIdentity().category) && ... 221 isempty(b1.ice_getAdapterId()) && isempty(b1.ice_getFacet())); 222 223 property = [propertyPrefix, '.Locator']; 224 assert(isempty(b1.ice_getLocator())); 225 prop.setProperty(property, 'locator:default -p 10000'); 226 b1 = communicator.propertyToProxy(propertyPrefix); 227 assert(~isempty(b1.ice_getLocator()) && strcmp(b1.ice_getLocator().ice_getIdentity().name, 'locator')); 228 prop.setProperty(property, ''); 229 230 property = [propertyPrefix, '.LocatorCacheTimeout']; 231 assert(b1.ice_getLocatorCacheTimeout() == -1) 232 prop.setProperty(property, '1'); 233 b1 = communicator.propertyToProxy(propertyPrefix); 234 assert(b1.ice_getLocatorCacheTimeout() == 1); 235 prop.setProperty(property, ''); 236 237 % Now retest with an indirect proxy. 238 prop.setProperty(propertyPrefix, 'test'); 239 property = [propertyPrefix, '.Locator']; 240 prop.setProperty(property, 'locator:default -p 10000'); 241 b1 = communicator.propertyToProxy(propertyPrefix); 242 assert(~isempty(b1.ice_getLocator()) && strcmp(b1.ice_getLocator().ice_getIdentity().name, 'locator')); 243 prop.setProperty(property, ''); 244 245 property = [propertyPrefix, '.LocatorCacheTimeout']; 246 assert(b1.ice_getLocatorCacheTimeout() == -1); 247 prop.setProperty(property, '1'); 248 b1 = communicator.propertyToProxy(propertyPrefix); 249 assert(b1.ice_getLocatorCacheTimeout() == 1); 250 prop.setProperty(property, ''); 251 252 % This cannot be tested so easily because the property is cached 253 % on communicator initialization. 254 % 255 %prop.setProperty('Ice.Default.LocatorCacheTimeout', '60'); 256 %b1 = communicator.propertyToProxy(propertyPrefix); 257 %assert(b1.ice_getLocatorCacheTimeout() == 60); 258 %prop.setProperty('Ice.Default.LocatorCacheTimeout', ''); 259 260 prop.setProperty(propertyPrefix, 'test:default -p 12010'); 261 262 property = [propertyPrefix, '.Router']; 263 assert(isempty(b1.ice_getRouter())); 264 prop.setProperty(property, 'router:default -p 10000'); 265 b1 = communicator.propertyToProxy(propertyPrefix); 266 assert(~isempty(b1.ice_getRouter()) && strcmp(b1.ice_getRouter().ice_getIdentity().name, 'router')); 267 prop.setProperty(property, ''); 268 269 property = [propertyPrefix, '.PreferSecure']; 270 assert(~b1.ice_isPreferSecure()); 271 prop.setProperty(property, '1'); 272 b1 = communicator.propertyToProxy(propertyPrefix); 273 assert(b1.ice_isPreferSecure()); 274 prop.setProperty(property, ''); 275 276 property = [propertyPrefix, '.ConnectionCached']; 277 assert(b1.ice_isConnectionCached()); 278 prop.setProperty(property, '0'); 279 b1 = communicator.propertyToProxy(propertyPrefix); 280 assert(~b1.ice_isConnectionCached()); 281 prop.setProperty(property, ''); 282 283 property = [propertyPrefix, '.InvocationTimeout']; 284 assert(b1.ice_getInvocationTimeout() == -1); 285 prop.setProperty(property, '1000'); 286 b1 = communicator.propertyToProxy(propertyPrefix); 287 assert(b1.ice_getInvocationTimeout() == 1000); 288 prop.setProperty(property, ''); 289 290 property = [propertyPrefix, '.EndpointSelection']; 291 assert(b1.ice_getEndpointSelection() == Ice.EndpointSelectionType.Random); 292 prop.setProperty(property, 'Random'); 293 b1 = communicator.propertyToProxy(propertyPrefix); 294 assert(b1.ice_getEndpointSelection() == Ice.EndpointSelectionType.Random); 295 prop.setProperty(property, 'Ordered'); 296 b1 = communicator.propertyToProxy(propertyPrefix); 297 assert(b1.ice_getEndpointSelection() == Ice.EndpointSelectionType.Ordered); 298 prop.setProperty(property, ''); 299 300 fprintf('ok\n'); 301 302 fprintf('testing proxyToProperty... '); 303 304 b1 = communicator.stringToProxy('test'); 305 b1 = b1.ice_connectionCached(true); 306 b1 = b1.ice_preferSecure(false); 307 b1 = b1.ice_endpointSelection(Ice.EndpointSelectionType.Ordered); 308 b1 = b1.ice_locatorCacheTimeout(100); 309 b1 = b1.ice_invocationTimeout(1234); 310 b1 = b1.ice_encodingVersion(Ice.EncodingVersion(1, 0)); 311 312 router = communicator.stringToProxy('router'); 313 router = router.ice_connectionCached(true); 314 router = router.ice_preferSecure(true); 315 router = router.ice_endpointSelection(Ice.EndpointSelectionType.Random); 316 router = router.ice_locatorCacheTimeout(200); 317 router = router.ice_invocationTimeout(1500); 318 319 locator = communicator.stringToProxy('locator'); 320 locator = locator.ice_connectionCached(false); 321 locator = locator.ice_preferSecure(true); 322 locator = locator.ice_endpointSelection(Ice.EndpointSelectionType.Random); 323 locator = locator.ice_locatorCacheTimeout(300); 324 locator = locator.ice_invocationTimeout(1500); 325 326 locator = locator.ice_router(Ice.RouterPrx.uncheckedCast(router)); 327 b1 = b1.ice_locator(Ice.LocatorPrx.uncheckedCast(locator)); 328 329 proxyProps = communicator.proxyToProperty(b1, 'Test'); 330 assert(length(proxyProps) == 21); 331 332 assert(strcmp(proxyProps('Test'), 'test -t -e 1.0')); 333 %assert(strcmp(proxyProps('Test.CollocationOptimized'), '1')); 334 assert(strcmp(proxyProps('Test.ConnectionCached'), '1')); 335 assert(strcmp(proxyProps('Test.PreferSecure'), '0')); 336 assert(strcmp(proxyProps('Test.EndpointSelection'), 'Ordered')); 337 assert(strcmp(proxyProps('Test.LocatorCacheTimeout'), '100')); 338 assert(strcmp(proxyProps('Test.InvocationTimeout'), '1234')); 339 340 assert(strcmp(proxyProps('Test.Locator'), ... 341 ['locator -t -e ', Ice.encodingVersionToString(Ice.currentEncoding())])); 342 %assert(strcmp(proxyProps('Test.Locator.CollocationOptimized'), '1')); 343 assert(strcmp(proxyProps('Test.Locator.ConnectionCached'), '0')); 344 assert(strcmp(proxyProps('Test.Locator.PreferSecure'), '1')); 345 assert(strcmp(proxyProps('Test.Locator.EndpointSelection'), 'Random')); 346 assert(strcmp(proxyProps('Test.Locator.LocatorCacheTimeout'), '300')); 347 assert(strcmp(proxyProps('Test.Locator.InvocationTimeout'), '1500')); 348 349 assert(strcmp(proxyProps('Test.Locator.Router'), ... 350 ['router -t -e ', Ice.encodingVersionToString(Ice.currentEncoding())])); 351 %assert(strcmp(proxyProps('Test.Locator.Router.CollocationOptimized'), '0')); 352 assert(strcmp(proxyProps('Test.Locator.Router.ConnectionCached'), '1')); 353 assert(strcmp(proxyProps('Test.Locator.Router.PreferSecure'), '1')); 354 assert(strcmp(proxyProps('Test.Locator.Router.EndpointSelection'), 'Random')); 355 assert(strcmp(proxyProps('Test.Locator.Router.LocatorCacheTimeout'), '200')); 356 assert(strcmp(proxyProps('Test.Locator.Router.InvocationTimeout'), '1500')); 357 358 fprintf('ok\n'); 359 360 fprintf('testing ice_getCommunicator... '); 361 362 assert(base.ice_getCommunicator() == communicator); 363 364 fprintf('ok\n'); 365 366 fprintf('testing proxy methods... '); 367 368 assert(strcmp(communicator.identityToString(base.ice_identity(Ice.stringToIdentity('other')).ice_getIdentity()), 'other')); 369 370 %{ 371 % TODO 372 % 373 % Verify that ToStringMode is passed correctly 374 % 375 euroStr = sprintf('\x7F\xE2\x82\xAC'); 376 ident = Ice.Identity('test', euroStr); 377 378 idStr = Ice.identityToString(ident, Ice.ToStringMode.Unicode); 379 assert(strcmp(idStr, sprintf('\x007f\xe2\x82\xac/test'))); 380 ident2 = Ice.stringToIdentity(idStr); 381 assert(ident == ident2); 382 assert(strcmp(Ice.identityToString(ident), idStr)); 383 384 idStr = Ice.identityToString(ident, Ice.ToStringMode.ASCII) 385 assert(idStr == "\\u007f\\u20ac/test") 386 ident2 = Ice.stringToIdentity(idStr) 387 assert(ident == ident2) 388 389 idStr = Ice.identityToString(ident, Ice.ToStringMode.Compat) 390 assert(idStr == "\\177\\342\\202\\254/test") 391 ident2 = Ice.stringToIdentity(idStr) 392 assert(ident == ident2) 393 394 ident2 = Ice.stringToIdentity(communicator.identityToString(ident)) 395 assert(ident == ident2) 396 %} 397 398 assert(strcmp(base.ice_facet('facet').ice_getFacet(), 'facet')); 399 assert(strcmp(base.ice_adapterId('id').ice_getAdapterId(), 'id')); 400 assert(base.ice_twoway().ice_isTwoway()); 401 assert(base.ice_oneway().ice_isOneway()); 402 assert(base.ice_batchOneway().ice_isBatchOneway()); 403 assert(base.ice_datagram().ice_isDatagram()); 404 assert(base.ice_batchDatagram().ice_isBatchDatagram()); 405 assert(base.ice_secure(true).ice_isSecure()); 406 assert(~base.ice_secure(false).ice_isSecure()); 407 %assert(base.ice_collocationOptimized(true).ice_isCollocationOptimized()); 408 %assert(~base.ice_collocationOptimized(false).ice_isCollocationOptimized()); 409 assert(base.ice_preferSecure(true).ice_isPreferSecure()); 410 assert(~base.ice_preferSecure(false).ice_isPreferSecure()); 411 assert(base.ice_encodingVersion(Ice.EncodingVersion(1, 0)).ice_getEncodingVersion() == Ice.EncodingVersion(1, 0)); 412 assert(base.ice_encodingVersion(Ice.EncodingVersion(1, 1)).ice_getEncodingVersion() == Ice.EncodingVersion(1, 1)); 413 assert(base.ice_encodingVersion(Ice.EncodingVersion(1, 0)).ice_getEncodingVersion() ~= Ice.EncodingVersion(1, 1)); 414 415 try 416 base.ice_timeout(0); 417 assert(false); 418 catch ex 419 end 420 421 try 422 base.ice_timeout(-1); 423 catch ex 424 assert(false); 425 end 426 427 try 428 base.ice_timeout(-2); 429 assert(false); 430 catch ex 431 end 432 433 try 434 base.ice_invocationTimeout(0); 435 assert(false); 436 catch ex 437 end 438 439 try 440 base.ice_invocationTimeout(-1); 441 catch ex 442 assert(false); 443 end 444 445 try 446 base.ice_invocationTimeout(-2); 447 assert(false); 448 catch ex 449 end 450 451 try 452 base.ice_locatorCacheTimeout(0); 453 catch ex 454 assert(false); 455 end 456 457 try 458 base.ice_locatorCacheTimeout(-1); 459 catch ex 460 assert(false); 461 end 462 463 try 464 base.ice_locatorCacheTimeout(-2); 465 assert(false); 466 catch ex 467 end 468 469 fprintf('ok\n'); 470 471 fprintf('testing proxy comparison... '); 472 473 assert(communicator.stringToProxy('foo') == communicator.stringToProxy('foo')); 474 assert(communicator.stringToProxy('foo') ~= communicator.stringToProxy('foo2')); 475 %assert(communicator.stringToProxy('foo') < communicator.stringToProxy('foo2')); 476 %assert(~(communicator.stringToProxy('foo2') < communicator.stringToProxy('foo'))); 477 478 compObj = communicator.stringToProxy('foo'); 479 480 assert(compObj.ice_facet('facet') == compObj.ice_facet('facet')); 481 assert(compObj.ice_facet('facet') ~= compObj.ice_facet('facet1')); 482 %assert(compObj.ice_facet('facet') < compObj.ice_facet('facet1')); 483 %assert(~(compObj.ice_facet('facet') < compObj.ice_facet('facet'))); 484 485 assert(compObj.ice_oneway() == compObj.ice_oneway()); 486 assert(compObj.ice_oneway() ~= compObj.ice_twoway()); 487 %assert(compObj.ice_twoway() < compObj.ice_oneway()); 488 %assert(~(compObj.ice_oneway() < compObj.ice_twoway())); 489 490 assert(compObj.ice_secure(true) == compObj.ice_secure(true)); 491 assert(compObj.ice_secure(false) ~= compObj.ice_secure(true)); 492 %assert(compObj.ice_secure(false) < compObj.ice_secure(true)); 493 %assert(~(compObj.ice_secure(true) < compObj.ice_secure(false))); 494 495 %assert(compObj.ice_collocationOptimized(true) == compObj.ice_collocationOptimized(true)); 496 %assert(compObj.ice_collocationOptimized(false) ~= compObj.ice_collocationOptimized(true)); 497 %assert(compObj.ice_collocationOptimized(false) < compObj.ice_collocationOptimized(true)); 498 %assert(~(compObj.ice_collocationOptimized(true) < compObj.ice_collocationOptimized(false))); 499 500 assert(compObj.ice_connectionCached(true) == compObj.ice_connectionCached(true)); 501 assert(compObj.ice_connectionCached(false) ~= compObj.ice_connectionCached(true)); 502 %assert(compObj.ice_connectionCached(false) < compObj.ice_connectionCached(true)); 503 %assert(~(compObj.ice_connectionCached(true) < compObj.ice_connectionCached(false))); 504 505 assert(compObj.ice_endpointSelection(Ice.EndpointSelectionType.Random) == ... 506 compObj.ice_endpointSelection(Ice.EndpointSelectionType.Random)); 507 assert(compObj.ice_endpointSelection(Ice.EndpointSelectionType.Random) ~= ... 508 compObj.ice_endpointSelection(Ice.EndpointSelectionType.Ordered)); 509 %assert(compObj.ice_endpointSelection(Ice.EndpointSelectionType.Random) < ... 510 % compObj.ice_endpointSelection(Ice.EndpointSelectionType.Ordered)); 511 %assert(~(compObj.ice_endpointSelection(Ice.EndpointSelectionType.Ordered) < ... 512 % compObj.ice_endpointSelection(Ice.EndpointSelectionType.Random))); 513 514 assert(compObj.ice_connectionId('id2') == compObj.ice_connectionId('id2')); 515 assert(compObj.ice_connectionId('id1') ~= compObj.ice_connectionId('id2')); 516 %assert(compObj.ice_connectionId('id1') < compObj.ice_connectionId('id2')); 517 %assert(~(compObj.ice_connectionId('id2') < compObj.ice_connectionId('id1'))); 518 assert(strcmp(compObj.ice_connectionId('id1').ice_getConnectionId(), 'id1')); 519 assert(strcmp(compObj.ice_connectionId('id2').ice_getConnectionId(), 'id2')); 520 521 assert(compObj.ice_compress(true) == compObj.ice_compress(true)); 522 assert(compObj.ice_compress(false) ~= compObj.ice_compress(true)); 523 %assert(compObj.ice_compress(false) < compObj.ice_compress(true)); 524 %assert(~(compObj.ice_compress(true) < compObj.ice_compress(false))); 525 526 assert(compObj.ice_getCompress() == Ice.Unset); 527 assert(compObj.ice_compress(true).ice_getCompress() == true); 528 assert(compObj.ice_compress(false).ice_getCompress() == false); 529 530 assert(compObj.ice_timeout(20) == compObj.ice_timeout(20)); 531 assert(compObj.ice_timeout(10) ~= compObj.ice_timeout(20)); 532 %assert(compObj.ice_timeout(10) < compObj.ice_timeout(20)); 533 %assert(~(compObj.ice_timeout(20) < compObj.ice_timeout(10))); 534 535 assert(compObj.ice_getTimeout() == Ice.Unset); 536 assert(compObj.ice_timeout(10).ice_getTimeout() == 10); 537 assert(compObj.ice_timeout(20).ice_getTimeout() == 20); 538 539 loc1 = Ice.LocatorPrx.uncheckedCast(communicator.stringToProxy('loc1:default -p 10000')); 540 loc2 = Ice.LocatorPrx.uncheckedCast(communicator.stringToProxy('loc2:default -p 10000')); 541 assert(compObj.ice_locator([]) == compObj.ice_locator([])); 542 assert(compObj.ice_locator(loc1) == compObj.ice_locator(loc1)); 543 assert(compObj.ice_locator(loc1) ~= compObj.ice_locator([])); 544 assert(compObj.ice_locator([]) ~= compObj.ice_locator(loc2)); 545 assert(compObj.ice_locator(loc1) ~= compObj.ice_locator(loc2)); 546 %assert(compObj.ice_locator([]) < compObj.ice_locator(loc1)); 547 %assert(~(compObj.ice_locator(loc1) < compObj.ice_locator([]))); 548 %assert(compObj.ice_locator(loc1) < compObj.ice_locator(loc2)); 549 %assert(~(compObj.ice_locator(loc2) < compObj.ice_locator(loc1))); 550 551 rtr1 = Ice.RouterPrx.uncheckedCast(communicator.stringToProxy('rtr1:default -p 10000')); 552 rtr2 = Ice.RouterPrx.uncheckedCast(communicator.stringToProxy('rtr2:default -p 10000')); 553 assert(compObj.ice_router([]) == compObj.ice_router([])); 554 assert(compObj.ice_router(rtr1) == compObj.ice_router(rtr1)); 555 assert(compObj.ice_router(rtr1) ~= compObj.ice_router([])); 556 assert(compObj.ice_router([]) ~= compObj.ice_router(rtr2)); 557 assert(compObj.ice_router(rtr1) ~= compObj.ice_router(rtr2)); 558 %assert(compObj.ice_router([]) < compObj.ice_router(rtr1)); 559 %assert(~(compObj.ice_router(rtr1) < compObj.ice_router([]))); 560 %assert(compObj.ice_router(rtr1) < compObj.ice_router(rtr2)); 561 %assert(~(compObj.ice_router(rtr2) < compObj.ice_router(rtr1))); 562 563 ctx1 = containers.Map('KeyType', 'char', 'ValueType', 'char'); 564 ctx1('ctx1') = 'v1'; 565 ctx2 = containers.Map('KeyType', 'char', 'ValueType', 'char'); 566 ctx2('ctx2') = 'v2'; 567 empty = containers.Map('KeyType', 'char', 'ValueType', 'char'); 568 assert(compObj.ice_context(empty) == compObj.ice_context(empty)); 569 assert(compObj.ice_context(ctx1) == compObj.ice_context(ctx1)); 570 assert(compObj.ice_context(ctx1) ~= compObj.ice_context(empty)); 571 assert(compObj.ice_context(empty) ~= compObj.ice_context(ctx2)); 572 assert(compObj.ice_context(ctx1) ~= compObj.ice_context(ctx2)); 573 %assert(compObj.ice_context(ctx1) < compObj.ice_context(ctx2)); 574 %assert(~(compObj.ice_context(ctx2) < compObj.ice_context(ctx1))); 575 576 assert(compObj.ice_preferSecure(true) == compObj.ice_preferSecure(true)); 577 assert(compObj.ice_preferSecure(true) ~= compObj.ice_preferSecure(false)); 578 %assert(compObj.ice_preferSecure(false) < compObj.ice_preferSecure(true)); 579 %assert(~(compObj.ice_preferSecure(true) < compObj.ice_preferSecure(false))); 580 581 compObj1 = communicator.stringToProxy('foo:tcp -h 127.0.0.1 -p 10000'); 582 compObj2 = communicator.stringToProxy('foo:tcp -h 127.0.0.1 -p 10001'); 583 assert(compObj1 ~= compObj2); 584 %assert(compObj1 < compObj2); 585 %assert(~(compObj2 < compObj1)); 586 587 compObj1 = communicator.stringToProxy('foo@MyAdapter1'); 588 compObj2 = communicator.stringToProxy('foo@MyAdapter2'); 589 assert(compObj1 ~= compObj2); 590 %assert(compObj1 < compObj2); 591 %assert(~(compObj2 < compObj1)); 592 593 assert(compObj1.ice_locatorCacheTimeout(20) == compObj1.ice_locatorCacheTimeout(20)); 594 assert(compObj1.ice_locatorCacheTimeout(10) ~= compObj1.ice_locatorCacheTimeout(20)); 595 %assert(compObj1.ice_locatorCacheTimeout(10) < compObj1.ice_locatorCacheTimeout(20)); 596 %assert(~(compObj1.ice_locatorCacheTimeout(20) < compObj1.ice_locatorCacheTimeout(10))); 597 598 assert(compObj1.ice_invocationTimeout(20) == compObj1.ice_invocationTimeout(20)); 599 assert(compObj1.ice_invocationTimeout(10) ~= compObj1.ice_invocationTimeout(20)); 600 %assert(compObj1.ice_invocationTimeout(10) < compObj1.ice_invocationTimeout(20)); 601 %assert(~(compObj1.ice_invocationTimeout(20) < compObj1.ice_invocationTimeout(10))); 602 603 compObj1 = communicator.stringToProxy('foo:tcp -h 127.0.0.1 -p 1000'); 604 compObj2 = communicator.stringToProxy('foo@MyAdapter1'); 605 assert(compObj1 ~= compObj2); 606 %assert(compObj1 < compObj2); 607 %assert(~(compObj2 < compObj1)); 608 609 endpts1 = communicator.stringToProxy('foo:tcp -h 127.0.0.1 -p 10000').ice_getEndpoints(); 610 endpts2 = communicator.stringToProxy('foo:tcp -h 127.0.0.1 -p 10001').ice_getEndpoints(); 611 assert(endpts1{1} ~= endpts2{1}); 612 %assert(endpts1 < endpts2); 613 %assert(~(endpts2 < endpts1)); 614 endpts3 = communicator.stringToProxy('foo:tcp -h 127.0.0.1 -p 10000').ice_getEndpoints(); 615 assert(endpts1{1} == endpts3{1}); 616 617 assert(compObj1.ice_encodingVersion(Ice.EncodingVersion(1, 0)) == ... 618 compObj1.ice_encodingVersion(Ice.EncodingVersion(1, 0))); 619 assert(compObj1.ice_encodingVersion(Ice.EncodingVersion(1, 0)) ~= ... 620 compObj1.ice_encodingVersion(Ice.EncodingVersion(1, 1))); 621 %assert(compObj.ice_encodingVersion(Ice.EncodingVersion(1, 0)) < ... 622 % compObj.ice_encodingVersion(Ice.EncodingVersion(1, 1))); 623 %assert(~(compObj.ice_encodingVersion(Ice.EncodingVersion(1, 1)) < ... 624 % compObj.ice_encodingVersion(Ice.EncodingVersion(1, 0)))); 625 626 baseConnection = base.ice_getConnection(); 627 if ~isempty(baseConnection) 628 baseConnection2 = base.ice_connectionId('base2').ice_getConnection(); 629 compObj1 = compObj1.ice_fixed(baseConnection); 630 compObj2 = compObj2.ice_fixed(baseConnection2); 631 assert(compObj1 ~= compObj2); 632 end 633 634 fprintf('ok\n'); 635 636 fprintf('testing checked cast... '); 637 cl = MyClassPrx.checkedCast(base); 638 assert(~isempty(cl)); 639 640 derived = MyDerivedClassPrx.checkedCast(cl); 641 assert(~isempty(derived)); 642 assert(cl == base); 643 assert(derived == base); 644 assert(cl == derived); 645 646 loc = Ice.LocatorPrx.checkedCast(base); 647 assert(isempty(loc)); 648 649 % 650 % Upcasting 651 % 652 cl2 = MyClassPrx.checkedCast(derived); 653 obj = Ice.ObjectPrx.checkedCast(derived); 654 assert(~isempty(cl2)); 655 assert(~isempty(obj)); 656 assert(cl2 == obj); 657 assert(cl2 == derived); 658 659 fprintf('ok\n'); 660 661 fprintf('testing checked cast with context... '); 662 tccp = MyClassPrx.checkedCast(base); 663 c = tccp.getContext(); 664 assert(isempty(c)); 665 666 c = containers.Map('KeyType', 'char', 'ValueType', 'char'); 667 c('one') = 'hello'; 668 c('two') = 'world'; 669 tccp = MyClassPrx.checkedCast(base, c); 670 c2 = tccp.getContext(); 671 assert(isequal(c, c2)); 672 fprintf('ok\n'); 673 674 fprintf('testing ice_fixed... '); 675 connection = cl.ice_getConnection(); 676 if ~isempty(connection) 677 prx = cl.ice_fixed(connection); % Test factory method return type 678 prx.ice_ping(); 679 assert(cl.ice_secure(true).ice_fixed(connection).ice_isSecure()); 680 assert(strcmp(cl.ice_facet('facet').ice_fixed(connection).ice_getFacet(), 'facet')); 681 assert(cl.ice_oneway().ice_fixed(connection).ice_isOneway()); 682 ctx = containers.Map('KeyType', 'char', 'ValueType', 'char'); 683 ctx('one') = 'hello'; 684 ctx('two') = 'world'; 685 assert(isempty(cl.ice_fixed(connection).ice_getContext())); 686 assert(cl.ice_context(ctx).ice_fixed(connection).ice_getContext().length() == 2); 687 assert(cl.ice_fixed(connection).ice_getInvocationTimeout() == -1); 688 assert(cl.ice_invocationTimeout(10).ice_fixed(connection).ice_getInvocationTimeout() == 10); 689 assert(cl.ice_fixed(connection).ice_getConnection() == connection); 690 assert(cl.ice_fixed(connection).ice_fixed(connection).ice_getConnection() == connection); 691 assert(cl.ice_compress(true).ice_fixed(connection).ice_getCompress() == true); 692 assert(cl.ice_fixed(connection).ice_getTimeout() == Ice.Unset); 693 fixedConnection = cl.ice_connectionId('ice_fixed').ice_getConnection(); 694 assert(cl.ice_fixed(connection).ice_fixed(fixedConnection).ice_getConnection() == fixedConnection); 695 try 696 cl.ice_secure(~connection.getEndpoint().getInfo().secure()).ice_fixed(connection).ice_ping(); 697 catch ex 698 if ~isa(ex, 'Ice.NoEndpointException') 699 rethrow(ex); 700 end 701 end 702 try 703 cl.ice_datagram().ice_fixed(connection).ice_ping(); 704 catch ex 705 if ~isa(ex, 'Ice.NoEndpointException') 706 rethrow(ex); 707 end 708 end 709 else 710 try 711 cl.ice_fixed(connection); 712 assert(false); 713 catch ex 714 % Expected with null connection. 715 end 716 end 717 fprintf('ok\n'); 718 719 fprintf('testing encoding versioning... '); 720 ref20 = 'test -e 2.0:default -p 12010'; 721 cl20 = MyClassPrx.uncheckedCast(communicator.stringToProxy(ref20)); 722 try 723 cl20.ice_ping(); 724 assert(false); 725 catch ex 726 % Server 2.0 endpoint doesn't support 1.1 version. 727 assert(isa(ex, 'Ice.UnsupportedEncodingException')); 728 end 729 730 ref10 = 'test -e 1.0:default -p 12010'; 731 cl10 = MyClassPrx.uncheckedCast(communicator.stringToProxy(ref10)); 732 cl10.ice_ping(); 733 cl10.ice_encodingVersion(Ice.EncodingVersion(1, 0)).ice_ping(); 734 cl.ice_encodingVersion(Ice.EncodingVersion(1, 0)).ice_ping(); 735 736 % 1.3 isn't supported but since a 1.3 proxy supports 1.1, the 737 % call will use the 1.1 encoding 738 ref13 = 'test -e 1.3:default -p 12010'; 739 cl13 = MyClassPrx.uncheckedCast(communicator.stringToProxy(ref13)); 740 cl13.ice_ping(); 741 742 fprintf('ok\n'); 743 744 fprintf('testing opaque endpoints... '); 745 746 try 747 % Invalid -x option 748 p = communicator.stringToProxy('id:opaque -t 99 -v abc -x abc'); 749 assert(false); 750 catch ex 751 assert(isa(ex, 'Ice.EndpointParseException')); 752 end 753 754 try 755 % Missing -t and -v 756 p = communicator.stringToProxy('id:opaque'); 757 assert(false); 758 catch ex 759 assert(isa(ex, 'Ice.EndpointParseException')); 760 end 761 762 try 763 % Repeated -t 764 p = communicator.stringToProxy('id:opaque -t 1 -t 1 -v abc'); 765 assert(false); 766 catch ex 767 assert(isa(ex, 'Ice.EndpointParseException')); 768 end 769 770 try 771 % Repeated -v 772 p = communicator.stringToProxy('id:opaque -t 1 -v abc -v abc') 773 assert(false) 774 catch ex 775 assert(isa(ex, 'Ice.EndpointParseException')); 776 end 777 778 try 779 % Missing -t 780 p = communicator.stringToProxy('id:opaque -v abc'); 781 assert(false); 782 catch ex 783 assert(isa(ex, 'Ice.EndpointParseException')); 784 end 785 786 try 787 % Missing -v 788 p = communicator.stringToProxy('id:opaque -t 1'); 789 assert(false); 790 catch ex 791 assert(isa(ex, 'Ice.EndpointParseException')); 792 end 793 794 try 795 % Missing arg for -t 796 p = communicator.stringToProxy('id:opaque -t -v abc'); 797 assert(false); 798 catch ex 799 assert(isa(ex, 'Ice.EndpointParseException')); 800 end 801 802 try 803 % Missing arg for -v 804 p = communicator.stringToProxy('id:opaque -t 1 -v'); 805 assert(false); 806 catch ex 807 assert(isa(ex, 'Ice.EndpointParseException')); 808 end 809 810 try 811 % Not a number for -t 812 p = communicator.stringToProxy('id:opaque -t x -v abc'); 813 assert(false); 814 catch ex 815 assert(isa(ex, 'Ice.EndpointParseException')); 816 end 817 818 try 819 % < 0 for -t 820 p = communicator.stringToProxy('id:opaque -t -1 -v abc'); 821 assert(false); 822 catch ex 823 assert(isa(ex, 'Ice.EndpointParseException')); 824 end 825 826 try 827 % Invalid char for -v 828 p = communicator.stringToProxy('id:opaque -t 99 -v x?c'); 829 assert(false); 830 catch ex 831 assert(isa(ex, 'Ice.EndpointParseException')); 832 end 833 834 % Legal TCP endpoint expressed as opaque endpoint 835 p1 = communicator.stringToProxy('test -e 1.1:opaque -t 1 -e 1.0 -v CTEyNy4wLjAuMeouAAAQJwAAAA=='); 836 pstr = communicator.proxyToString(p1); 837 assert(strcmp(pstr, 'test -t -e 1.1:tcp -h 127.0.0.1 -p 12010 -t 10000')); 838 839 % Opaque endpoint encoded with 1.1 encoding. 840 p2 = communicator.stringToProxy('test -e 1.1:opaque -e 1.1 -t 1 -v CTEyNy4wLjAuMeouAAAQJwAAAA=='); 841 assert(strcmp(communicator.proxyToString(p2), 'test -t -e 1.1:tcp -h 127.0.0.1 -p 12010 -t 10000')); 842 843 if communicator.getProperties().getPropertyAsInt('Ice.IPv6') == 0 844 % Working? 845 ssl = strcmp(communicator.getProperties().getProperty('Ice.Default.Protocol'), 'ssl'); 846 tcp = strcmp(communicator.getProperties().getProperty('Ice.Default.Protocol'), 'tcp'); 847 if tcp 848 p1.ice_encodingVersion(Ice.EncodingVersion(1, 0)).ice_ping(); 849 end 850 851 % Two legal TCP endpoints expressed as opaque endpoints 852 p1 = communicator.stringToProxy('test -e 1.0:opaque -t 1 -e 1.0 -v CTEyNy4wLjAuMeouAAAQJwAAAA==:opaque -t 1 -e 1.0 -v CTEyNy4wLjAuMusuAAAQJwAAAA=='); 853 pstr = communicator.proxyToString(p1); 854 assert(strcmp(pstr, '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')); 855 856 % 857 % Test that an SSL endpoint and a nonsense endpoint get written 858 % back out as an opaque endpoint. 859 % 860 p1 = communicator.stringToProxy('test -e 1.0:opaque -t 2 -e 1.0 -v CTEyNy4wLjAuMREnAAD/////AA==:opaque -t 99 -e 1.0 -v abch'); 861 pstr = communicator.proxyToString(p1); 862 if ssl 863 assert(strcmp(pstr, 'test -t -e 1.0:ssl -h 127.0.0.1 -p 10001 -t infinite:opaque -t 99 -e 1.0 -v abch')); 864 elseif tcp 865 assert(strcmp(pstr, 'test -t -e 1.0:opaque -t 2 -e 1.0 -v CTEyNy4wLjAuMREnAAD/////AA==:opaque -t 99 -e 1.0 -v abch')); 866 end 867 868 % 869 % Try to invoke on the SSL endpoint to verify that we get a 870 % NoEndpointException (or ConnectionRefusedException when 871 % running with SSL). 872 % 873 try 874 p1.ice_encodingVersion(Ice.EncodingVersion(1, 0)).ice_ping(); 875 assert(false); 876 catch ex 877 if isa(ex, 'Ice.NoEndpointException') 878 assert(~ssl); 879 elseif isa(ex, 'Ice.ConnectFailedException') 880 assert(~tcp); 881 else 882 rethrow(ex); 883 end 884 end 885 886 % 887 % Test that the proxy with an SSL endpoint and a nonsense 888 % endpoint (which the server doesn't understand either) can be 889 % sent over the wire and returned by the server without losing 890 % the opaque endpoints. 891 % 892 p2 = derived.echo(p1); 893 pstr = communicator.proxyToString(p2); 894 if ssl 895 assert(strcmp(pstr, 'test -t -e 1.0:ssl -h 127.0.0.1 -p 10001 -t infinite:opaque -t 99 -e 1.0 -v abch')); 896 elseif tcp 897 assert(strcmp(pstr, 'test -t -e 1.0:opaque -t 2 -e 1.0 -v CTEyNy4wLjAuMREnAAD/////AA==:opaque -t 99 -e 1.0 -v abch')); 898 end 899 end 900 901 fprintf('ok\n'); 902 903 r = cl; 904 end 905 end 906end 907