public static TestIntfPrx allTests(Ice.Communicator communicator) #endif { Write("testing stringToProxy... "); Flush(); string @ref = "asm:default -p 12010"; Ice.ObjectPrx @base = communicator.stringToProxy(@ref); test(@base != null); WriteLine("ok"); Write("testing checked cast... "); Flush(); TestIntfPrx obj = TestIntfPrxHelper.checkedCast(@base); test(obj != null); test(obj.Equals(@base)); WriteLine("ok"); Write("testing ice_ids... "); Flush(); try { Ice.ObjectPrx o = communicator.stringToProxy("category/locate:default -p 12010"); o.ice_ids(); test(false); } catch (UnknownUserException ex) { test(ex.unknown.Equals("Test::TestIntfUserException")); } catch (System.Exception) { test(false); } try { Ice.ObjectPrx o = communicator.stringToProxy("category/finished:default -p 12010"); o.ice_ids(); test(false); } catch (UnknownUserException ex) { test(ex.unknown.Equals("Test::TestIntfUserException")); } catch (System.Exception) { test(false); } WriteLine("ok"); Write("testing servant locator..."); Flush(); @base = communicator.stringToProxy("category/locate:default -p 12010"); obj = TestIntfPrxHelper.checkedCast(@base); try { TestIntfPrxHelper.checkedCast(communicator.stringToProxy("category/unknown:default -p 12010")); } catch (ObjectNotExistException) { } WriteLine("ok"); Write("testing default servant locator..."); Flush(); @base = communicator.stringToProxy("anothercat/locate:default -p 12010"); obj = TestIntfPrxHelper.checkedCast(@base); @base = communicator.stringToProxy("locate:default -p 12010"); obj = TestIntfPrxHelper.checkedCast(@base); try { TestIntfPrxHelper.checkedCast(communicator.stringToProxy("anothercat/unknown:default -p 12010")); } catch (ObjectNotExistException) { } try { TestIntfPrxHelper.checkedCast(communicator.stringToProxy("unknown:default -p 12010")); } catch (ObjectNotExistException) { } WriteLine("ok"); Write("testing locate exceptions... "); Flush(); @base = communicator.stringToProxy("category/locate:default -p 12010"); obj = TestIntfPrxHelper.checkedCast(@base); testExceptions(obj); WriteLine("ok"); Write("testing finished exceptions... "); Flush(); @base = communicator.stringToProxy("category/finished:default -p 12010"); obj = TestIntfPrxHelper.checkedCast(@base); testExceptions(obj); // // Only call these for category/finished. // try { obj.asyncResponse(); } catch (TestIntfUserException) { test(false); } catch (TestImpossibleException) { // // Called by finished(). // } // // Only call these for category/finished. // try { obj.asyncException(); } catch (TestIntfUserException) { test(false); } catch (TestImpossibleException) { // // Called by finished(). // } WriteLine("ok"); Write("testing servant locator removal... "); Flush(); @base = communicator.stringToProxy("test/activation:default -p 12010"); TestActivationPrx activation = TestActivationPrxHelper.checkedCast(@base); activation.activateServantLocator(false); try { obj.ice_ping(); test(false); } catch (ObjectNotExistException) { WriteLine("ok"); } Write("testing servant locator addition... "); Flush(); activation.activateServantLocator(true); try { obj.ice_ping(); WriteLine("ok"); } catch (System.Exception) { test(false); } #if SILVERLIGHT obj.shutdown(); #else return(obj); #endif }
public static void allTests(Ice.Communicator communicator) { Console.Out.Write("testing stringToProxy... "); Console.Out.Flush(); String rf = "test @ TestAdapter"; Ice.ObjectPrx @base = communicator.stringToProxy(rf); test(@base != null); Console.Out.WriteLine("ok"); Console.Out.Write("testing IceGrid.Locator is present... "); IceGrid.LocatorPrx locator = IceGrid.LocatorPrxHelper.uncheckedCast(@base); test(locator != null); Console.Out.WriteLine("ok"); Console.Out.Write("testing checked cast... "); Console.Out.Flush(); TestIntfPrx obj = TestIntfPrxHelper.checkedCast(@base); test(obj != null); test(obj.Equals(@base)); Console.Out.WriteLine("ok"); Console.Out.Write("pinging server... "); Console.Out.Flush(); obj.ice_ping(); Console.Out.WriteLine("ok"); Console.Out.Write("testing locator finder... "); Ice.Identity finderId = new Ice.Identity(); finderId.category = "Ice"; finderId.name = "LocatorFinder"; Ice.LocatorFinderPrx finder = Ice.LocatorFinderPrxHelper.checkedCast( communicator.getDefaultLocator().ice_identity(finderId)); test(finder.getLocator() != null); Console.Out.WriteLine("ok"); Console.Out.Write("testing discovery... "); { // Add test well-known object IceGrid.RegistryPrx registry = IceGrid.RegistryPrxHelper.checkedCast( communicator.stringToProxy(communicator.getDefaultLocator().ice_getIdentity().category + "/Registry")); test(registry != null); try { IceGrid.AdminSessionPrx session = registry.createAdminSession("foo", "bar"); session.getAdmin().addObjectWithType(@base, "::Test"); session.destroy(); } catch (Ice.UserException) { test(false); } // // Ensure the IceGrid discovery locator can discover the // registries and make sure locator requests are forwarded. // Ice.InitializationData initData = new Ice.InitializationData(); initData.properties = communicator.getProperties().ice_clone_(); initData.properties.setProperty("Ice.Default.Locator", ""); initData.properties.setProperty("Ice.Plugin.IceLocatorDiscovery", "IceLocatorDiscovery:IceLocatorDiscovery.PluginFactory"); if (IceInternal.AssemblyUtil.osx_ && initData.properties.getPropertyAsInt("Ice.PreferIPv6Address") > 0) { initData.properties.setProperty("IceLocatorDiscovery.Interface", "::1"); } initData.properties.setProperty("AdapterForDiscoveryTest.AdapterId", "discoveryAdapter"); initData.properties.setProperty("AdapterForDiscoveryTest.Endpoints", "default"); Ice.Communicator com = Ice.Util.initialize(initData); test(com.getDefaultLocator() != null); com.stringToProxy("test @ TestAdapter").ice_ping(); com.stringToProxy("test").ice_ping(); test(com.getDefaultLocator().getRegistry() != null); test(IceGrid.LocatorPrxHelper.uncheckedCast(com.getDefaultLocator()).getLocalRegistry() != null); test(IceGrid.LocatorPrxHelper.uncheckedCast(com.getDefaultLocator()).getLocalQuery() != null); Ice.ObjectAdapter adapter = com.createObjectAdapter("AdapterForDiscoveryTest"); adapter.activate(); adapter.deactivate(); com.destroy(); // // Now, ensure that the IceGrid discovery locator correctly // handles failure to find a locator. // initData.properties.setProperty("IceLocatorDiscovery.InstanceName", "unknown"); initData.properties.setProperty("IceLocatorDiscovery.RetryCount", "1"); initData.properties.setProperty("IceLocatorDiscovery.Timeout", "100"); com = Ice.Util.initialize(initData); test(com.getDefaultLocator() != null); try { com.stringToProxy("test @ TestAdapter").ice_ping(); } catch (Ice.NoEndpointException) { } try { com.stringToProxy("test").ice_ping(); } catch (Ice.NoEndpointException) { } test(com.getDefaultLocator().getRegistry() == null); test(IceGrid.LocatorPrxHelper.checkedCast(com.getDefaultLocator()) == null); try { IceGrid.LocatorPrxHelper.uncheckedCast(com.getDefaultLocator()).getLocalRegistry(); } catch (Ice.OperationNotExistException) { } adapter = com.createObjectAdapter("AdapterForDiscoveryTest"); adapter.activate(); adapter.deactivate(); com.destroy(); } Console.Out.WriteLine("ok"); System.Console.Out.Write("shutting down server... "); System.Console.Out.Flush(); obj.shutdown(); System.Console.Out.WriteLine("ok"); }
public static TestIntfPrx allTests(Ice.Communicator communicator) #endif { string sref = "test:default -p 12010"; Ice.ObjectPrx obj = communicator.stringToProxy(sref); test(obj != null); TestIntfPrx proxy = TestIntfPrxHelper.uncheckedCast(obj); test(proxy != null); Console.Out.Write("testing enum values... "); Console.Out.Flush(); test((int)ByteEnum.benum1 == 0); test((int)ByteEnum.benum2 == 1); test((int)ByteEnum.benum3 == ByteConst1.value); test((int)ByteEnum.benum4 == ByteConst1.value + 1); test((int)ByteEnum.benum5 == ShortConst1.value); test((int)ByteEnum.benum6 == ShortConst1.value + 1); test((int)ByteEnum.benum7 == IntConst1.value); test((int)ByteEnum.benum8 == IntConst1.value + 1); test((int)ByteEnum.benum9 == LongConst1.value); test((int)ByteEnum.benum10 == LongConst1.value + 1); test((int)ByteEnum.benum11 == ByteConst2.value); test((int)ShortEnum.senum1 == 3); test((int)ShortEnum.senum2 == 4); test((int)ShortEnum.senum3 == ByteConst1.value); test((int)ShortEnum.senum4 == ByteConst1.value + 1); test((int)ShortEnum.senum5 == ShortConst1.value); test((int)ShortEnum.senum6 == ShortConst1.value + 1); test((int)ShortEnum.senum7 == IntConst1.value); test((int)ShortEnum.senum8 == IntConst1.value + 1); test((int)ShortEnum.senum9 == LongConst1.value); test((int)ShortEnum.senum10 == LongConst1.value + 1); test((int)ShortEnum.senum11 == ShortConst2.value); test((int)IntEnum.ienum1 == 0); test((int)IntEnum.ienum2 == 1); test((int)IntEnum.ienum3 == ByteConst1.value); test((int)IntEnum.ienum4 == ByteConst1.value + 1); test((int)IntEnum.ienum5 == ShortConst1.value); test((int)IntEnum.ienum6 == ShortConst1.value + 1); test((int)IntEnum.ienum7 == IntConst1.value); test((int)IntEnum.ienum8 == IntConst1.value + 1); test((int)IntEnum.ienum9 == LongConst1.value); test((int)IntEnum.ienum10 == LongConst1.value + 1); test((int)IntEnum.ienum11 == IntConst2.value); test((int)IntEnum.ienum12 == LongConst2.value); test((int)SimpleEnum.red == 0); test((int)SimpleEnum.green == 1); test((int)SimpleEnum.blue == 2); Console.Out.WriteLine("ok"); Console.Out.Write("testing enum streaming... "); Console.Out.Flush(); Ice.OutputStream ostr; byte[] bytes; bool encoding_1_0 = communicator.getProperties().getProperty("Ice.Default.EncodingVersion").Equals("1.0"); ostr = Ice.Util.createOutputStream(communicator); ByteEnumHelper.write(ostr, ByteEnum.benum11); bytes = ostr.finished(); test(bytes.Length == 1); // ByteEnum should require one byte ostr = Ice.Util.createOutputStream(communicator); ShortEnumHelper.write(ostr, ShortEnum.senum11); bytes = ostr.finished(); test(bytes.Length == (encoding_1_0 ? 2 : 5)); ostr = Ice.Util.createOutputStream(communicator); IntEnumHelper.write(ostr, IntEnum.ienum11); bytes = ostr.finished(); test(bytes.Length == (encoding_1_0 ? 4 : 5)); ostr = Ice.Util.createOutputStream(communicator); SimpleEnumHelper.write(ostr, SimpleEnum.blue); bytes = ostr.finished(); test(bytes.Length == 1); // SimpleEnum should require one byte Console.Out.WriteLine("ok"); Console.Out.Write("testing enum operations... "); Console.Out.Flush(); ByteEnum byteEnum; test(proxy.opByte(ByteEnum.benum1, out byteEnum) == ByteEnum.benum1); test(byteEnum == ByteEnum.benum1); test(proxy.opByte(ByteEnum.benum11, out byteEnum) == ByteEnum.benum11); test(byteEnum == ByteEnum.benum11); ShortEnum shortEnum; test(proxy.opShort(ShortEnum.senum1, out shortEnum) == ShortEnum.senum1); test(shortEnum == ShortEnum.senum1); test(proxy.opShort(ShortEnum.senum11, out shortEnum) == ShortEnum.senum11); test(shortEnum == ShortEnum.senum11); IntEnum intEnum; test(proxy.opInt(IntEnum.ienum1, out intEnum) == IntEnum.ienum1); test(intEnum == IntEnum.ienum1); test(proxy.opInt(IntEnum.ienum11, out intEnum) == IntEnum.ienum11); test(intEnum == IntEnum.ienum11); test(proxy.opInt(IntEnum.ienum12, out intEnum) == IntEnum.ienum12); test(intEnum == IntEnum.ienum12); SimpleEnum s; test(proxy.opSimple(SimpleEnum.green, out s) == SimpleEnum.green); test(s == SimpleEnum.green); Console.Out.WriteLine("ok"); Console.Out.Write("testing enum exceptions... "); Console.Out.Flush(); try { ostr = Ice.Util.createOutputStream(communicator); ostr.writeByte((byte)128); // Invalid enumerator Ice.InputStream istr = Ice.Util.createInputStream(communicator, ostr.finished()); ByteEnumHelper.read(istr); test(false); } catch (Ice.MarshalException) { } try { ostr = Ice.Util.createOutputStream(communicator); ostr.writeShort((short)-1); // Negative enumerators are not supported Ice.InputStream istr = Ice.Util.createInputStream(communicator, ostr.finished()); ShortEnumHelper.read(istr); test(false); } catch (Ice.MarshalException) { } try { ostr = Ice.Util.createOutputStream(communicator); ostr.writeShort((short)0); // Invalid enumerator Ice.InputStream istr = Ice.Util.createInputStream(communicator, ostr.finished()); ShortEnumHelper.read(istr); test(false); } catch (Ice.MarshalException) { } try { ostr = Ice.Util.createOutputStream(communicator); ostr.writeShort((short)32767); // Invalid enumerator Ice.InputStream istr = Ice.Util.createInputStream(communicator, ostr.finished()); ShortEnumHelper.read(istr); test(false); } catch (Ice.MarshalException) { } try { ostr = Ice.Util.createOutputStream(communicator); ostr.writeInt(-1); // Negative enumerators are not supported Ice.InputStream istr = Ice.Util.createInputStream(communicator, ostr.finished()); IntEnumHelper.read(istr); test(false); } catch (Ice.MarshalException) { } Console.Out.WriteLine("ok"); #if SILVERLIGHT proxy.shutdown(); #else return(proxy); #endif }
public static TestIntfPrx allTests(Test.TestHelper helper, bool collocated) { Ice.Communicator communicator = helper.communicator(); var output = helper.getWriter(); output.Write("testing stringToProxy... "); output.Flush(); String @ref = "Test:" + helper.getTestEndpoint(0) + " -t 2000"; Ice.ObjectPrx @base = communicator.stringToProxy(@ref); test(@base != null); output.WriteLine("ok"); output.Write("testing checked cast... "); output.Flush(); TestIntfPrx testPrx = TestIntfPrxHelper.checkedCast(@base); test(testPrx != null); test(testPrx.Equals(@base)); output.WriteLine("ok"); output.Write("base... "); output.Flush(); { try { testPrx.baseAsBase(); test(false); } catch (Base b) { test(b.b.Equals("Base.b")); test(b.GetType().FullName.Equals("Test.Base")); } catch (Exception) { test(false); } } output.WriteLine("ok"); output.Write("base (AMI)... "); output.Flush(); { try { testPrx.baseAsBaseAsync().Wait(); test(false); } catch (AggregateException ae) { try { throw ae.InnerException; } catch (Base b) { test(b.b.Equals("Base.b")); test(b.GetType().Name.Equals("Base")); } catch (Exception) { test(false); } } } output.WriteLine("ok"); output.Write("slicing of unknown derived... "); output.Flush(); { try { testPrx.unknownDerivedAsBase(); test(false); } catch (Base b) { test(b.b.Equals("UnknownDerived.b")); test(b.GetType().FullName.Equals("Test.Base")); } catch (Exception) { test(false); } } output.WriteLine("ok"); output.Write("slicing of unknown derived (AMI)... "); output.Flush(); { try { testPrx.unknownDerivedAsBaseAsync().Wait(); test(false); } catch (AggregateException ae) { try { throw ae.InnerException; } catch (Base b) { test(b.b.Equals("UnknownDerived.b")); test(b.GetType().Name.Equals("Base")); } catch (Exception) { test(false); } } } output.WriteLine("ok"); output.Write("non-slicing of known derived as base... "); output.Flush(); { try { testPrx.knownDerivedAsBase(); test(false); } catch (KnownDerived k) { test(k.b.Equals("KnownDerived.b")); test(k.kd.Equals("KnownDerived.kd")); test(k.GetType().FullName.Equals("Test.KnownDerived")); } catch (Exception) { test(false); } } output.WriteLine("ok"); output.Write("non-slicing of known derived as base (AMI)... "); output.Flush(); { try { testPrx.knownDerivedAsBaseAsync().Wait(); test(false); } catch (AggregateException ae) { try { throw ae.InnerException; } catch (KnownDerived k) { test(k.b.Equals("KnownDerived.b")); test(k.kd.Equals("KnownDerived.kd")); test(k.GetType().Name.Equals("KnownDerived")); } catch (Exception) { test(false); } } } output.WriteLine("ok"); output.Write("non-slicing of known derived as derived... "); output.Flush(); { try { testPrx.knownDerivedAsKnownDerived(); test(false); } catch (KnownDerived k) { test(k.b.Equals("KnownDerived.b")); test(k.kd.Equals("KnownDerived.kd")); test(k.GetType().FullName.Equals("Test.KnownDerived")); } catch (Exception) { test(false); } } output.WriteLine("ok"); output.Write("non-slicing of known derived as derived (AMI)... "); output.Flush(); { try { testPrx.knownDerivedAsKnownDerivedAsync().Wait(); test(false); } catch (AggregateException ae) { try { throw ae.InnerException; } catch (KnownDerived k) { test(k.b.Equals("KnownDerived.b")); test(k.kd.Equals("KnownDerived.kd")); test(k.GetType().Name.Equals("KnownDerived")); } catch (Exception) { test(false); } } } output.WriteLine("ok"); output.Write("slicing of unknown intermediate as base... "); output.Flush(); { try { testPrx.unknownIntermediateAsBase(); test(false); } catch (Base b) { test(b.b.Equals("UnknownIntermediate.b")); test(b.GetType().FullName.Equals("Test.Base")); } catch (Exception) { test(false); } } output.WriteLine("ok"); output.Write("slicing of unknown intermediate as base (AMI)... "); output.Flush(); { try { testPrx.unknownIntermediateAsBaseAsync().Wait(); test(false); } catch (AggregateException ae) { try { throw ae.InnerException; } catch (Base b) { test(b.b.Equals("UnknownIntermediate.b")); test(b.GetType().Name.Equals("Base")); } catch (Exception) { test(false); } } } output.WriteLine("ok"); output.Write("slicing of known intermediate as base... "); output.Flush(); { try { testPrx.knownIntermediateAsBase(); test(false); } catch (KnownIntermediate ki) { test(ki.b.Equals("KnownIntermediate.b")); test(ki.ki.Equals("KnownIntermediate.ki")); test(ki.GetType().FullName.Equals("Test.KnownIntermediate")); } catch (Exception) { test(false); } } output.WriteLine("ok"); output.Write("slicing of known intermediate as base (AMI)... "); output.Flush(); { try { testPrx.knownIntermediateAsBaseAsync().Wait(); test(false); } catch (AggregateException ae) { try { throw ae.InnerException; } catch (KnownIntermediate ki) { test(ki.b.Equals("KnownIntermediate.b")); test(ki.ki.Equals("KnownIntermediate.ki")); test(ki.GetType().Name.Equals("KnownIntermediate")); } catch (Exception) { test(false); } } } output.WriteLine("ok"); output.Write("slicing of known most derived as base... "); output.Flush(); { try { testPrx.knownMostDerivedAsBase(); test(false); } catch (KnownMostDerived kmd) { test(kmd.b.Equals("KnownMostDerived.b")); test(kmd.ki.Equals("KnownMostDerived.ki")); test(kmd.kmd.Equals("KnownMostDerived.kmd")); test(kmd.GetType().FullName.Equals("Test.KnownMostDerived")); } catch (Exception) { test(false); } } output.WriteLine("ok"); output.Write("slicing of known most derived as base (AMI)... "); output.Flush(); { try { testPrx.knownMostDerivedAsBaseAsync().Wait(); test(false); } catch (AggregateException ae) { try { throw ae.InnerException; } catch (KnownMostDerived kmd) { test(kmd.b.Equals("KnownMostDerived.b")); test(kmd.ki.Equals("KnownMostDerived.ki")); test(kmd.kmd.Equals("KnownMostDerived.kmd")); test(kmd.GetType().Name.Equals("KnownMostDerived")); } catch (Exception) { test(false); } } } output.WriteLine("ok"); output.Write("non-slicing of known intermediate as intermediate... "); output.Flush(); { try { testPrx.knownIntermediateAsKnownIntermediate(); test(false); } catch (KnownIntermediate ki) { test(ki.b.Equals("KnownIntermediate.b")); test(ki.ki.Equals("KnownIntermediate.ki")); test(ki.GetType().FullName.Equals("Test.KnownIntermediate")); } catch (Exception) { test(false); } } output.WriteLine("ok"); output.Write("non-slicing of known intermediate as intermediate (AMI)... "); output.Flush(); { try { testPrx.knownIntermediateAsKnownIntermediateAsync().Wait(); test(false); } catch (AggregateException ae) { try { throw ae.InnerException; } catch (KnownIntermediate ki) { test(ki.b.Equals("KnownIntermediate.b")); test(ki.ki.Equals("KnownIntermediate.ki")); test(ki.GetType().Name.Equals("KnownIntermediate")); } catch (Exception) { test(false); } } } output.WriteLine("ok"); output.Write("non-slicing of known most derived as intermediate... "); output.Flush(); { try { testPrx.knownMostDerivedAsKnownIntermediate(); test(false); } catch (KnownMostDerived kmd) { test(kmd.b.Equals("KnownMostDerived.b")); test(kmd.ki.Equals("KnownMostDerived.ki")); test(kmd.kmd.Equals("KnownMostDerived.kmd")); test(kmd.GetType().FullName.Equals("Test.KnownMostDerived")); } catch (Exception) { test(false); } } output.WriteLine("ok"); output.Write("non-slicing of known most derived as intermediate (AMI)... "); output.Flush(); { try { testPrx.knownMostDerivedAsKnownIntermediateAsync().Wait(); test(false); } catch (AggregateException ae) { try { throw ae.InnerException; } catch (KnownMostDerived kmd) { test(kmd.b.Equals("KnownMostDerived.b")); test(kmd.ki.Equals("KnownMostDerived.ki")); test(kmd.kmd.Equals("KnownMostDerived.kmd")); test(kmd.GetType().Name.Equals("KnownMostDerived")); } catch (Exception) { test(false); } } } output.WriteLine("ok"); output.Write("non-slicing of known most derived as most derived... "); output.Flush(); { try { testPrx.knownMostDerivedAsKnownMostDerived(); test(false); } catch (KnownMostDerived kmd) { test(kmd.b.Equals("KnownMostDerived.b")); test(kmd.ki.Equals("KnownMostDerived.ki")); test(kmd.kmd.Equals("KnownMostDerived.kmd")); test(kmd.GetType().FullName.Equals("Test.KnownMostDerived")); } catch (Exception) { test(false); } } output.WriteLine("ok"); output.Write("non-slicing of known most derived as most derived (AMI)... "); output.Flush(); { try { testPrx.knownMostDerivedAsKnownMostDerivedAsync().Wait(); test(false); } catch (AggregateException ae) { try { throw ae.InnerException; } catch (KnownMostDerived kmd) { test(kmd.b.Equals("KnownMostDerived.b")); test(kmd.ki.Equals("KnownMostDerived.ki")); test(kmd.kmd.Equals("KnownMostDerived.kmd")); test(kmd.GetType().Name.Equals("KnownMostDerived")); } catch (Exception) { test(false); } } } output.WriteLine("ok"); output.Write("slicing of unknown most derived, known intermediate as base... "); output.Flush(); { try { testPrx.unknownMostDerived1AsBase(); test(false); } catch (KnownIntermediate ki) { test(ki.b.Equals("UnknownMostDerived1.b")); test(ki.ki.Equals("UnknownMostDerived1.ki")); test(ki.GetType().FullName.Equals("Test.KnownIntermediate")); } catch (Exception) { test(false); } } output.WriteLine("ok"); output.Write("slicing of unknown most derived, known intermediate as base (AMI)... "); output.Flush(); { try { testPrx.unknownMostDerived1AsBaseAsync().Wait(); test(false); } catch (AggregateException ae) { try { throw ae.InnerException; } catch (KnownIntermediate ki) { test(ki.b.Equals("UnknownMostDerived1.b")); test(ki.ki.Equals("UnknownMostDerived1.ki")); test(ki.GetType().Name.Equals("KnownIntermediate")); } catch (Exception) { test(false); } } } output.WriteLine("ok"); output.Write("slicing of unknown most derived, known intermediate as intermediate... "); output.Flush(); { try { testPrx.unknownMostDerived1AsKnownIntermediate(); test(false); } catch (KnownIntermediate ki) { test(ki.b.Equals("UnknownMostDerived1.b")); test(ki.ki.Equals("UnknownMostDerived1.ki")); test(ki.GetType().FullName.Equals("Test.KnownIntermediate")); } catch (Exception) { test(false); } } output.WriteLine("ok"); output.Write("slicing of unknown most derived, known intermediate as intermediate (AMI)... "); output.Flush(); { try { testPrx.unknownMostDerived1AsKnownIntermediateAsync().Wait(); test(false); } catch (AggregateException ae) { try { throw ae.InnerException; } catch (KnownIntermediate ki) { test(ki.b.Equals("UnknownMostDerived1.b")); test(ki.ki.Equals("UnknownMostDerived1.ki")); test(ki.GetType().Name.Equals("KnownIntermediate")); } catch (Exception) { test(false); } } } output.WriteLine("ok"); output.Write("slicing of unknown most derived, unknown intermediate thrown as base... "); output.Flush(); { try { testPrx.unknownMostDerived2AsBase(); test(false); } catch (Base b) { test(b.b.Equals("UnknownMostDerived2.b")); test(b.GetType().FullName.Equals("Test.Base")); } catch (Exception) { test(false); } } output.WriteLine("ok"); output.Write("slicing of unknown most derived, unknown intermediate thrown as base (AMI)... "); output.Flush(); { try { testPrx.unknownMostDerived2AsBaseAsync().Wait(); test(false); } catch (AggregateException ae) { try { throw ae.InnerException; } catch (Base b) { test(b.b.Equals("UnknownMostDerived2.b")); test(b.GetType().Name.Equals("Base")); } catch (Exception) { test(false); } } } output.WriteLine("ok"); output.Write("unknown most derived in compact format... "); output.Flush(); { try { testPrx.unknownMostDerived2AsBaseCompact(); test(false); } catch (Base) { // // For the 1.0 encoding, the unknown exception is sliced to Base. // test(testPrx.ice_getEncodingVersion().Equals(Ice.Util.Encoding_1_0)); } catch (Ice.UnknownUserException) { // // A MarshalException is raised for the compact format because the // most-derived type is unknown and the exception cannot be sliced. // test(!testPrx.ice_getEncodingVersion().Equals(Ice.Util.Encoding_1_0)); } catch (Ice.OperationNotExistException) { } catch (Exception) { test(false); } } output.WriteLine("ok"); output.Write("preserved exceptions... "); output.Flush(); { try { testPrx.unknownPreservedAsBase(); test(false); } catch (Base ex) { if (testPrx.ice_getEncodingVersion().Equals(Ice.Util.Encoding_1_0)) { test(ex.ice_getSlicedData() == null); } else { Ice.SlicedData slicedData = ex.ice_getSlicedData(); test(slicedData != null); test(slicedData.slices.Length == 2); test(slicedData.slices[1].typeId.Equals("::Test::SPreserved1")); test(slicedData.slices[0].typeId.Equals("::Test::SPreserved2")); } } try { testPrx.unknownPreservedAsKnownPreserved(); test(false); } catch (KnownPreserved ex) { test(ex.kp.Equals("preserved")); if (testPrx.ice_getEncodingVersion().Equals(Ice.Util.Encoding_1_0)) { test(ex.ice_getSlicedData() == null); } else { Ice.SlicedData slicedData = ex.ice_getSlicedData(); test(slicedData != null); test(slicedData.slices.Length == 2); test(slicedData.slices[1].typeId.Equals("::Test::SPreserved1")); test(slicedData.slices[0].typeId.Equals("::Test::SPreserved2")); } } Ice.ObjectAdapter adapter = communicator.createObjectAdapter(""); RelayPrx relay = RelayPrxHelper.uncheckedCast(adapter.addWithUUID(new RelayI())); adapter.activate(); testPrx.ice_getConnection().setAdapter(adapter); try { testPrx.relayKnownPreservedAsBase(relay); test(false); } catch (KnownPreservedDerived ex) { test(ex.b.Equals("base")); test(ex.kp.Equals("preserved")); test(ex.kpd.Equals("derived")); } catch (Ice.OperationNotExistException) { } catch (Exception) { test(false); } try { testPrx.relayKnownPreservedAsKnownPreserved(relay); test(false); } catch (KnownPreservedDerived ex) { test(ex.b.Equals("base")); test(ex.kp.Equals("preserved")); test(ex.kpd.Equals("derived")); } catch (Ice.OperationNotExistException) { } catch (Exception) { test(false); } try { testPrx.relayUnknownPreservedAsBase(relay); test(false); } catch (Preserved2 ex) { test(ex.b.Equals("base")); test(ex.kp.Equals("preserved")); test(ex.kpd.Equals("derived")); test(ex.p1.ice_id().Equals(PreservedClass.ice_staticId())); PreservedClass pc = ex.p1 as PreservedClass; test(pc.bc.Equals("bc")); test(pc.pc.Equals("pc")); test(ex.p2 == ex.p1); } catch (KnownPreservedDerived ex) { // // For the 1.0 encoding, the unknown exception is sliced to KnownPreserved. // test(testPrx.ice_getEncodingVersion().Equals(Ice.Util.Encoding_1_0)); test(ex.b.Equals("base")); test(ex.kp.Equals("preserved")); test(ex.kpd.Equals("derived")); } catch (Ice.OperationNotExistException) { } catch (Exception) { test(false); } try { testPrx.relayUnknownPreservedAsKnownPreserved(relay); test(false); } catch (Preserved2 ex) { test(ex.b.Equals("base")); test(ex.kp.Equals("preserved")); test(ex.kpd.Equals("derived")); test(ex.p1.ice_id().Equals(PreservedClass.ice_staticId())); PreservedClass pc = ex.p1 as PreservedClass; test(pc.bc.Equals("bc")); test(pc.pc.Equals("pc")); test(ex.p2 == ex.p1); } catch (KnownPreservedDerived ex) { // // For the 1.0 encoding, the unknown exception is sliced to KnownPreserved. // test(testPrx.ice_getEncodingVersion().Equals(Ice.Util.Encoding_1_0)); test(ex.b.Equals("base")); test(ex.kp.Equals("preserved")); test(ex.kpd.Equals("derived")); } catch (Ice.OperationNotExistException) { } catch (Exception) { test(false); } adapter.destroy(); } output.WriteLine("ok"); return(testPrx); }
allTestsWithDeploy(Ice.Communicator communicator) { Console.Out.Write("testing stringToProxy... "); Console.Out.Flush(); Ice.ObjectPrx @base = communicator.stringToProxy("test @ TestAdapter"); test(@base != null); Ice.ObjectPrx @base2 = communicator.stringToProxy("test"); test(@base2 != null); Console.Out.WriteLine("ok"); Console.Out.Write("testing checked cast... "); Console.Out.Flush(); TestIntfPrx obj = TestIntfPrxHelper.checkedCast(@base); test(obj != null); test(obj.Equals(@base)); TestIntfPrx obj2 = TestIntfPrxHelper.checkedCast(@base2); test(obj2 != null); test(obj2.Equals(@base2)); Console.Out.WriteLine("ok"); Console.Out.Write("pinging server... "); Console.Out.Flush(); obj.ice_ping(); obj2.ice_ping(); Console.Out.WriteLine("ok"); Console.Out.Write("testing encoding versioning... "); Console.Out.Flush(); Ice.ObjectPrx base10 = communicator.stringToProxy("test10 @ TestAdapter10"); test(base10 != null); Ice.ObjectPrx base102 = communicator.stringToProxy("test10"); test(base102 != null); try { base10.ice_ping(); test(false); } catch (Ice.NoEndpointException) { } try { base102.ice_ping(); test(false); } catch (Ice.NoEndpointException) { } base10 = base10.ice_encodingVersion(Ice.Util.Encoding_1_0); base102 = base102.ice_encodingVersion(Ice.Util.Encoding_1_0); base10.ice_ping(); base102.ice_ping(); Console.Out.WriteLine("ok"); Console.Out.Write("testing reference with unknown identity... "); Console.Out.Flush(); try { communicator.stringToProxy("unknown/unknown").ice_ping(); test(false); } catch (Ice.NotRegisteredException ex) { test(ex.kindOfObject.Equals("object")); test(ex.id.Equals("unknown/unknown")); } Console.Out.WriteLine("ok"); Console.Out.Write("testing reference with unknown adapter... "); Console.Out.Flush(); try { communicator.stringToProxy("test @ TestAdapterUnknown").ice_ping(); test(false); } catch (Ice.NotRegisteredException ex) { test(ex.kindOfObject.Equals("object adapter")); test(ex.id.Equals("TestAdapterUnknown")); } Console.Out.WriteLine("ok"); IceGrid.RegistryPrx registry = IceGrid.RegistryPrxHelper.checkedCast( communicator.stringToProxy(communicator.getDefaultLocator().ice_getIdentity().category + "/Registry")); test(registry != null); IceGrid.AdminSessionPrx session = null; try { session = registry.createAdminSession("foo", "bar"); } catch (IceGrid.PermissionDeniedException) { test(false); } session.ice_getConnection().setACM(registry.getACMTimeout(), Ice.Util.None, Ice.ACMHeartbeat.HeartbeatAlways); IceGrid.AdminPrx admin = session.getAdmin(); test(admin != null); try { admin.enableServer("server", false); admin.stopServer("server"); } catch (IceGrid.ServerNotExistException) { test(false); } catch (IceGrid.ServerStopException) { test(false); } catch (IceGrid.NodeUnreachableException) { test(false); } Console.Out.Write("testing whether server is still reachable... "); Console.Out.Flush(); try { obj = TestIntfPrxHelper.checkedCast(@base); test(false); } catch (Ice.NoEndpointException) { } try { obj2 = TestIntfPrxHelper.checkedCast(@base2); test(false); } catch (Ice.NoEndpointException) { } try { admin.enableServer("server", true); } catch (IceGrid.ServerNotExistException) { test(false); } catch (IceGrid.NodeUnreachableException) { test(false); } try { obj = TestIntfPrxHelper.checkedCast(@base); } catch (Ice.NoEndpointException) { test(false); } try { obj2 = TestIntfPrxHelper.checkedCast(@base2); } catch (Ice.NoEndpointException) { test(false); } Console.Out.WriteLine("ok"); try { admin.stopServer("server"); } catch (IceGrid.ServerNotExistException) { test(false); } catch (IceGrid.ServerStopException) { test(false); } catch (IceGrid.NodeUnreachableException) { test(false); } session.destroy(); }
public static void allTests(TestCommon.Application app) { Ice.Communicator communicator = app.communicator(); TestIntfPrx service1 = TestIntfPrxHelper.uncheckedCast(communicator.stringToProxy("test:" + app.getTestEndpoint(0))); TestIntfPrx service2 = TestIntfPrxHelper.uncheckedCast(communicator.stringToProxy("test:" + app.getTestEndpoint(1))); TestIntfPrx service3 = TestIntfPrxHelper.uncheckedCast(communicator.stringToProxy("test:" + app.getTestEndpoint(2))); TestIntfPrx service4 = TestIntfPrxHelper.uncheckedCast(communicator.stringToProxy("test:" + app.getTestEndpoint(3))); if (service1.getProperty("IceBox.InheritProperties").Equals("")) { Console.Out.Write("testing service properties... "); Console.Out.Flush(); test(service1.getProperty("Ice.ProgramName").Equals("IceBox-Service1")); test(service1.getProperty("Service").Equals("1")); test(service1.getProperty("Service1.Ovrd").Equals("2")); test(service1.getProperty("Service1.Unset").Equals("")); test(service1.getProperty("Arg").Equals("1")); string[] args1 = { "-a", "--Arg=2" }; test(IceUtilInternal.Arrays.Equals(service1.getArgs(), args1)); test(service2.getProperty("Ice.ProgramName").Equals("Test")); test(service2.getProperty("Service").Equals("2")); test(service2.getProperty("Service1.ArgProp").Equals("")); test(service2.getProperty("IceBox.InheritProperties").Equals("1")); string[] args2 = { "--Service1.ArgProp=1" }; test(IceUtilInternal.Arrays.Equals(service2.getArgs(), args2)); Console.Out.WriteLine("ok"); Console.Out.Write("testing with shared communicator... "); Console.Out.Flush(); test(service3.getProperty("Ice.ProgramName").Equals("IceBox-SharedCommunicator")); test(service3.getProperty("Service").Equals("4")); test(service3.getProperty("Prop").Equals("")); test(service3.getProperty("Service3.Prop").Equals("1")); test(service3.getProperty("Ice.Trace.Slicing").Equals("3")); test(service4.getProperty("Ice.ProgramName").Equals("IceBox-SharedCommunicator")); test(service4.getProperty("Service").Equals("4")); test(service4.getProperty("Prop").Equals("")); test(service4.getProperty("Service3.Prop").Equals("1")); test(service4.getProperty("Ice.Trace.Slicing").Equals("3")); string[] args4 = { "--Service3.Prop=2" }; test(IceUtilInternal.Arrays.Equals(service4.getArgs(), args4)); Console.Out.WriteLine("ok"); } else { Console.Out.Write("testing property inheritance... "); Console.Out.Flush(); test(service1.getProperty("Ice.ProgramName").Equals("IceBox2-Service1")); test(service1.getProperty("ServerProp").Equals("1")); test(service1.getProperty("OverrideMe").Equals("2")); test(service1.getProperty("UnsetMe").Equals("")); test(service1.getProperty("Service1.Prop").Equals("1")); test(service1.getProperty("Service1.ArgProp").Equals("2")); test(service2.getProperty("Ice.ProgramName").Equals("IceBox2-SharedCommunicator")); test(service2.getProperty("ServerProp").Equals("1")); test(service2.getProperty("OverrideMe").Equals("3")); test(service2.getProperty("UnsetMe").Equals("")); test(service2.getProperty("Service2.Prop").Equals("1")); Console.Out.WriteLine("ok"); } }
public static void allTests(Test.TestHelper helper) { var output = helper.getWriter(); Ice.Communicator communicator = helper.communicator(); string sref = "test:" + helper.getTestEndpoint(0); Ice.ObjectPrx obj = communicator.stringToProxy(sref); test(obj != null); Test.TestIntfPrx p = Test.TestIntfPrxHelper.uncheckedCast(obj); sref = "testController:" + helper.getTestEndpoint(1); obj = communicator.stringToProxy(sref); test(obj != null); Test.TestIntfControllerPrx testController = Test.TestIntfControllerPrxHelper.uncheckedCast(obj); output.Write("testing dispatcher with continuations... "); output.Flush(); { p.op(); Callback cb = new Callback(output); Action <Task> continuation = (Task previous) => { try { previous.Wait(); cb.response(); } catch (AggregateException ex) { cb.exception((Ice.Exception)ex.InnerException); } }; // We use sleepAsync instead of opAsync to ensure the response isn't received before // we setup the continuation var t = p.sleepAsync(500).ContinueWith(continuation, TaskContinuationOptions.ExecuteSynchronously); t.Wait(); cb.check(); var i = (TestIntfPrx)p.ice_adapterId("dummy"); // // sleepAsync doesn't help here as the test will fail with Ice.NoEndpointException and sleepAsync // will not be called. // //i.sleepAsync(500).ContinueWith(continuation, TaskContinuationOptions.ExecuteSynchronously).Wait(); //cb.check(); // // Expect InvocationTimeoutException. // { // The continuation might be (rarely) executed on the current thread if the setup of the // continuation occurs after the invocation timeout. var thread = Thread.CurrentThread; TestIntfPrx to = TestIntfPrxHelper.uncheckedCast(p.ice_invocationTimeout(20)); to.sleepAsync(500).ContinueWith( previous => { try { previous.Wait(); test(false); } catch (AggregateException ex) { test(ex.InnerException is Ice.InvocationTimeoutException); test(Dispatcher.isDispatcherThread() || thread == Thread.CurrentThread); } }, TaskContinuationOptions.ExecuteSynchronously).Wait(); } // // Repeat using the proxy scheduler in this case we don't need to call sleepAsync, continuations // are waranted to run with the dispatcher even if not executed synchronously. // t = p.opAsync().ContinueWith(continuation, p.ice_scheduler()); t.Wait(); cb.check(); i.opAsync().ContinueWith(continuation, i.ice_scheduler()).Wait(); cb.check(); // // Expect InvocationTimeoutException. // { TestIntfPrx to = TestIntfPrxHelper.uncheckedCast(p.ice_invocationTimeout(10)); to.sleepAsync(500).ContinueWith( previous => { try { previous.Wait(); test(false); } catch (AggregateException ex) { test(ex.InnerException is Ice.InvocationTimeoutException); test(Dispatcher.isDispatcherThread()); } }, p.ice_scheduler()).Wait(); } // // Hold adapter to ensure the invocations don't complete synchronously // Also disable collocation optimization on p // testController.holdAdapter(); var p2 = TestIntfPrxHelper.uncheckedCast(p.ice_collocationOptimized(false)); Action <Task> continuation2 = (Task previous) => { test(Dispatcher.isDispatcherThread()); try { previous.Wait(); } catch (AggregateException ex) { test(ex.InnerException is Ice.CommunicatorDestroyedException); } }; byte[] seq = new byte[10 * 1024]; (new Random()).NextBytes(seq); Progress sentSynchronously; do { sentSynchronously = new Progress(); t = p2.opWithPayloadAsync(seq, progress: sentSynchronously).ContinueWith( continuation2, TaskContinuationOptions.ExecuteSynchronously); }while (sentSynchronously.getResult()); testController.resumeAdapter(); t.Wait(); } output.WriteLine("ok"); output.Write("testing dispatcher with async/await... "); output.Flush(); { TaskCompletionSource <object> t = new TaskCompletionSource <object>(); p.opAsync().ContinueWith(async previous => // Execute the code below from the Ice client thread pool { try { await p.opAsync(); test(Dispatcher.isDispatcherThread()); try { TestIntfPrx i = (TestIntfPrx)p.ice_adapterId("dummy"); await i.opAsync(); test(false); } catch (Exception) { test(Dispatcher.isDispatcherThread()); } TestIntfPrx to = TestIntfPrxHelper.uncheckedCast(p.ice_invocationTimeout(10)); try { await to.sleepAsync(500); test(false); } catch (Ice.InvocationTimeoutException) { test(Dispatcher.isDispatcherThread()); } t.SetResult(null); } catch (Exception ex) { t.SetException(ex); } }, p.ice_scheduler()); t.Task.Wait(); } output.WriteLine("ok"); p.shutdown(); }
public static void allTests(Ice.Communicator communicator) { string @ref = "communicator:default -p 12010"; RemoteCommunicatorPrx com = RemoteCommunicatorPrxHelper.uncheckedCast(communicator.stringToProxy(@ref)); System.Random rand = new System.Random(unchecked ((int)System.DateTime.Now.Ticks)); Write("testing binding with single endpoint... "); Flush(); { RemoteObjectAdapterPrx adapter = com.createObjectAdapter("Adapter", "default"); TestIntfPrx test1 = adapter.getTestIntf(); TestIntfPrx test2 = adapter.getTestIntf(); test(test1.ice_getConnection() == test2.ice_getConnection()); test1.ice_ping(); test2.ice_ping(); com.deactivateObjectAdapter(adapter); TestIntfPrx test3 = TestIntfPrxHelper.uncheckedCast(test1); test(test3.ice_getConnection() == test1.ice_getConnection()); test(test3.ice_getConnection() == test2.ice_getConnection()); try { test3.ice_ping(); test(false); } catch (Ice.ConnectFailedException) { } } WriteLine("ok"); Write("testing binding with multiple endpoints... "); Flush(); { List <RemoteObjectAdapterPrx> adapters = new List <RemoteObjectAdapterPrx>(); adapters.Add(com.createObjectAdapter("Adapter11", "default")); adapters.Add(com.createObjectAdapter("Adapter12", "default")); adapters.Add(com.createObjectAdapter("Adapter13", "default")); // // Ensure that when a connection is opened it's reused for new // proxies and that all endpoints are eventually tried. // List <string> names = new List <string>(); names.Add("Adapter11"); names.Add("Adapter12"); names.Add("Adapter13"); while (names.Count > 0) { List <RemoteObjectAdapterPrx> adpts = new List <RemoteObjectAdapterPrx>(adapters); TestIntfPrx test1 = createTestIntfPrx(adpts); shuffle(ref adpts); TestIntfPrx test2 = createTestIntfPrx(adpts); shuffle(ref adpts); TestIntfPrx test3 = createTestIntfPrx(adpts); test1.ice_ping(); test(test1.ice_getConnection() == test2.ice_getConnection()); test(test2.ice_getConnection() == test3.ice_getConnection()); names.Remove(test1.getAdapterName()); test1.ice_getConnection().close(false); } // // Ensure that the proxy correctly caches the connection (we // always send the request over the same connection.) // { foreach (RemoteObjectAdapterPrx adpt in adapters) { adpt.getTestIntf().ice_ping(); } TestIntfPrx t = createTestIntfPrx(adapters); string name = t.getAdapterName(); int nRetry = 10; int i; for (i = 0; i < nRetry && t.getAdapterName().Equals(name); i++) { ; } test(i == nRetry); foreach (RemoteObjectAdapterPrx adpt in adapters) { adpt.getTestIntf().ice_getConnection().close(false); } } // // Deactivate an adapter and ensure that we can still // establish the connection to the remaining adapters. // com.deactivateObjectAdapter((RemoteObjectAdapterPrx)adapters[0]); names.Add("Adapter12"); names.Add("Adapter13"); while (names.Count > 0) { List <RemoteObjectAdapterPrx> adpts = new List <RemoteObjectAdapterPrx>(adapters); TestIntfPrx test1 = createTestIntfPrx(adpts); shuffle(ref adpts); TestIntfPrx test2 = createTestIntfPrx(adpts); shuffle(ref adpts); TestIntfPrx test3 = createTestIntfPrx(adpts); test(test1.ice_getConnection() == test2.ice_getConnection()); test(test2.ice_getConnection() == test3.ice_getConnection()); names.Remove(test1.getAdapterName()); test1.ice_getConnection().close(false); } // // Deactivate an adapter and ensure that we can still // establish the connection to the remaining adapter. // com.deactivateObjectAdapter((RemoteObjectAdapterPrx)adapters[2]); TestIntfPrx obj = createTestIntfPrx(adapters); test(obj.getAdapterName().Equals("Adapter12")); deactivate(com, adapters); } WriteLine("ok"); Write("testing binding with multiple random endpoints... "); Flush(); { RemoteObjectAdapterPrx[] adapters = new RemoteObjectAdapterPrx[5]; adapters[0] = com.createObjectAdapter("AdapterRandom11", "default"); adapters[1] = com.createObjectAdapter("AdapterRandom12", "default"); adapters[2] = com.createObjectAdapter("AdapterRandom13", "default"); adapters[3] = com.createObjectAdapter("AdapterRandom14", "default"); adapters[4] = com.createObjectAdapter("AdapterRandom15", "default"); int count; if (IceInternal.AssemblyUtil.platform_ == IceInternal.AssemblyUtil.Platform.Windows) { count = 20; } else { count = 60; } int adapterCount = adapters.Length; while (--count > 0) { TestIntfPrx[] proxies; if (IceInternal.AssemblyUtil.platform_ == IceInternal.AssemblyUtil.Platform.Windows) { if (count == 10) { com.deactivateObjectAdapter(adapters[4]); --adapterCount; } proxies = new TestIntfPrx[10]; } else { if (count < 60 && count % 10 == 0) { com.deactivateObjectAdapter(adapters[count / 10 - 1]); --adapterCount; } proxies = new TestIntfPrx[40]; } int i; for (i = 0; i < proxies.Length; ++i) { RemoteObjectAdapterPrx[] adpts = new RemoteObjectAdapterPrx[rand.Next(adapters.Length)]; if (adpts.Length == 0) { adpts = new RemoteObjectAdapterPrx[1]; } for (int j = 0; j < adpts.Length; ++j) { adpts[j] = adapters[rand.Next(adapters.Length)]; } proxies[i] = createTestIntfPrx(new List <RemoteObjectAdapterPrx>(adpts)); } for (i = 0; i < proxies.Length; i++) { proxies[i].begin_getAdapterName(); } for (i = 0; i < proxies.Length; i++) { try { proxies[i].ice_ping(); } catch (Ice.LocalException) { } } List <Ice.Connection> connections = new List <Ice.Connection>(); for (i = 0; i < proxies.Length; i++) { if (proxies[i].ice_getCachedConnection() != null) { if (!connections.Contains(proxies[i].ice_getCachedConnection())) { connections.Add(proxies[i].ice_getCachedConnection()); } } } test(connections.Count <= adapterCount); foreach (RemoteObjectAdapterPrx a in adapters) { try { a.getTestIntf().ice_getConnection().close(false); } catch (Ice.LocalException) { // Expected if adapter is down. } } } } WriteLine("ok"); Write("testing binding with multiple endpoints and AMI... "); Flush(); { List <RemoteObjectAdapterPrx> adapters = new List <RemoteObjectAdapterPrx>(); adapters.Add(com.createObjectAdapter("AdapterAMI11", "default")); adapters.Add(com.createObjectAdapter("AdapterAMI12", "default")); adapters.Add(com.createObjectAdapter("AdapterAMI13", "default")); // // Ensure that when a connection is opened it's reused for new // proxies and that all endpoints are eventually tried. // List <string> names = new List <string>(); names.Add("AdapterAMI11"); names.Add("AdapterAMI12"); names.Add("AdapterAMI13"); while (names.Count > 0) { List <RemoteObjectAdapterPrx> adpts = new List <RemoteObjectAdapterPrx>(adapters); TestIntfPrx test1 = createTestIntfPrx(adpts); shuffle(ref adpts); TestIntfPrx test2 = createTestIntfPrx(adpts); shuffle(ref adpts); TestIntfPrx test3 = createTestIntfPrx(adpts); test1.ice_ping(); test(test1.ice_getConnection() == test2.ice_getConnection()); test(test2.ice_getConnection() == test3.ice_getConnection()); names.Remove(getAdapterNameWithAMI(test1)); test1.ice_getConnection().close(false); } // // Ensure that the proxy correctly caches the connection (we // always send the request over the same connection.) // { foreach (RemoteObjectAdapterPrx adpt in adapters) { adpt.getTestIntf().ice_ping(); } TestIntfPrx t = createTestIntfPrx(adapters); string name = getAdapterNameWithAMI(t); int nRetry = 10; int i; for (i = 0; i < nRetry && getAdapterNameWithAMI(t).Equals(name); i++) { ; } test(i == nRetry); foreach (RemoteObjectAdapterPrx adpt in adapters) { adpt.getTestIntf().ice_getConnection().close(false); } } // // Deactivate an adapter and ensure that we can still // establish the connection to the remaining adapters. // com.deactivateObjectAdapter((RemoteObjectAdapterPrx)adapters[0]); names.Add("AdapterAMI12"); names.Add("AdapterAMI13"); while (names.Count > 0) { List <RemoteObjectAdapterPrx> adpts = new List <RemoteObjectAdapterPrx>(adapters); TestIntfPrx test1 = createTestIntfPrx(adpts); shuffle(ref adpts); TestIntfPrx test2 = createTestIntfPrx(adpts); shuffle(ref adpts); TestIntfPrx test3 = createTestIntfPrx(adpts); test(test1.ice_getConnection() == test2.ice_getConnection()); test(test2.ice_getConnection() == test3.ice_getConnection()); names.Remove(getAdapterNameWithAMI(test1)); test1.ice_getConnection().close(false); } // // Deactivate an adapter and ensure that we can still // establish the connection to the remaining adapter. // com.deactivateObjectAdapter((RemoteObjectAdapterPrx)adapters[2]); TestIntfPrx obj = createTestIntfPrx(adapters); test(getAdapterNameWithAMI(obj).Equals("AdapterAMI12")); deactivate(com, adapters); } WriteLine("ok"); Write("testing random endpoint selection... "); Flush(); { List <RemoteObjectAdapterPrx> adapters = new List <RemoteObjectAdapterPrx>(); adapters.Add(com.createObjectAdapter("Adapter21", "default")); adapters.Add(com.createObjectAdapter("Adapter22", "default")); adapters.Add(com.createObjectAdapter("Adapter23", "default")); TestIntfPrx obj = createTestIntfPrx(adapters); test(obj.ice_getEndpointSelection() == Ice.EndpointSelectionType.Random); List <string> names = new List <string>(); names.Add("Adapter21"); names.Add("Adapter22"); names.Add("Adapter23"); while (names.Count > 0) { names.Remove(obj.getAdapterName()); obj.ice_getConnection().close(false); } obj = TestIntfPrxHelper.uncheckedCast(obj.ice_endpointSelection(Ice.EndpointSelectionType.Random)); test(obj.ice_getEndpointSelection() == Ice.EndpointSelectionType.Random); names.Add("Adapter21"); names.Add("Adapter22"); names.Add("Adapter23"); while (names.Count > 0) { names.Remove(obj.getAdapterName()); obj.ice_getConnection().close(false); } deactivate(com, adapters); } WriteLine("ok"); Write("testing ordered endpoint selection... "); Flush(); { List <RemoteObjectAdapterPrx> adapters = new List <RemoteObjectAdapterPrx>(); adapters.Add(com.createObjectAdapter("Adapter31", "default")); adapters.Add(com.createObjectAdapter("Adapter32", "default")); adapters.Add(com.createObjectAdapter("Adapter33", "default")); TestIntfPrx obj = createTestIntfPrx(adapters); obj = TestIntfPrxHelper.uncheckedCast(obj.ice_endpointSelection(Ice.EndpointSelectionType.Ordered)); test(obj.ice_getEndpointSelection() == Ice.EndpointSelectionType.Ordered); int nRetry = 3; int i; // // Ensure that endpoints are tried in order by deactiving the adapters // one after the other. // for (i = 0; i < nRetry && obj.getAdapterName().Equals("Adapter31"); i++) { ; } test(i == nRetry); com.deactivateObjectAdapter((RemoteObjectAdapterPrx)adapters[0]); for (i = 0; i < nRetry && obj.getAdapterName().Equals("Adapter32"); i++) { ; } test(i == nRetry); com.deactivateObjectAdapter((RemoteObjectAdapterPrx)adapters[1]); for (i = 0; i < nRetry && obj.getAdapterName().Equals("Adapter33"); i++) { ; } test(i == nRetry); com.deactivateObjectAdapter((RemoteObjectAdapterPrx)adapters[2]); try { obj.getAdapterName(); } catch (Ice.ConnectFailedException) { } Ice.Endpoint[] endpoints = obj.ice_getEndpoints(); adapters.Clear(); // // Now, re-activate the adapters with the same endpoints in the opposite // order. // adapters.Add(com.createObjectAdapter("Adapter36", endpoints[2].ToString())); for (i = 0; i < nRetry && obj.getAdapterName().Equals("Adapter36"); i++) { ; } test(i == nRetry); obj.ice_getConnection().close(false); adapters.Add(com.createObjectAdapter("Adapter35", endpoints[1].ToString())); for (i = 0; i < nRetry && obj.getAdapterName().Equals("Adapter35"); i++) { ; } test(i == nRetry); obj.ice_getConnection().close(false); adapters.Add(com.createObjectAdapter("Adapter34", endpoints[0].ToString())); for (i = 0; i < nRetry && obj.getAdapterName().Equals("Adapter34"); i++) { ; } test(i == nRetry); deactivate(com, adapters); } WriteLine("ok"); Write("testing per request binding with single endpoint... "); Flush(); { RemoteObjectAdapterPrx adapter = com.createObjectAdapter("Adapter41", "default"); TestIntfPrx test1 = TestIntfPrxHelper.uncheckedCast(adapter.getTestIntf().ice_connectionCached(false)); TestIntfPrx test2 = TestIntfPrxHelper.uncheckedCast(adapter.getTestIntf().ice_connectionCached(false)); test(!test1.ice_isConnectionCached()); test(!test2.ice_isConnectionCached()); test(test1.ice_getConnection() != null && test2.ice_getConnection() != null); test(test1.ice_getConnection() == test2.ice_getConnection()); test1.ice_ping(); com.deactivateObjectAdapter(adapter); TestIntfPrx test3 = TestIntfPrxHelper.uncheckedCast(test1); try { test(test3.ice_getConnection() == test1.ice_getConnection()); test(false); } catch (Ice.ConnectFailedException) { } } WriteLine("ok"); Write("testing per request binding with multiple endpoints... "); Flush(); { List <RemoteObjectAdapterPrx> adapters = new List <RemoteObjectAdapterPrx>(); adapters.Add(com.createObjectAdapter("Adapter51", "default")); adapters.Add(com.createObjectAdapter("Adapter52", "default")); adapters.Add(com.createObjectAdapter("Adapter53", "default")); TestIntfPrx obj = TestIntfPrxHelper.uncheckedCast(createTestIntfPrx(adapters).ice_connectionCached(false)); test(!obj.ice_isConnectionCached()); List <string> names = new List <string>(); names.Add("Adapter51"); names.Add("Adapter52"); names.Add("Adapter53"); while (names.Count > 0) { names.Remove(obj.getAdapterName()); } com.deactivateObjectAdapter((RemoteObjectAdapterPrx)adapters[0]); names.Add("Adapter52"); names.Add("Adapter53"); while (names.Count > 0) { names.Remove(obj.getAdapterName()); } com.deactivateObjectAdapter((RemoteObjectAdapterPrx)adapters[2]); test(obj.getAdapterName().Equals("Adapter52")); deactivate(com, adapters); } WriteLine("ok"); Write("testing per request binding with multiple endpoints and AMI... "); Flush(); { List <RemoteObjectAdapterPrx> adapters = new List <RemoteObjectAdapterPrx>(); adapters.Add(com.createObjectAdapter("AdapterAMI51", "default")); adapters.Add(com.createObjectAdapter("AdapterAMI52", "default")); adapters.Add(com.createObjectAdapter("AdapterAMI53", "default")); TestIntfPrx obj = TestIntfPrxHelper.uncheckedCast(createTestIntfPrx(adapters).ice_connectionCached(false)); test(!obj.ice_isConnectionCached()); List <string> names = new List <string>(); names.Add("AdapterAMI51"); names.Add("AdapterAMI52"); names.Add("AdapterAMI53"); while (names.Count > 0) { names.Remove(getAdapterNameWithAMI(obj)); } com.deactivateObjectAdapter((RemoteObjectAdapterPrx)adapters[0]); names.Add("AdapterAMI52"); names.Add("AdapterAMI53"); while (names.Count > 0) { names.Remove(getAdapterNameWithAMI(obj)); } com.deactivateObjectAdapter((RemoteObjectAdapterPrx)adapters[2]); test(getAdapterNameWithAMI(obj).Equals("AdapterAMI52")); deactivate(com, adapters); } WriteLine("ok"); Write("testing per request binding and ordered endpoint selection... "); Flush(); { List <RemoteObjectAdapterPrx> adapters = new List <RemoteObjectAdapterPrx>(); adapters.Add(com.createObjectAdapter("Adapter61", "default")); adapters.Add(com.createObjectAdapter("Adapter62", "default")); adapters.Add(com.createObjectAdapter("Adapter63", "default")); TestIntfPrx obj = createTestIntfPrx(adapters); obj = TestIntfPrxHelper.uncheckedCast(obj.ice_endpointSelection(Ice.EndpointSelectionType.Ordered)); test(obj.ice_getEndpointSelection() == Ice.EndpointSelectionType.Ordered); obj = TestIntfPrxHelper.uncheckedCast(obj.ice_connectionCached(false)); test(!obj.ice_isConnectionCached()); int nRetry = 3; int i; // // Ensure that endpoints are tried in order by deactiving the adapters // one after the other. // for (i = 0; i < nRetry && obj.getAdapterName().Equals("Adapter61"); i++) { ; } test(i == nRetry); com.deactivateObjectAdapter((RemoteObjectAdapterPrx)adapters[0]); for (i = 0; i < nRetry && obj.getAdapterName().Equals("Adapter62"); i++) { ; } test(i == nRetry); com.deactivateObjectAdapter((RemoteObjectAdapterPrx)adapters[1]); for (i = 0; i < nRetry && obj.getAdapterName().Equals("Adapter63"); i++) { ; } test(i == nRetry); com.deactivateObjectAdapter((RemoteObjectAdapterPrx)adapters[2]); try { obj.getAdapterName(); } catch (Ice.ConnectFailedException) { } Ice.Endpoint[] endpoints = obj.ice_getEndpoints(); adapters.Clear(); // // Now, re-activate the adapters with the same endpoints in the opposite // order. // adapters.Add(com.createObjectAdapter("Adapter66", endpoints[2].ToString())); for (i = 0; i < nRetry && obj.getAdapterName().Equals("Adapter66"); i++) { ; } test(i == nRetry); adapters.Add(com.createObjectAdapter("Adapter65", endpoints[1].ToString())); for (i = 0; i < nRetry && obj.getAdapterName().Equals("Adapter65"); i++) { ; } test(i == nRetry); adapters.Add(com.createObjectAdapter("Adapter64", endpoints[0].ToString())); for (i = 0; i < nRetry && obj.getAdapterName().Equals("Adapter64"); i++) { ; } test(i == nRetry); deactivate(com, adapters); } WriteLine("ok"); Write("testing per request binding and ordered endpoint selection and AMI... "); Flush(); { List <RemoteObjectAdapterPrx> adapters = new List <RemoteObjectAdapterPrx>(); adapters.Add(com.createObjectAdapter("AdapterAMI61", "default")); adapters.Add(com.createObjectAdapter("AdapterAMI62", "default")); adapters.Add(com.createObjectAdapter("AdapterAMI63", "default")); TestIntfPrx obj = createTestIntfPrx(adapters); obj = TestIntfPrxHelper.uncheckedCast(obj.ice_endpointSelection(Ice.EndpointSelectionType.Ordered)); test(obj.ice_getEndpointSelection() == Ice.EndpointSelectionType.Ordered); obj = TestIntfPrxHelper.uncheckedCast(obj.ice_connectionCached(false)); test(!obj.ice_isConnectionCached()); int nRetry = 3; int i; // // Ensure that endpoints are tried in order by deactiving the adapters // one after the other. // for (i = 0; i < nRetry && getAdapterNameWithAMI(obj).Equals("AdapterAMI61"); i++) { ; } test(i == nRetry); com.deactivateObjectAdapter((RemoteObjectAdapterPrx)adapters[0]); for (i = 0; i < nRetry && getAdapterNameWithAMI(obj).Equals("AdapterAMI62"); i++) { ; } test(i == nRetry); com.deactivateObjectAdapter((RemoteObjectAdapterPrx)adapters[1]); for (i = 0; i < nRetry && getAdapterNameWithAMI(obj).Equals("AdapterAMI63"); i++) { ; } test(i == nRetry); com.deactivateObjectAdapter((RemoteObjectAdapterPrx)adapters[2]); try { obj.getAdapterName(); } catch (Ice.ConnectFailedException) { } Ice.Endpoint[] endpoints = obj.ice_getEndpoints(); adapters.Clear(); // // Now, re-activate the adapters with the same endpoints in the opposite // order. // adapters.Add(com.createObjectAdapter("AdapterAMI66", endpoints[2].ToString())); for (i = 0; i < nRetry && getAdapterNameWithAMI(obj).Equals("AdapterAMI66"); i++) { ; } test(i == nRetry); adapters.Add(com.createObjectAdapter("AdapterAMI65", endpoints[1].ToString())); for (i = 0; i < nRetry && getAdapterNameWithAMI(obj).Equals("AdapterAMI65"); i++) { ; } test(i == nRetry); adapters.Add(com.createObjectAdapter("AdapterAMI64", endpoints[0].ToString())); for (i = 0; i < nRetry && getAdapterNameWithAMI(obj).Equals("AdapterAMI64"); i++) { ; } test(i == nRetry); deactivate(com, adapters); } WriteLine("ok"); Write("testing endpoint mode filtering... "); Flush(); { List <RemoteObjectAdapterPrx> adapters = new List <RemoteObjectAdapterPrx>(); adapters.Add(com.createObjectAdapter("Adapter71", "default")); adapters.Add(com.createObjectAdapter("Adapter72", "udp")); TestIntfPrx obj = createTestIntfPrx(adapters); test(obj.getAdapterName().Equals("Adapter71")); TestIntfPrx testUDP = TestIntfPrxHelper.uncheckedCast(obj.ice_datagram()); test(obj.ice_getConnection() != testUDP.ice_getConnection()); try { testUDP.getAdapterName(); } catch (System.ArgumentException) { } } WriteLine("ok"); if (communicator.getProperties().getProperty("Ice.Plugin.IceSSL").Length > 0) { Write("testing unsecure vs. secure endpoints... "); Flush(); { List <RemoteObjectAdapterPrx> adapters = new List <RemoteObjectAdapterPrx>(); adapters.Add(com.createObjectAdapter("Adapter81", "ssl")); adapters.Add(com.createObjectAdapter("Adapter82", "tcp")); TestIntfPrx obj = createTestIntfPrx(adapters); int i; for (i = 0; i < 5; i++) { test(obj.getAdapterName().Equals("Adapter82")); obj.ice_getConnection().close(false); } TestIntfPrx testSecure = TestIntfPrxHelper.uncheckedCast(obj.ice_secure(true)); test(testSecure.ice_isSecure()); testSecure = TestIntfPrxHelper.uncheckedCast(obj.ice_secure(false)); test(!testSecure.ice_isSecure()); testSecure = TestIntfPrxHelper.uncheckedCast(obj.ice_secure(true)); test(testSecure.ice_isSecure()); test(obj.ice_getConnection() != testSecure.ice_getConnection()); com.deactivateObjectAdapter((RemoteObjectAdapterPrx)adapters[1]); for (i = 0; i < 5; i++) { test(obj.getAdapterName().Equals("Adapter81")); obj.ice_getConnection().close(false); } com.createObjectAdapter("Adapter83", (obj.ice_getEndpoints()[1]).ToString()); // Reactive tcp OA. for (i = 0; i < 5; i++) { test(obj.getAdapterName().Equals("Adapter83")); obj.ice_getConnection().close(false); } com.deactivateObjectAdapter((RemoteObjectAdapterPrx)adapters[0]); try { testSecure.ice_ping(); test(false); } catch (Ice.ConnectFailedException) { } deactivate(com, adapters); } WriteLine("ok"); } { Write("testing ipv4 & ipv6 connections... "); Flush(); Ice.Properties ipv4 = Ice.Util.createProperties(); ipv4.setProperty("Ice.IPv4", "1"); ipv4.setProperty("Ice.IPv6", "0"); ipv4.setProperty("Adapter.Endpoints", "tcp -h localhost"); Ice.Properties ipv6 = Ice.Util.createProperties(); ipv6.setProperty("Ice.IPv4", "0"); ipv6.setProperty("Ice.IPv6", "1"); ipv6.setProperty("Adapter.Endpoints", "tcp -h localhost"); Ice.Properties bothPreferIPv4 = Ice.Util.createProperties(); bothPreferIPv4.setProperty("Ice.IPv4", "1"); bothPreferIPv4.setProperty("Ice.IPv6", "1"); bothPreferIPv4.setProperty("Ice.PreferIPv6Address", "0"); bothPreferIPv4.setProperty("Adapter.Endpoints", "tcp -h localhost"); Ice.Properties bothPreferIPv6 = Ice.Util.createProperties(); bothPreferIPv6.setProperty("Ice.IPv4", "1"); bothPreferIPv6.setProperty("Ice.IPv6", "1"); bothPreferIPv6.setProperty("Ice.PreferIPv6Address", "1"); bothPreferIPv6.setProperty("Adapter.Endpoints", "tcp -h localhost"); List <Ice.Properties> clientProps = new List <Ice.Properties>(); clientProps.Add(ipv4); clientProps.Add(ipv6); clientProps.Add(bothPreferIPv4); clientProps.Add(bothPreferIPv6); Ice.Properties anyipv4 = ipv4.ice_clone_(); anyipv4.setProperty("Adapter.Endpoints", "tcp -p 12012"); anyipv4.setProperty("Adapter.PublishedEndpoints", "tcp -h 127.0.0.1 -p 12012"); Ice.Properties anyipv6 = ipv6.ice_clone_(); anyipv6.setProperty("Adapter.Endpoints", "tcp -p 12012"); anyipv6.setProperty("Adapter.PublishedEndpoints", "tcp -h \".1\" -p 12012"); Ice.Properties anyboth = Ice.Util.createProperties(); anyboth.setProperty("Ice.IPv4", "1"); anyboth.setProperty("Ice.IPv6", "1"); anyboth.setProperty("Adapter.Endpoints", "tcp -p 12012"); anyboth.setProperty("Adapter.PublishedEndpoints", "tcp -h \"::1\" -p 12012:tcp -h 127.0.0.1 -p 12012"); Ice.Properties localipv4 = ipv4.ice_clone_(); localipv4.setProperty("Adapter.Endpoints", "tcp -h 127.0.0.1"); Ice.Properties localipv6 = ipv6.ice_clone_(); localipv6.setProperty("Adapter.Endpoints", "tcp -h \"::1\""); List <Ice.Properties> serverProps = new List <Ice.Properties>(clientProps); serverProps.Add(anyipv4); serverProps.Add(anyipv6); serverProps.Add(anyboth); serverProps.Add(localipv4); serverProps.Add(localipv6); bool ipv6NotSupported = false; foreach (Ice.Properties p in serverProps) { Ice.InitializationData serverInitData = new Ice.InitializationData(); serverInitData.properties = p; Ice.Communicator serverCommunicator = Ice.Util.initialize(serverInitData); Ice.ObjectAdapter oa; try { oa = serverCommunicator.createObjectAdapter("Adapter"); oa.activate(); } catch (Ice.DNSException) { serverCommunicator.destroy(); continue; // IP version not supported. } catch (Ice.SocketException) { if (p == ipv6) { ipv6NotSupported = true; } serverCommunicator.destroy(); continue; // IP version not supported. } Ice.ObjectPrx prx = oa.createProxy(Ice.Util.stringToIdentity("dummy")); try { prx.ice_collocationOptimized(false).ice_ping(); } catch (Ice.LocalException) { serverCommunicator.destroy(); continue; // IP version not supported. } string strPrx = prx.ToString(); foreach (Ice.Properties q in clientProps) { Ice.InitializationData clientInitData = new Ice.InitializationData(); clientInitData.properties = q; Ice.Communicator clientCommunicator = Ice.Util.initialize(clientInitData); prx = clientCommunicator.stringToProxy(strPrx); try { prx.ice_ping(); test(false); } catch (Ice.ObjectNotExistException) { // Expected, no object registered. } catch (Ice.DNSException) { // Expected if no IPv4 or IPv6 address is // associated to localhost or if trying to connect // to an any endpoint with the wrong IP version, // e.g.: resolving an IPv4 address when only IPv6 // is enabled fails with a DNS exception. } catch (Ice.SocketException) { test((p == ipv4 && q == ipv6) || (p == ipv6 && q == ipv4) || (p == bothPreferIPv4 && q == ipv6) || (p == bothPreferIPv6 && q == ipv4) || (p == bothPreferIPv6 && q == ipv6 && ipv6NotSupported) || (p == anyipv4 && q == ipv6) || (p == anyipv6 && q == ipv4) || (p == localipv4 && q == ipv6) || (p == localipv6 && q == ipv4) || (p == ipv6 && q == bothPreferIPv4) || (p == ipv6 && q == bothPreferIPv6) || (p == bothPreferIPv6 && q == ipv6)); } clientCommunicator.destroy(); } serverCommunicator.destroy(); } WriteLine("ok"); } com.shutdown(); }
public static TestIntfPrx allTests(TestCommon.Application app, bool collocated) { Ice.Communicator communicator = app.communicator(); Write("testing stringToProxy... "); Flush(); String @ref = "Test:" + app.getTestEndpoint(0) + " -t 2000"; Ice.ObjectPrx @base = communicator.stringToProxy(@ref); test(@base != null); WriteLine("ok"); Write("testing checked cast... "); Flush(); TestIntfPrx testPrx = TestIntfPrxHelper.checkedCast(@base); test(testPrx != null); test(testPrx.Equals(@base)); WriteLine("ok"); Write("base... "); Flush(); { try { testPrx.baseAsBase(); test(false); } catch (Base b) { test(b.b.Equals("Base.b")); test(b.GetType().FullName.Equals("Test.Base")); } catch (Exception) { test(false); } } WriteLine("ok"); Write("base (AMI)... "); Flush(); { Callback cb = new Callback(); testPrx.begin_baseAsBase().whenCompleted( () => { test(false); }, (Ice.Exception ex) => { try { throw ex; } catch (Base b) { test(b.b.Equals("Base.b")); test(b.GetType().Name.Equals("Base")); } catch (Exception) { test(false); } cb.called(); }); cb.check(); try { testPrx.baseAsBaseAsync().Wait(); test(false); } catch (AggregateException ae) { try { throw ae.InnerException; } catch (Base b) { test(b.b.Equals("Base.b")); test(b.GetType().Name.Equals("Base")); } catch (Exception) { test(false); } } } WriteLine("ok"); Write("slicing of unknown derived... "); Flush(); { try { testPrx.unknownDerivedAsBase(); test(false); } catch (Base b) { test(b.b.Equals("UnknownDerived.b")); test(b.GetType().FullName.Equals("Test.Base")); } catch (Exception) { test(false); } } WriteLine("ok"); Write("slicing of unknown derived (AMI)... "); Flush(); { Callback cb = new Callback(); testPrx.begin_unknownDerivedAsBase().whenCompleted( () => { test(false); }, (Ice.Exception ex) => { try { throw ex; } catch (Base b) { test(b.b.Equals("UnknownDerived.b")); test(b.GetType().Name.Equals("Base")); } catch (Exception) { test(false); } cb.called(); }); cb.check(); try { testPrx.unknownDerivedAsBaseAsync().Wait(); test(false); } catch (AggregateException ae) { try { throw ae.InnerException; } catch (Base b) { test(b.b.Equals("UnknownDerived.b")); test(b.GetType().Name.Equals("Base")); } catch (Exception) { test(false); } } } WriteLine("ok"); Write("non-slicing of known derived as base... "); Flush(); { try { testPrx.knownDerivedAsBase(); test(false); } catch (KnownDerived k) { test(k.b.Equals("KnownDerived.b")); test(k.kd.Equals("KnownDerived.kd")); test(k.GetType().FullName.Equals("Test.KnownDerived")); } catch (Exception) { test(false); } } WriteLine("ok"); Write("non-slicing of known derived as base (AMI)... "); Flush(); { Callback cb = new Callback(); testPrx.begin_knownDerivedAsBase().whenCompleted( () => { test(false); }, (Ice.Exception ex) => { try { throw ex; } catch (KnownDerived k) { test(k.b.Equals("KnownDerived.b")); test(k.kd.Equals("KnownDerived.kd")); test(k.GetType().Name.Equals("KnownDerived")); } catch (Exception) { test(false); } cb.called(); }); cb.check(); try { testPrx.knownDerivedAsBaseAsync().Wait(); test(false); } catch (AggregateException ae) { try { throw ae.InnerException; } catch (KnownDerived k) { test(k.b.Equals("KnownDerived.b")); test(k.kd.Equals("KnownDerived.kd")); test(k.GetType().Name.Equals("KnownDerived")); } catch (Exception) { test(false); } } } WriteLine("ok"); Write("non-slicing of known derived as derived... "); Flush(); { try { testPrx.knownDerivedAsKnownDerived(); test(false); } catch (KnownDerived k) { test(k.b.Equals("KnownDerived.b")); test(k.kd.Equals("KnownDerived.kd")); test(k.GetType().FullName.Equals("Test.KnownDerived")); } catch (Exception) { test(false); } } WriteLine("ok"); Write("non-slicing of known derived as derived (AMI)... "); Flush(); { Callback cb = new Callback(); testPrx.begin_knownDerivedAsKnownDerived().whenCompleted( () => { test(false); }, (Ice.Exception ex) => { try { throw ex; } catch (KnownDerived k) { test(k.b.Equals("KnownDerived.b")); test(k.kd.Equals("KnownDerived.kd")); test(k.GetType().Name.Equals("KnownDerived")); } catch (Exception) { test(false); } cb.called(); }); cb.check(); try { testPrx.knownDerivedAsKnownDerivedAsync().Wait(); test(false); } catch (AggregateException ae) { try { throw ae.InnerException; } catch (KnownDerived k) { test(k.b.Equals("KnownDerived.b")); test(k.kd.Equals("KnownDerived.kd")); test(k.GetType().Name.Equals("KnownDerived")); } catch (Exception) { test(false); } } } WriteLine("ok"); Write("slicing of unknown intermediate as base... "); Flush(); { try { testPrx.unknownIntermediateAsBase(); test(false); } catch (Base b) { test(b.b.Equals("UnknownIntermediate.b")); test(b.GetType().FullName.Equals("Test.Base")); } catch (Exception) { test(false); } } WriteLine("ok"); Write("slicing of unknown intermediate as base (AMI)... "); Flush(); { Callback cb = new Callback(); testPrx.begin_unknownIntermediateAsBase().whenCompleted( () => { test(false); }, (Ice.Exception ex) => { try { throw ex; } catch (Base b) { test(b.b.Equals("UnknownIntermediate.b")); test(b.GetType().Name.Equals("Base")); } catch (Exception) { test(false); } cb.called(); }); cb.check(); try { testPrx.unknownIntermediateAsBaseAsync().Wait(); test(false); } catch (AggregateException ae) { try { throw ae.InnerException; } catch (Base b) { test(b.b.Equals("UnknownIntermediate.b")); test(b.GetType().Name.Equals("Base")); } catch (Exception) { test(false); } } } WriteLine("ok"); Write("slicing of known intermediate as base... "); Flush(); { try { testPrx.knownIntermediateAsBase(); test(false); } catch (KnownIntermediate ki) { test(ki.b.Equals("KnownIntermediate.b")); test(ki.ki.Equals("KnownIntermediate.ki")); test(ki.GetType().FullName.Equals("Test.KnownIntermediate")); } catch (Exception) { test(false); } } WriteLine("ok"); Write("slicing of known intermediate as base (AMI)... "); Flush(); { Callback cb = new Callback(); testPrx.begin_knownIntermediateAsBase().whenCompleted( () => { test(false); }, (Ice.Exception ex) => { try { throw ex; } catch (KnownIntermediate ki) { test(ki.b.Equals("KnownIntermediate.b")); test(ki.ki.Equals("KnownIntermediate.ki")); test(ki.GetType().Name.Equals("KnownIntermediate")); } catch (Exception) { test(false); } cb.called(); }); cb.check(); try { testPrx.knownIntermediateAsBaseAsync().Wait(); test(false); } catch (AggregateException ae) { try { throw ae.InnerException; } catch (KnownIntermediate ki) { test(ki.b.Equals("KnownIntermediate.b")); test(ki.ki.Equals("KnownIntermediate.ki")); test(ki.GetType().Name.Equals("KnownIntermediate")); } catch (Exception) { test(false); } } } WriteLine("ok"); Write("slicing of known most derived as base... "); Flush(); { try { testPrx.knownMostDerivedAsBase(); test(false); } catch (KnownMostDerived kmd) { test(kmd.b.Equals("KnownMostDerived.b")); test(kmd.ki.Equals("KnownMostDerived.ki")); test(kmd.kmd.Equals("KnownMostDerived.kmd")); test(kmd.GetType().FullName.Equals("Test.KnownMostDerived")); } catch (Exception) { test(false); } } WriteLine("ok"); Write("slicing of known most derived as base (AMI)... "); Flush(); { Callback cb = new Callback(); testPrx.begin_knownMostDerivedAsBase().whenCompleted( () => { test(false); }, (Ice.Exception ex) => { try { throw ex; } catch (KnownMostDerived kmd) { test(kmd.b.Equals("KnownMostDerived.b")); test(kmd.ki.Equals("KnownMostDerived.ki")); test(kmd.kmd.Equals("KnownMostDerived.kmd")); test(kmd.GetType().Name.Equals("KnownMostDerived")); } catch (Exception) { test(false); } cb.called(); }); cb.check(); try { testPrx.knownMostDerivedAsBaseAsync().Wait(); test(false); } catch (AggregateException ae) { try { throw ae.InnerException; } catch (KnownMostDerived kmd) { test(kmd.b.Equals("KnownMostDerived.b")); test(kmd.ki.Equals("KnownMostDerived.ki")); test(kmd.kmd.Equals("KnownMostDerived.kmd")); test(kmd.GetType().Name.Equals("KnownMostDerived")); } catch (Exception) { test(false); } } } WriteLine("ok"); Write("non-slicing of known intermediate as intermediate... "); Flush(); { try { testPrx.knownIntermediateAsKnownIntermediate(); test(false); } catch (KnownIntermediate ki) { test(ki.b.Equals("KnownIntermediate.b")); test(ki.ki.Equals("KnownIntermediate.ki")); test(ki.GetType().FullName.Equals("Test.KnownIntermediate")); } catch (Exception) { test(false); } } WriteLine("ok"); Write("non-slicing of known intermediate as intermediate (AMI)... "); Flush(); { Callback cb = new Callback(); testPrx.begin_knownIntermediateAsKnownIntermediate().whenCompleted( () => { test(false); }, (Ice.Exception ex) => { try { throw ex; } catch (KnownIntermediate ki) { test(ki.b.Equals("KnownIntermediate.b")); test(ki.ki.Equals("KnownIntermediate.ki")); test(ki.GetType().Name.Equals("KnownIntermediate")); } catch (Exception) { test(false); } cb.called(); }); cb.check(); try { testPrx.knownIntermediateAsKnownIntermediateAsync().Wait(); test(false); } catch (AggregateException ae) { try { throw ae.InnerException; } catch (KnownIntermediate ki) { test(ki.b.Equals("KnownIntermediate.b")); test(ki.ki.Equals("KnownIntermediate.ki")); test(ki.GetType().Name.Equals("KnownIntermediate")); } catch (Exception) { test(false); } } } WriteLine("ok"); Write("non-slicing of known most derived as intermediate... "); Flush(); { try { testPrx.knownMostDerivedAsKnownIntermediate(); test(false); } catch (KnownMostDerived kmd) { test(kmd.b.Equals("KnownMostDerived.b")); test(kmd.ki.Equals("KnownMostDerived.ki")); test(kmd.kmd.Equals("KnownMostDerived.kmd")); test(kmd.GetType().FullName.Equals("Test.KnownMostDerived")); } catch (Exception) { test(false); } } WriteLine("ok"); Write("non-slicing of known most derived as intermediate (AMI)... "); Flush(); { Callback cb = new Callback(); testPrx.begin_knownMostDerivedAsKnownIntermediate().whenCompleted( () => { test(false); }, (Ice.Exception ex) => { try { throw ex; } catch (KnownMostDerived kmd) { test(kmd.b.Equals("KnownMostDerived.b")); test(kmd.ki.Equals("KnownMostDerived.ki")); test(kmd.kmd.Equals("KnownMostDerived.kmd")); test(kmd.GetType().Name.Equals("KnownMostDerived")); } catch (Exception) { test(false); } cb.called(); }); cb.check(); try { testPrx.knownMostDerivedAsKnownIntermediateAsync().Wait(); test(false); } catch (AggregateException ae) { try { throw ae.InnerException; } catch (KnownMostDerived kmd) { test(kmd.b.Equals("KnownMostDerived.b")); test(kmd.ki.Equals("KnownMostDerived.ki")); test(kmd.kmd.Equals("KnownMostDerived.kmd")); test(kmd.GetType().Name.Equals("KnownMostDerived")); } catch (Exception) { test(false); } } } WriteLine("ok"); Write("non-slicing of known most derived as most derived... "); Flush(); { try { testPrx.knownMostDerivedAsKnownMostDerived(); test(false); } catch (KnownMostDerived kmd) { test(kmd.b.Equals("KnownMostDerived.b")); test(kmd.ki.Equals("KnownMostDerived.ki")); test(kmd.kmd.Equals("KnownMostDerived.kmd")); test(kmd.GetType().FullName.Equals("Test.KnownMostDerived")); } catch (Exception) { test(false); } } WriteLine("ok"); Write("non-slicing of known most derived as most derived (AMI)... "); Flush(); { Callback cb = new Callback(); testPrx.begin_knownMostDerivedAsKnownMostDerived().whenCompleted( () => { test(false); }, (Ice.Exception ex) => { try { throw ex; } catch (KnownMostDerived kmd) { test(kmd.b.Equals("KnownMostDerived.b")); test(kmd.ki.Equals("KnownMostDerived.ki")); test(kmd.kmd.Equals("KnownMostDerived.kmd")); test(kmd.GetType().Name.Equals("KnownMostDerived")); } catch (Exception) { test(false); } cb.called(); }); cb.check(); try { testPrx.knownMostDerivedAsKnownMostDerivedAsync().Wait(); test(false); } catch (AggregateException ae) { try { throw ae.InnerException; } catch (KnownMostDerived kmd) { test(kmd.b.Equals("KnownMostDerived.b")); test(kmd.ki.Equals("KnownMostDerived.ki")); test(kmd.kmd.Equals("KnownMostDerived.kmd")); test(kmd.GetType().Name.Equals("KnownMostDerived")); } catch (Exception) { test(false); } } } WriteLine("ok"); Write("slicing of unknown most derived, known intermediate as base... "); Flush(); { try { testPrx.unknownMostDerived1AsBase(); test(false); } catch (KnownIntermediate ki) { test(ki.b.Equals("UnknownMostDerived1.b")); test(ki.ki.Equals("UnknownMostDerived1.ki")); test(ki.GetType().FullName.Equals("Test.KnownIntermediate")); } catch (Exception) { test(false); } } WriteLine("ok"); Write("slicing of unknown most derived, known intermediate as base (AMI)... "); Flush(); { Callback cb = new Callback(); testPrx.begin_unknownMostDerived1AsBase().whenCompleted( () => { test(false); }, (Ice.Exception ex) => { try { throw ex; } catch (KnownIntermediate ki) { test(ki.b.Equals("UnknownMostDerived1.b")); test(ki.ki.Equals("UnknownMostDerived1.ki")); test(ki.GetType().Name.Equals("KnownIntermediate")); } catch (Exception) { test(false); } cb.called(); }); cb.check(); try { testPrx.unknownMostDerived1AsBaseAsync().Wait(); test(false); } catch (AggregateException ae) { try { throw ae.InnerException; } catch (KnownIntermediate ki) { test(ki.b.Equals("UnknownMostDerived1.b")); test(ki.ki.Equals("UnknownMostDerived1.ki")); test(ki.GetType().Name.Equals("KnownIntermediate")); } catch (Exception) { test(false); } } } WriteLine("ok"); Write("slicing of unknown most derived, known intermediate as intermediate... "); Flush(); { try { testPrx.unknownMostDerived1AsKnownIntermediate(); test(false); } catch (KnownIntermediate ki) { test(ki.b.Equals("UnknownMostDerived1.b")); test(ki.ki.Equals("UnknownMostDerived1.ki")); test(ki.GetType().FullName.Equals("Test.KnownIntermediate")); } catch (Exception) { test(false); } } WriteLine("ok"); Write("slicing of unknown most derived, known intermediate as intermediate (AMI)... "); Flush(); { Callback cb = new Callback(); testPrx.begin_unknownMostDerived1AsKnownIntermediate().whenCompleted( () => { test(false); }, (Ice.Exception ex) => { try { throw ex; } catch (KnownIntermediate ki) { test(ki.b.Equals("UnknownMostDerived1.b")); test(ki.ki.Equals("UnknownMostDerived1.ki")); test(ki.GetType().Name.Equals("KnownIntermediate")); } catch (Exception) { test(false); } cb.called(); }); cb.check(); try { testPrx.unknownMostDerived1AsKnownIntermediateAsync().Wait(); test(false); } catch (AggregateException ae) { try { throw ae.InnerException; } catch (KnownIntermediate ki) { test(ki.b.Equals("UnknownMostDerived1.b")); test(ki.ki.Equals("UnknownMostDerived1.ki")); test(ki.GetType().Name.Equals("KnownIntermediate")); } catch (Exception) { test(false); } } } WriteLine("ok"); Write("slicing of unknown most derived, unknown intermediate thrown as base... "); Flush(); { try { testPrx.unknownMostDerived2AsBase(); test(false); } catch (Base b) { test(b.b.Equals("UnknownMostDerived2.b")); test(b.GetType().FullName.Equals("Test.Base")); } catch (Exception) { test(false); } } WriteLine("ok"); Write("slicing of unknown most derived, unknown intermediate thrown as base (AMI)... "); Flush(); { Callback cb = new Callback(); testPrx.begin_unknownMostDerived2AsBase().whenCompleted( () => { test(false); }, (Ice.Exception ex) => { try { throw ex; } catch (Base b) { test(b.b.Equals("UnknownMostDerived2.b")); test(b.GetType().Name.Equals("Base")); } catch (Exception) { test(false); } cb.called(); }); cb.check(); try { testPrx.unknownMostDerived2AsBaseAsync().Wait(); test(false); } catch (AggregateException ae) { try { throw ae.InnerException; } catch (Base b) { test(b.b.Equals("UnknownMostDerived2.b")); test(b.GetType().Name.Equals("Base")); } catch (Exception) { test(false); } } } WriteLine("ok"); Write("unknown most derived in compact format... "); Flush(); { try { testPrx.unknownMostDerived2AsBaseCompact(); test(false); } catch (Base) { // // For the 1.0 encoding, the unknown exception is sliced to Base. // test(testPrx.ice_getEncodingVersion().Equals(Ice.Util.Encoding_1_0)); } catch (Ice.UnknownUserException) { // // A MarshalException is raised for the compact format because the // most-derived type is unknown and the exception cannot be sliced. // test(!testPrx.ice_getEncodingVersion().Equals(Ice.Util.Encoding_1_0)); } catch (Ice.OperationNotExistException) { } catch (Exception) { test(false); } } WriteLine("ok"); string defaultHost = communicator.getProperties().getProperty("Ice.Default.Host"); if (defaultHost.Equals("127.0.0.1") || defaultHost.Equals("::1")) { Write("preserved exceptions... "); Flush(); { Ice.ObjectAdapter adapter = communicator.createObjectAdapterWithEndpoints("Relay", "default"); RelayPrx relay = RelayPrxHelper.uncheckedCast(adapter.addWithUUID(new RelayI())); adapter.activate(); try { testPrx.relayKnownPreservedAsBase(relay); test(false); } catch (KnownPreservedDerived ex) { test(ex.b.Equals("base")); test(ex.kp.Equals("preserved")); test(ex.kpd.Equals("derived")); } catch (Ice.OperationNotExistException) { } catch (Exception) { test(false); } try { testPrx.relayKnownPreservedAsKnownPreserved(relay); test(false); } catch (KnownPreservedDerived ex) { test(ex.b.Equals("base")); test(ex.kp.Equals("preserved")); test(ex.kpd.Equals("derived")); } catch (Ice.OperationNotExistException) { } catch (Exception) { test(false); } try { testPrx.relayUnknownPreservedAsBase(relay); test(false); } catch (Preserved2 ex) { test(ex.b.Equals("base")); test(ex.kp.Equals("preserved")); test(ex.kpd.Equals("derived")); test(ex.p1.ice_id().Equals(PreservedClass.ice_staticId())); PreservedClass pc = ex.p1 as PreservedClass; test(pc.bc.Equals("bc")); test(pc.pc.Equals("pc")); test(ex.p2 == ex.p1); } catch (KnownPreservedDerived ex) { // // For the 1.0 encoding, the unknown exception is sliced to KnownPreserved. // test(testPrx.ice_getEncodingVersion().Equals(Ice.Util.Encoding_1_0)); test(ex.b.Equals("base")); test(ex.kp.Equals("preserved")); test(ex.kpd.Equals("derived")); } catch (Ice.OperationNotExistException) { } catch (Exception) { test(false); } try { testPrx.relayUnknownPreservedAsKnownPreserved(relay); test(false); } catch (Preserved2 ex) { test(ex.b.Equals("base")); test(ex.kp.Equals("preserved")); test(ex.kpd.Equals("derived")); test(ex.p1.ice_id().Equals(PreservedClass.ice_staticId())); PreservedClass pc = ex.p1 as PreservedClass; test(pc.bc.Equals("bc")); test(pc.pc.Equals("pc")); test(ex.p2 == ex.p1); } catch (KnownPreservedDerived ex) { // // For the 1.0 encoding, the unknown exception is sliced to KnownPreserved. // test(testPrx.ice_getEncodingVersion().Equals(Ice.Util.Encoding_1_0)); test(ex.b.Equals("base")); test(ex.kp.Equals("preserved")); test(ex.kpd.Equals("derived")); } catch (Ice.OperationNotExistException) { } catch (Exception) { test(false); } adapter.destroy(); } WriteLine("ok"); } return(testPrx); }
public static void allTests(TestCommon.Application app) { Ice.Communicator communicator = app.communicator(); Write("testing proxy endpoint information... "); Flush(); { Ice.ObjectPrx 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"); Ice.Endpoint[] endps = p1.ice_getEndpoints(); Ice.EndpointInfo info = endps[0].getInfo(); Ice.TCPEndpointInfo tcpEndpoint = getTCPEndpointInfo(info); test(tcpEndpoint.host.Equals("tcphost")); test(tcpEndpoint.port == 10000); test(tcpEndpoint.sourceAddress.Equals("10.10.10.10")); test(tcpEndpoint.timeout == 1200); test(tcpEndpoint.compress); test(!tcpEndpoint.datagram()); test(tcpEndpoint.type() == Ice.TCPEndpointType.value && !tcpEndpoint.secure() || tcpEndpoint.type() == Ice.SSLEndpointType.value && tcpEndpoint.secure() || tcpEndpoint.type() == Ice.WSEndpointType.value && !tcpEndpoint.secure() || tcpEndpoint.type() == Ice.WSSEndpointType.value && tcpEndpoint.secure()); test(tcpEndpoint.type() == Ice.TCPEndpointType.value && info is Ice.TCPEndpointInfo || tcpEndpoint.type() == Ice.SSLEndpointType.value && info is IceSSL.EndpointInfo || tcpEndpoint.type() == Ice.WSEndpointType.value && info is Ice.WSEndpointInfo || tcpEndpoint.type() == Ice.WSSEndpointType.value && info is Ice.WSEndpointInfo); Ice.UDPEndpointInfo udpEndpoint = (Ice.UDPEndpointInfo)endps[1].getInfo(); test(udpEndpoint.host.Equals("udphost")); test(udpEndpoint.port == 10001); test(udpEndpoint.mcastInterface.Equals("eth0")); test(udpEndpoint.mcastTtl == 5); test(udpEndpoint.sourceAddress.Equals("10.10.10.10")); test(udpEndpoint.timeout == -1); test(!udpEndpoint.compress); test(!udpEndpoint.secure()); test(udpEndpoint.datagram()); test(udpEndpoint.type() == 3); Ice.OpaqueEndpointInfo opaqueEndpoint = (Ice.OpaqueEndpointInfo)endps[2].getInfo(); test(opaqueEndpoint.rawBytes.Length > 0); test(opaqueEndpoint.rawEncoding.Equals(new Ice.EncodingVersion(1, 8))); } WriteLine("ok"); string defaultHost = communicator.getProperties().getProperty("Ice.Default.Host"); Ice.ObjectAdapter adapter; Write("test object adapter endpoint information... "); Flush(); { communicator.getProperties().setProperty("TestAdapter.Endpoints", "default -t 15000:udp"); adapter = communicator.createObjectAdapter("TestAdapter"); Ice.Endpoint[] endpoints = adapter.getEndpoints(); test(endpoints.Length == 2); Ice.Endpoint[] publishedEndpoints = adapter.getPublishedEndpoints(); test(IceUtilInternal.Arrays.Equals(endpoints, publishedEndpoints)); Ice.TCPEndpointInfo tcpEndpoint = getTCPEndpointInfo(endpoints[0].getInfo()); test(tcpEndpoint.type() == Ice.TCPEndpointType.value || tcpEndpoint.type() == Ice.SSLEndpointType.value || tcpEndpoint.type() == Ice.WSEndpointType.value || tcpEndpoint.type() == Ice.WSSEndpointType.value); test(tcpEndpoint.host.Equals(defaultHost)); test(tcpEndpoint.port > 0); test(tcpEndpoint.timeout == 15000); Ice.UDPEndpointInfo udpEndpoint = (Ice.UDPEndpointInfo)endpoints[1].getInfo(); test(udpEndpoint.host.Equals(defaultHost)); test(udpEndpoint.datagram()); test(udpEndpoint.port > 0); endpoints = new Ice.Endpoint[] { endpoints[0] }; test(endpoints.Length == 1); adapter.setPublishedEndpoints(endpoints); publishedEndpoints = adapter.getPublishedEndpoints(); test(IceUtilInternal.Arrays.Equals(endpoints, publishedEndpoints)); adapter.destroy(); int port = app.getTestPort(1); communicator.getProperties().setProperty("TestAdapter.Endpoints", "default -h * -p " + port); communicator.getProperties().setProperty("TestAdapter.PublishedEndpoints", app.getTestEndpoint(1)); adapter = communicator.createObjectAdapter("TestAdapter"); endpoints = adapter.getEndpoints(); test(endpoints.Length >= 1); publishedEndpoints = adapter.getPublishedEndpoints(); test(publishedEndpoints.Length == 1); foreach (Ice.Endpoint endpoint in endpoints) { tcpEndpoint = getTCPEndpointInfo(endpoint.getInfo()); test(tcpEndpoint.port == port); } tcpEndpoint = getTCPEndpointInfo(publishedEndpoints[0].getInfo()); test(tcpEndpoint.host.Equals("127.0.0.1")); test(tcpEndpoint.port == port); adapter.destroy(); } WriteLine("ok"); int endpointPort = app.getTestPort(0); Ice.ObjectPrx @base = communicator.stringToProxy("test:" + app.getTestEndpoint(0) + ":" + app.getTestEndpoint(0, "udp")); TestIntfPrx testIntf = TestIntfPrxHelper.checkedCast(@base); Write("test connection endpoint information... "); Flush(); { Ice.EndpointInfo info = @base.ice_getConnection().getEndpoint().getInfo(); Ice.TCPEndpointInfo tcpinfo = getTCPEndpointInfo(info); test(tcpinfo.port == endpointPort); test(!tcpinfo.compress); test(tcpinfo.host.Equals(defaultHost)); Dictionary <string, string> ctx = testIntf.getEndpointInfoAsContext(); test(ctx["host"].Equals(tcpinfo.host)); test(ctx["compress"].Equals("false")); int port = System.Int32.Parse(ctx["port"]); test(port > 0); info = @base.ice_datagram().ice_getConnection().getEndpoint().getInfo(); Ice.UDPEndpointInfo udp = (Ice.UDPEndpointInfo)info; test(udp.port == endpointPort); test(udp.host.Equals(defaultHost)); } WriteLine("ok"); Write("testing connection information... "); Flush(); { Ice.Connection connection = @base.ice_getConnection(); connection.setBufferSize(1024, 2048); Ice.ConnectionInfo info = connection.getInfo(); Ice.TCPConnectionInfo ipInfo = getTCPConnectionInfo(info); test(!info.incoming); test(info.adapterName.Length == 0); test(ipInfo.remotePort == endpointPort); test(ipInfo.localPort > 0); if (defaultHost.Equals("127.0.0.1")) { test(ipInfo.localAddress.Equals(defaultHost)); test(ipInfo.remoteAddress.Equals(defaultHost)); } test(ipInfo.rcvSize >= 1024); test(ipInfo.sndSize >= 2048); Dictionary <string, string> ctx = testIntf.getConnectionInfoAsContext(); test(ctx["incoming"].Equals("true")); test(ctx["adapterName"].Equals("TestAdapter")); test(ctx["remoteAddress"].Equals(ipInfo.localAddress)); test(ctx["localAddress"].Equals(ipInfo.remoteAddress)); test(ctx["remotePort"].Equals(ipInfo.localPort.ToString())); test(ctx["localPort"].Equals(ipInfo.remotePort.ToString())); if (@base.ice_getConnection().type().Equals("ws") || @base.ice_getConnection().type().Equals("wss")) { Dictionary <string, string> headers = ((Ice.WSConnectionInfo)info).headers; test(headers["Upgrade"].Equals("websocket")); test(headers["Connection"].Equals("Upgrade")); test(headers["Sec-WebSocket-Protocol"].Equals("ice.zeroc.com")); test(headers["Sec-WebSocket-Accept"] != null); test(ctx["ws.Upgrade"].Equals("websocket")); test(ctx["ws.Connection"].Equals("Upgrade")); test(ctx["ws.Sec-WebSocket-Protocol"].Equals("ice.zeroc.com")); test(ctx["ws.Sec-WebSocket-Version"].Equals("13")); test(ctx["ws.Sec-WebSocket-Key"] != null); } connection = @base.ice_datagram().ice_getConnection(); connection.setBufferSize(2048, 1024); Ice.UDPConnectionInfo udpInfo = (Ice.UDPConnectionInfo)connection.getInfo(); test(!udpInfo.incoming); test(udpInfo.adapterName.Length == 0); test(udpInfo.localPort > 0); test(udpInfo.remotePort == endpointPort); if (defaultHost.Equals("127.0.0.1")) { test(udpInfo.remoteAddress.Equals(defaultHost)); test(udpInfo.localAddress.Equals(defaultHost)); } test(udpInfo.rcvSize >= 2048); test(udpInfo.sndSize >= 1024); } WriteLine("ok"); testIntf.shutdown(); communicator.shutdown(); communicator.waitForShutdown(); }
public static void allTests(TestCommon.Application app) { Ice.Communicator communicator = app.communicator(); ServerManagerPrx manager = ServerManagerPrxHelper.checkedCast( communicator.stringToProxy("ServerManager :" + app.getTestEndpoint(0))); test(manager != null); TestLocatorPrx locator = TestLocatorPrxHelper.uncheckedCast(communicator.getDefaultLocator()); test(locator != null); TestLocatorRegistryPrx registry = TestLocatorRegistryPrxHelper.checkedCast(locator.getRegistry()); test(registry != null); Write("testing stringToProxy... "); Flush(); Ice.ObjectPrx @base = communicator.stringToProxy("test @ TestAdapter"); Ice.ObjectPrx base2 = communicator.stringToProxy("test @ TestAdapter"); Ice.ObjectPrx base3 = communicator.stringToProxy("test"); Ice.ObjectPrx base4 = communicator.stringToProxy("ServerManager"); Ice.ObjectPrx base5 = communicator.stringToProxy("test2"); Ice.ObjectPrx base6 = communicator.stringToProxy("test @ ReplicatedAdapter"); WriteLine("ok"); Write("testing ice_locator and ice_getLocator... "); test(Ice.Util.proxyIdentityCompare(@base.ice_getLocator(), communicator.getDefaultLocator()) == 0); Ice.LocatorPrx anotherLocator = Ice.LocatorPrxHelper.uncheckedCast(communicator.stringToProxy("anotherLocator")); @base = @base.ice_locator(anotherLocator); test(Ice.Util.proxyIdentityCompare(@base.ice_getLocator(), anotherLocator) == 0); communicator.setDefaultLocator(null); @base = communicator.stringToProxy("test @ TestAdapter"); test(@base.ice_getLocator() == null); @base = @base.ice_locator(anotherLocator); test(Ice.Util.proxyIdentityCompare(@base.ice_getLocator(), anotherLocator) == 0); communicator.setDefaultLocator(locator); @base = communicator.stringToProxy("test @ TestAdapter"); test(Ice.Util.proxyIdentityCompare(@base.ice_getLocator(), communicator.getDefaultLocator()) == 0); // // We also test ice_router/ice_getRouter (perhaps we should add a // test/Ice/router test?) // test(@base.ice_getRouter() == null); Ice.RouterPrx anotherRouter = Ice.RouterPrxHelper.uncheckedCast(communicator.stringToProxy("anotherRouter")); @base = @base.ice_router(anotherRouter); test(Ice.Util.proxyIdentityCompare(@base.ice_getRouter(), anotherRouter) == 0); Ice.RouterPrx router = Ice.RouterPrxHelper.uncheckedCast(communicator.stringToProxy("dummyrouter")); communicator.setDefaultRouter(router); @base = communicator.stringToProxy("test @ TestAdapter"); test(Ice.Util.proxyIdentityCompare(@base.ice_getRouter(), communicator.getDefaultRouter()) == 0); communicator.setDefaultRouter(null); @base = communicator.stringToProxy("test @ TestAdapter"); test(@base.ice_getRouter() == null); WriteLine("ok"); Write("starting server... "); Flush(); manager.startServer(); WriteLine("ok"); Write("testing checked cast... "); Flush(); TestIntfPrx obj = TestIntfPrxHelper.checkedCast(@base); test(obj != null); TestIntfPrx obj2 = TestIntfPrxHelper.checkedCast(base2); test(obj2 != null); TestIntfPrx obj3 = TestIntfPrxHelper.checkedCast(base3); test(obj3 != null); ServerManagerPrx obj4 = ServerManagerPrxHelper.checkedCast(base4); test(obj4 != null); TestIntfPrx obj5 = TestIntfPrxHelper.checkedCast(base5); test(obj5 != null); TestIntfPrx obj6 = TestIntfPrxHelper.checkedCast(base6); test(obj6 != null); WriteLine("ok"); Write("testing id@AdapterId indirect proxy... "); Flush(); obj.shutdown(); manager.startServer(); try { obj2.ice_ping(); } catch (Ice.LocalException) { test(false); } WriteLine("ok"); Write("testing id@ReplicaGroupId indirect proxy... "); Flush(); obj.shutdown(); manager.startServer(); try { obj6.ice_ping(); } catch (Ice.LocalException) { test(false); } WriteLine("ok"); Write("testing identity indirect proxy... "); Flush(); obj.shutdown(); manager.startServer(); try { obj3.ice_ping(); } catch (Ice.LocalException) { test(false); } try { obj2.ice_ping(); } catch (Ice.LocalException) { test(false); } obj.shutdown(); manager.startServer(); try { obj2.ice_ping(); } catch (Ice.LocalException) { test(false); } try { obj3.ice_ping(); } catch (Ice.LocalException) { test(false); } obj.shutdown(); manager.startServer(); try { obj2.ice_ping(); } catch (Ice.LocalException) { test(false); } obj.shutdown(); manager.startServer(); try { obj3.ice_ping(); } catch (Ice.LocalException) { test(false); } obj.shutdown(); manager.startServer(); try { obj5 = TestIntfPrxHelper.checkedCast(base5); obj5.ice_ping(); } catch (Ice.LocalException) { test(false); } WriteLine("ok"); Write("testing proxy with unknown identity... "); Flush(); try { @base = communicator.stringToProxy("unknown/unknown"); @base.ice_ping(); test(false); } catch (Ice.NotRegisteredException ex) { test(ex.kindOfObject.Equals("object")); test(ex.id.Equals("unknown/unknown")); } WriteLine("ok"); Write("testing proxy with unknown adapter... "); Flush(); try { @base = communicator.stringToProxy("test @ TestAdapterUnknown"); @base.ice_ping(); test(false); } catch (Ice.NotRegisteredException ex) { test(ex.kindOfObject.Equals("object adapter")); test(ex.id.Equals("TestAdapterUnknown")); } WriteLine("ok"); Write("testing locator cache timeout... "); Flush(); 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()); System.Threading.Thread.Sleep(1200); // 1200ms 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()); System.Threading.Thread.Sleep(1200); // 1200ms 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); WriteLine("ok"); Write("testing proxy from server... "); Flush(); obj = TestIntfPrxHelper.checkedCast(communicator.stringToProxy("test@TestAdapter")); HelloPrx hello = obj.getHello(); test(hello.ice_getAdapterId().Equals("TestAdapter")); hello.sayHello(); hello = obj.getReplicatedHello(); test(hello.ice_getAdapterId().Equals("ReplicatedAdapter")); hello.sayHello(); WriteLine("ok"); Write("testing locator request queuing... "); Flush(); hello = (HelloPrx)obj.getReplicatedHello().ice_locatorCacheTimeout(0).ice_connectionCached(false); count = locator.getRequestCount(); hello.ice_ping(); test(++count == locator.getRequestCount()); List <Ice.AsyncResult <Test.Callback_Hello_sayHello> > results = new List <Ice.AsyncResult <Test.Callback_Hello_sayHello> >(); for (int i = 0; i < 1000; i++) { Ice.AsyncResult <Test.Callback_Hello_sayHello> result = hello.begin_sayHello(). whenCompleted( () => { }, (Ice.Exception ex) => { test(false); }); results.Add(result); } foreach (Ice.AsyncResult <Test.Callback_Hello_sayHello> result in results) { result.waitForCompleted(); } results.Clear(); test(locator.getRequestCount() > count && locator.getRequestCount() < count + 999); if (locator.getRequestCount() > count + 800) { Write("queuing = " + (locator.getRequestCount() - count)); } count = locator.getRequestCount(); hello = (HelloPrx)hello.ice_adapterId("unknown"); for (int i = 0; i < 1000; i++) { Ice.AsyncResult <Test.Callback_Hello_sayHello> result = hello.begin_sayHello(). whenCompleted( () => { test(false); }, (Ice.Exception ex) => { test(ex is Ice.NotRegisteredException); }); results.Add(result); } foreach (Ice.AsyncResult <Test.Callback_Hello_sayHello> result in results) { result.waitForCompleted(); } results.Clear(); // XXX: // Take into account the retries. test(locator.getRequestCount() > count && locator.getRequestCount() < count + 1999); if (locator.getRequestCount() > count + 800) { Write("queuing = " + (locator.getRequestCount() - count)); } WriteLine("ok"); Write("testing adapter locator cache... "); Flush(); try { communicator.stringToProxy("test@TestAdapter3").ice_ping(); test(false); } catch (Ice.NotRegisteredException ex) { test(ex.kindOfObject == "object adapter"); test(ex.id.Equals("TestAdapter3")); } registry.setAdapterDirectProxy("TestAdapter3", locator.findAdapterById("TestAdapter")); try { communicator.stringToProxy("test@TestAdapter3").ice_ping(); registry.setAdapterDirectProxy("TestAdapter3", communicator.stringToProxy("dummy:tcp")); communicator.stringToProxy("test@TestAdapter3").ice_ping(); } catch (Ice.LocalException) { test(false); } try { communicator.stringToProxy("test@TestAdapter3").ice_locatorCacheTimeout(0).ice_ping(); test(false); } catch (Ice.LocalException) { } try { communicator.stringToProxy("test@TestAdapter3").ice_ping(); test(false); } catch (Ice.LocalException) { } registry.setAdapterDirectProxy("TestAdapter3", locator.findAdapterById("TestAdapter")); try { communicator.stringToProxy("test@TestAdapter3").ice_ping(); } catch (Ice.LocalException) { test(false); } WriteLine("ok"); Write("testing well-known object locator cache... "); Flush(); registry.addObject(communicator.stringToProxy("test3@TestUnknown")); try { communicator.stringToProxy("test3").ice_ping(); test(false); } catch (Ice.NotRegisteredException ex) { test(ex.kindOfObject == "object adapter"); test(ex.id.Equals("TestUnknown")); } registry.addObject(communicator.stringToProxy("test3@TestAdapter4")); // Update registry.setAdapterDirectProxy("TestAdapter4", communicator.stringToProxy("dummy:tcp")); try { communicator.stringToProxy("test3").ice_ping(); test(false); } catch (Ice.LocalException) { } registry.setAdapterDirectProxy("TestAdapter4", locator.findAdapterById("TestAdapter")); try { communicator.stringToProxy("test3").ice_ping(); } catch (Ice.LocalException) { test(false); } registry.setAdapterDirectProxy("TestAdapter4", communicator.stringToProxy("dummy:tcp")); try { communicator.stringToProxy("test3").ice_ping(); } catch (Ice.LocalException) { test(false); } try { communicator.stringToProxy("test@TestAdapter4").ice_locatorCacheTimeout(0).ice_ping(); test(false); } catch (Ice.LocalException) { } try { communicator.stringToProxy("test@TestAdapter4").ice_ping(); test(false); } catch (Ice.LocalException) { } try { communicator.stringToProxy("test3").ice_ping(); test(false); } catch (Ice.LocalException) { } registry.addObject(communicator.stringToProxy("test3@TestAdapter")); try { communicator.stringToProxy("test3").ice_ping(); } catch (Ice.LocalException) { test(false); } registry.addObject(communicator.stringToProxy("test4")); try { communicator.stringToProxy("test4").ice_ping(); test(false); } catch (Ice.NoEndpointException) { } WriteLine("ok"); Write("testing locator cache background updates... "); Flush(); { Ice.InitializationData initData = new Ice.InitializationData(); initData.properties = communicator.getProperties().ice_clone_(); initData.properties.setProperty("Ice.BackgroundLocatorCacheUpdates", "1"); Ice.Communicator ic = Ice.Util.initialize(initData); registry.setAdapterDirectProxy("TestAdapter5", locator.findAdapterById("TestAdapter")); registry.addObject(communicator.stringToProxy("test3@TestAdapter")); count = locator.getRequestCount(); ic.stringToProxy("test@TestAdapter5").ice_locatorCacheTimeout(0).ice_ping(); // No locator cache. ic.stringToProxy("test3").ice_locatorCacheTimeout(0).ice_ping(); // No locator cache. count += 3; test(count == locator.getRequestCount()); registry.setAdapterDirectProxy("TestAdapter5", null); registry.addObject(communicator.stringToProxy("test3:tcp")); ic.stringToProxy("test@TestAdapter5").ice_locatorCacheTimeout(10).ice_ping(); // 10s timeout. ic.stringToProxy("test3").ice_locatorCacheTimeout(10).ice_ping(); // 10s timeout. test(count == locator.getRequestCount()); System.Threading.Thread.Sleep(1200); // The following request should trigger the background // updates but still use the cached endpoints and // therefore succeed. ic.stringToProxy("test@TestAdapter5").ice_locatorCacheTimeout(1).ice_ping(); // 1s timeout. ic.stringToProxy("test3").ice_locatorCacheTimeout(1).ice_ping(); // 1s timeout. try { while (true) { ic.stringToProxy("test@TestAdapter5").ice_locatorCacheTimeout(1).ice_ping(); // 1s timeout. System.Threading.Thread.Sleep(10); } } catch (Ice.LocalException) { // Expected to fail once they endpoints have been updated in the background. } try { while (true) { ic.stringToProxy("test3").ice_locatorCacheTimeout(1).ice_ping(); // 1s timeout. System.Threading.Thread.Sleep(10); } } catch (Ice.LocalException) { // Expected to fail once they endpoints have been updated in the background. } ic.destroy(); } WriteLine("ok"); Write("testing proxy from server after shutdown... "); Flush(); hello = obj.getReplicatedHello(); obj.shutdown(); manager.startServer(); hello.sayHello(); WriteLine("ok"); Write("testing object migration... "); Flush(); hello = HelloPrxHelper.checkedCast(communicator.stringToProxy("hello")); obj.migrateHello(); hello.ice_getConnection().close(false); hello.sayHello(); obj.migrateHello(); hello.sayHello(); obj.migrateHello(); hello.sayHello(); WriteLine("ok"); Write("testing locator encoding resolution... "); Flush(); hello = HelloPrxHelper.checkedCast(communicator.stringToProxy("hello")); count = locator.getRequestCount(); communicator.stringToProxy("test@TestAdapter").ice_encodingVersion(Ice.Util.Encoding_1_1).ice_ping(); test(count == locator.getRequestCount()); communicator.stringToProxy("test@TestAdapter10").ice_encodingVersion(Ice.Util.Encoding_1_0).ice_ping(); test(++count == locator.getRequestCount()); communicator.stringToProxy("test -e 1.0@TestAdapter10-2").ice_ping(); test(++count == locator.getRequestCount()); WriteLine("ok"); Write("shutdown server... "); Flush(); obj.shutdown(); WriteLine("ok"); Write("testing whether server is gone... "); Flush(); try { obj2.ice_ping(); test(false); } catch (Ice.LocalException) { } try { obj3.ice_ping(); test(false); } catch (Ice.LocalException) { } try { obj5.ice_ping(); test(false); } catch (Ice.LocalException) { } WriteLine("ok"); Write("testing indirect proxies to collocated objects... "); Flush(); // // Set up test for calling a collocated object through an // indirect, adapterless reference. // Ice.Properties properties = communicator.getProperties(); properties.setProperty("Ice.PrintAdapterReady", "0"); Ice.ObjectAdapter adapter = communicator.createObjectAdapterWithEndpoints("Hello", "default"); adapter.setLocator(locator); Ice.Identity id = new Ice.Identity(); id.name = Guid.NewGuid().ToString(); registry.addObject(adapter.add(new HelloI(), id)); adapter.activate(); HelloPrx helloPrx = HelloPrxHelper.checkedCast( communicator.stringToProxy("\"" + communicator.identityToString(id) + "\"")); test(helloPrx.ice_getConnection() == null); adapter.deactivate(); WriteLine("ok"); Write("shutdown server manager... "); Flush(); manager.shutdown(); WriteLine("ok"); }
public static TestIntfPrx allTests(Ice.Communicator communicator, bool collocated) #endif { Write("testing stringToProxy... "); Flush(); String @ref = "Test:default -p 12010 -t 2000"; Ice.ObjectPrx @base = communicator.stringToProxy(@ref); test(@base != null); WriteLine("ok"); Write("testing checked cast... "); Flush(); TestIntfPrx testPrx = TestIntfPrxHelper.checkedCast(@base); test(testPrx != null); test(testPrx.Equals(@base)); WriteLine("ok"); Write("base... "); Flush(); { try { testPrx.baseAsBase(); test(false); } catch (Base b) { test(b.b.Equals("Base.b")); test(b.GetType().FullName.Equals("Test.Base")); } catch (Exception) { test(false); } } WriteLine("ok"); Write("base (AMI)... "); Flush(); { Callback cb = new Callback(); testPrx.begin_baseAsBase().whenCompleted( () => { test(false); }, (Ice.Exception ex) => { try { throw ex; } catch (Base b) { test(b.b.Equals("Base.b")); test(b.GetType().Name.Equals("Base")); } catch (Exception) { test(false); } cb.called(); }); cb.check(); } WriteLine("ok"); Write("slicing of unknown derived... "); Flush(); { try { testPrx.unknownDerivedAsBase(); test(false); } catch (Base b) { test(b.b.Equals("UnknownDerived.b")); test(b.GetType().FullName.Equals("Test.Base")); } catch (Exception) { test(false); } } WriteLine("ok"); Write("slicing of unknown derived (AMI)... "); Flush(); { Callback cb = new Callback(); testPrx.begin_unknownDerivedAsBase().whenCompleted( () => { test(false); }, (Ice.Exception ex) => { try { throw ex; } catch (Base b) { test(b.b.Equals("UnknownDerived.b")); test(b.GetType().Name.Equals("Base")); } catch (Exception) { test(false); } cb.called(); }); cb.check(); } WriteLine("ok"); Write("non-slicing of known derived as base... "); Flush(); { try { testPrx.knownDerivedAsBase(); test(false); } catch (KnownDerived k) { test(k.b.Equals("KnownDerived.b")); test(k.kd.Equals("KnownDerived.kd")); test(k.GetType().FullName.Equals("Test.KnownDerived")); } catch (Exception) { test(false); } } WriteLine("ok"); Write("non-slicing of known derived as base (AMI)... "); Flush(); { Callback cb = new Callback(); testPrx.begin_knownDerivedAsBase().whenCompleted( () => { test(false); }, (Ice.Exception ex) => { try { throw ex; } catch (KnownDerived k) { test(k.b.Equals("KnownDerived.b")); test(k.kd.Equals("KnownDerived.kd")); test(k.GetType().Name.Equals("KnownDerived")); } catch (Exception) { test(false); } cb.called(); }); cb.check(); } WriteLine("ok"); Write("non-slicing of known derived as derived... "); Flush(); { try { testPrx.knownDerivedAsKnownDerived(); test(false); } catch (KnownDerived k) { test(k.b.Equals("KnownDerived.b")); test(k.kd.Equals("KnownDerived.kd")); test(k.GetType().FullName.Equals("Test.KnownDerived")); } catch (Exception) { test(false); } } WriteLine("ok"); Write("non-slicing of known derived as derived (AMI)... "); Flush(); { Callback cb = new Callback(); testPrx.begin_knownDerivedAsKnownDerived().whenCompleted( () => { test(false); }, (Ice.Exception ex) => { try { throw ex; } catch (KnownDerived k) { test(k.b.Equals("KnownDerived.b")); test(k.kd.Equals("KnownDerived.kd")); test(k.GetType().Name.Equals("KnownDerived")); } catch (Exception) { test(false); } cb.called(); }); cb.check(); } WriteLine("ok"); Write("slicing of unknown intermediate as base... "); Flush(); { try { testPrx.unknownIntermediateAsBase(); test(false); } catch (Base b) { test(b.b.Equals("UnknownIntermediate.b")); test(b.GetType().FullName.Equals("Test.Base")); } catch (Exception) { test(false); } } WriteLine("ok"); Write("slicing of unknown intermediate as base (AMI)... "); Flush(); { Callback cb = new Callback(); testPrx.begin_unknownIntermediateAsBase().whenCompleted( () => { test(false); }, (Ice.Exception ex) => { try { throw ex; } catch (Base b) { test(b.b.Equals("UnknownIntermediate.b")); test(b.GetType().Name.Equals("Base")); } catch (Exception) { test(false); } cb.called(); }); cb.check(); } WriteLine("ok"); Write("slicing of known intermediate as base... "); Flush(); { try { testPrx.knownIntermediateAsBase(); test(false); } catch (KnownIntermediate ki) { test(ki.b.Equals("KnownIntermediate.b")); test(ki.ki.Equals("KnownIntermediate.ki")); test(ki.GetType().FullName.Equals("Test.KnownIntermediate")); } catch (Exception) { test(false); } } WriteLine("ok"); Write("slicing of known intermediate as base (AMI)... "); Flush(); { Callback cb = new Callback(); testPrx.begin_knownIntermediateAsBase().whenCompleted( () => { test(false); }, (Ice.Exception ex) => { try { throw ex; } catch (KnownIntermediate ki) { test(ki.b.Equals("KnownIntermediate.b")); test(ki.ki.Equals("KnownIntermediate.ki")); test(ki.GetType().Name.Equals("KnownIntermediate")); } catch (Exception) { test(false); } cb.called(); }); cb.check(); } WriteLine("ok"); Write("slicing of known most derived as base... "); Flush(); { try { testPrx.knownMostDerivedAsBase(); test(false); } catch (KnownMostDerived kmd) { test(kmd.b.Equals("KnownMostDerived.b")); test(kmd.ki.Equals("KnownMostDerived.ki")); test(kmd.kmd.Equals("KnownMostDerived.kmd")); test(kmd.GetType().FullName.Equals("Test.KnownMostDerived")); } catch (Exception) { test(false); } } WriteLine("ok"); Write("slicing of known most derived as base (AMI)... "); Flush(); { Callback cb = new Callback(); testPrx.begin_knownMostDerivedAsBase().whenCompleted( () => { test(false); }, (Ice.Exception ex) => { try { throw ex; } catch (KnownMostDerived kmd) { test(kmd.b.Equals("KnownMostDerived.b")); test(kmd.ki.Equals("KnownMostDerived.ki")); test(kmd.kmd.Equals("KnownMostDerived.kmd")); test(kmd.GetType().Name.Equals("KnownMostDerived")); } catch (Exception) { test(false); } cb.called(); }); cb.check(); } WriteLine("ok"); Write("non-slicing of known intermediate as intermediate... "); Flush(); { try { testPrx.knownIntermediateAsKnownIntermediate(); test(false); } catch (KnownIntermediate ki) { test(ki.b.Equals("KnownIntermediate.b")); test(ki.ki.Equals("KnownIntermediate.ki")); test(ki.GetType().FullName.Equals("Test.KnownIntermediate")); } catch (Exception) { test(false); } } WriteLine("ok"); Write("non-slicing of known intermediate as intermediate (AMI)... "); Flush(); { Callback cb = new Callback(); testPrx.begin_knownIntermediateAsKnownIntermediate().whenCompleted( () => { test(false); }, (Ice.Exception ex) => { try { throw ex; } catch (KnownIntermediate ki) { test(ki.b.Equals("KnownIntermediate.b")); test(ki.ki.Equals("KnownIntermediate.ki")); test(ki.GetType().Name.Equals("KnownIntermediate")); } catch (Exception) { test(false); } cb.called(); }); cb.check(); } WriteLine("ok"); Write("non-slicing of known most derived as intermediate... "); Flush(); { try { testPrx.knownMostDerivedAsKnownIntermediate(); test(false); } catch (KnownMostDerived kmd) { test(kmd.b.Equals("KnownMostDerived.b")); test(kmd.ki.Equals("KnownMostDerived.ki")); test(kmd.kmd.Equals("KnownMostDerived.kmd")); test(kmd.GetType().FullName.Equals("Test.KnownMostDerived")); } catch (Exception) { test(false); } } WriteLine("ok"); Write("non-slicing of known most derived as intermediate (AMI)... "); Flush(); { Callback cb = new Callback(); testPrx.begin_knownMostDerivedAsKnownIntermediate().whenCompleted( () => { test(false); }, (Ice.Exception ex) => { try { throw ex; } catch (KnownMostDerived kmd) { test(kmd.b.Equals("KnownMostDerived.b")); test(kmd.ki.Equals("KnownMostDerived.ki")); test(kmd.kmd.Equals("KnownMostDerived.kmd")); test(kmd.GetType().Name.Equals("KnownMostDerived")); } catch (Exception) { test(false); } cb.called(); }); cb.check(); } WriteLine("ok"); Write("non-slicing of known most derived as most derived... "); Flush(); { try { testPrx.knownMostDerivedAsKnownMostDerived(); test(false); } catch (KnownMostDerived kmd) { test(kmd.b.Equals("KnownMostDerived.b")); test(kmd.ki.Equals("KnownMostDerived.ki")); test(kmd.kmd.Equals("KnownMostDerived.kmd")); test(kmd.GetType().FullName.Equals("Test.KnownMostDerived")); } catch (Exception) { test(false); } } WriteLine("ok"); Write("non-slicing of known most derived as most derived (AMI)... "); Flush(); { Callback cb = new Callback(); testPrx.begin_knownMostDerivedAsKnownMostDerived().whenCompleted( () => { test(false); }, (Ice.Exception ex) => { try { throw ex; } catch (KnownMostDerived kmd) { test(kmd.b.Equals("KnownMostDerived.b")); test(kmd.ki.Equals("KnownMostDerived.ki")); test(kmd.kmd.Equals("KnownMostDerived.kmd")); test(kmd.GetType().Name.Equals("KnownMostDerived")); } catch (Exception) { test(false); } cb.called(); }); cb.check(); } WriteLine("ok"); Write("slicing of unknown most derived, known intermediate as base... "); Flush(); { try { testPrx.unknownMostDerived1AsBase(); test(false); } catch (KnownIntermediate ki) { test(ki.b.Equals("UnknownMostDerived1.b")); test(ki.ki.Equals("UnknownMostDerived1.ki")); test(ki.GetType().FullName.Equals("Test.KnownIntermediate")); } catch (Exception) { test(false); } } WriteLine("ok"); Write("slicing of unknown most derived, known intermediate as base (AMI)... "); Flush(); { Callback cb = new Callback(); testPrx.begin_unknownMostDerived1AsBase().whenCompleted( () => { test(false); }, (Ice.Exception ex) => { try { throw ex; } catch (KnownIntermediate ki) { test(ki.b.Equals("UnknownMostDerived1.b")); test(ki.ki.Equals("UnknownMostDerived1.ki")); test(ki.GetType().Name.Equals("KnownIntermediate")); } catch (Exception) { test(false); } cb.called(); }); cb.check(); } WriteLine("ok"); Write("slicing of unknown most derived, known intermediate as intermediate... "); Flush(); { try { testPrx.unknownMostDerived1AsKnownIntermediate(); test(false); } catch (KnownIntermediate ki) { test(ki.b.Equals("UnknownMostDerived1.b")); test(ki.ki.Equals("UnknownMostDerived1.ki")); test(ki.GetType().FullName.Equals("Test.KnownIntermediate")); } catch (Exception) { test(false); } } WriteLine("ok"); Write("slicing of unknown most derived, known intermediate as intermediate (AMI)... "); Flush(); { Callback cb = new Callback(); testPrx.begin_unknownMostDerived1AsKnownIntermediate().whenCompleted( () => { test(false); }, (Ice.Exception ex) => { try { throw ex; } catch (KnownIntermediate ki) { test(ki.b.Equals("UnknownMostDerived1.b")); test(ki.ki.Equals("UnknownMostDerived1.ki")); test(ki.GetType().Name.Equals("KnownIntermediate")); } catch (Exception) { test(false); } cb.called(); }); cb.check(); } WriteLine("ok"); Write("slicing of unknown most derived, unknown intermediate thrown as base... "); Flush(); { try { testPrx.unknownMostDerived2AsBase(); test(false); } catch (Base b) { test(b.b.Equals("UnknownMostDerived2.b")); test(b.GetType().FullName.Equals("Test.Base")); } catch (Exception) { test(false); } } WriteLine("ok"); Write("slicing of unknown most derived, unknown intermediate thrown as base (AMI)... "); Flush(); { Callback cb = new Callback(); testPrx.begin_unknownMostDerived2AsBase().whenCompleted( () => { test(false); }, (Ice.Exception ex) => { try { throw ex; } catch (Base b) { test(b.b.Equals("UnknownMostDerived2.b")); test(b.GetType().Name.Equals("Base")); } catch (Exception) { test(false); } cb.called(); }); cb.check(); } WriteLine("ok"); Write("unknown most derived in compact format... "); Flush(); { try { testPrx.unknownMostDerived2AsBaseCompact(); test(false); } catch (Base) { // // For the 1.0 encoding, the unknown exception is sliced to Base. // test(testPrx.ice_getEncodingVersion().Equals(Ice.Util.Encoding_1_0)); } catch (Ice.UnknownUserException) { // // A MarshalException is raised for the compact format because the // most-derived type is unknown and the exception cannot be sliced. // test(!testPrx.ice_getEncodingVersion().Equals(Ice.Util.Encoding_1_0)); } catch (Ice.OperationNotExistException) { } catch (Exception) { test(false); } } WriteLine("ok"); // // No server side in Silverlight // #if !SILVERLIGHT Write("preserved exceptions... "); Flush(); { Ice.ObjectAdapter adapter = communicator.createObjectAdapterWithEndpoints("Relay", "default"); RelayPrx relay = RelayPrxHelper.uncheckedCast(adapter.addWithUUID(new RelayI())); adapter.activate(); try { testPrx.relayKnownPreservedAsBase(relay); test(false); } catch (KnownPreservedDerived ex) { test(ex.b.Equals("base")); test(ex.kp.Equals("preserved")); test(ex.kpd.Equals("derived")); } catch (Ice.OperationNotExistException) { } catch (Exception) { test(false); } try { testPrx.relayKnownPreservedAsKnownPreserved(relay); test(false); } catch (KnownPreservedDerived ex) { test(ex.b.Equals("base")); test(ex.kp.Equals("preserved")); test(ex.kpd.Equals("derived")); } /* * catch(Exception) * { * test(false); * } */ catch (Ice.OperationNotExistException) { } catch (Exception) { test(false); } try { testPrx.relayUnknownPreservedAsBase(relay); test(false); } catch (Preserved2 ex) { test(ex.b.Equals("base")); test(ex.kp.Equals("preserved")); test(ex.kpd.Equals("derived")); test(ex.p1.ice_id().Equals(PreservedClass.ice_staticId())); PreservedClass pc = ex.p1 as PreservedClass; test(pc.bc.Equals("bc")); test(pc.pc.Equals("pc")); test(ex.p2 == ex.p1); } catch (KnownPreservedDerived ex) { // // For the 1.0 encoding, the unknown exception is sliced to KnownPreserved. // test(testPrx.ice_getEncodingVersion().Equals(Ice.Util.Encoding_1_0)); test(ex.b.Equals("base")); test(ex.kp.Equals("preserved")); test(ex.kpd.Equals("derived")); } catch (Ice.OperationNotExistException) { } catch (Exception) { test(false); } try { testPrx.relayUnknownPreservedAsKnownPreserved(relay); test(false); } catch (Preserved2 ex) { test(ex.b.Equals("base")); test(ex.kp.Equals("preserved")); test(ex.kpd.Equals("derived")); test(ex.p1.ice_id().Equals(PreservedClass.ice_staticId())); PreservedClass pc = ex.p1 as PreservedClass; test(pc.bc.Equals("bc")); test(pc.pc.Equals("pc")); test(ex.p2 == ex.p1); } catch (KnownPreservedDerived ex) { // // For the 1.0 encoding, the unknown exception is sliced to KnownPreserved. // test(testPrx.ice_getEncodingVersion().Equals(Ice.Util.Encoding_1_0)); test(ex.b.Equals("base")); test(ex.kp.Equals("preserved")); test(ex.kpd.Equals("derived")); } catch (Ice.OperationNotExistException) { } catch (Exception) { test(false); } adapter.destroy(); } WriteLine("ok"); #endif #if SILVERLIGHT testPrx.shutdown(); #else return(testPrx); #endif }
public static void allTests(TestCommon.Application app) { Ice.Communicator communicator = app.communicator(); Console.Out.Write("testing stringToProxy... "); Console.Out.Flush(); String rf = "test @ TestAdapter"; Ice.ObjectPrx @base = communicator.stringToProxy(rf); test(@base != null); Console.Out.WriteLine("ok"); Console.Out.Write("testing IceGrid.Locator is present... "); IceGrid.LocatorPrx locator = IceGrid.LocatorPrxHelper.uncheckedCast(@base); test(locator != null); Console.Out.WriteLine("ok"); Console.Out.Write("testing checked cast... "); Console.Out.Flush(); TestIntfPrx obj = TestIntfPrxHelper.checkedCast(@base); test(obj != null); test(obj.Equals(@base)); Console.Out.WriteLine("ok"); Console.Out.Write("pinging server... "); Console.Out.Flush(); obj.ice_ping(); Console.Out.WriteLine("ok"); Console.Out.Write("testing locator finder... "); Ice.Identity finderId = new Ice.Identity(); finderId.category = "Ice"; finderId.name = "LocatorFinder"; Ice.LocatorFinderPrx finder = Ice.LocatorFinderPrxHelper.checkedCast( communicator.getDefaultLocator().ice_identity(finderId)); test(finder.getLocator() != null); Console.Out.WriteLine("ok"); Console.Out.Write("testing discovery... "); { // Add test well-known object IceGrid.RegistryPrx registry = IceGrid.RegistryPrxHelper.checkedCast( communicator.stringToProxy(communicator.getDefaultLocator().ice_getIdentity().category + "/Registry")); test(registry != null); try { IceGrid.AdminSessionPrx session = registry.createAdminSession("foo", "bar"); session.getAdmin().addObjectWithType(@base, "::Test"); session.destroy(); } catch (Ice.UserException) { test(false); } // // Ensure the IceGrid discovery locator can discover the // registries and make sure locator requests are forwarded. // Ice.InitializationData initData = new Ice.InitializationData(); initData.properties = communicator.getProperties().ice_clone_(); initData.properties.setProperty("Ice.Default.Locator", ""); initData.properties.setProperty("Ice.Plugin.IceLocatorDiscovery", "IceLocatorDiscovery:IceLocatorDiscovery.PluginFactory"); initData.properties.setProperty("IceLocatorDiscovery.Port", app.getTestPort(99).ToString()); initData.properties.setProperty("AdapterForDiscoveryTest.AdapterId", "discoveryAdapter"); initData.properties.setProperty("AdapterForDiscoveryTest.Endpoints", "default"); Ice.Communicator com = Ice.Util.initialize(initData); test(com.getDefaultLocator() != null); com.stringToProxy("test @ TestAdapter").ice_ping(); com.stringToProxy("test").ice_ping(); test(com.getDefaultLocator().getRegistry() != null); test(IceGrid.LocatorPrxHelper.uncheckedCast(com.getDefaultLocator()).getLocalRegistry() != null); test(IceGrid.LocatorPrxHelper.uncheckedCast(com.getDefaultLocator()).getLocalQuery() != null); Ice.ObjectAdapter adapter = com.createObjectAdapter("AdapterForDiscoveryTest"); adapter.activate(); adapter.deactivate(); com.destroy(); // // Now, ensure that the IceGrid discovery locator correctly // handles failure to find a locator. // initData.properties.setProperty("IceLocatorDiscovery.InstanceName", "unknown"); initData.properties.setProperty("IceLocatorDiscovery.RetryCount", "1"); initData.properties.setProperty("IceLocatorDiscovery.Timeout", "100"); com = Ice.Util.initialize(initData); test(com.getDefaultLocator() != null); try { com.stringToProxy("test @ TestAdapter").ice_ping(); } catch (Ice.NoEndpointException) { } try { com.stringToProxy("test").ice_ping(); } catch (Ice.NoEndpointException) { } test(com.getDefaultLocator().getRegistry() == null); test(IceGrid.LocatorPrxHelper.checkedCast(com.getDefaultLocator()) == null); try { IceGrid.LocatorPrxHelper.uncheckedCast(com.getDefaultLocator()).getLocalRegistry(); } catch (Ice.OperationNotExistException) { } adapter = com.createObjectAdapter("AdapterForDiscoveryTest"); adapter.activate(); adapter.deactivate(); com.destroy(); string multicast; if (communicator.getProperties().getProperty("Ice.IPv6").Equals("1")) { multicast = "\"ff15::1\""; } else { multicast = "239.255.0.1"; } // // Test invalid lookup endpoints // initData.properties = communicator.getProperties().ice_clone_(); initData.properties.setProperty("Ice.Default.Locator", ""); initData.properties.setProperty("Ice.Plugin.IceLocatorDiscovery", "IceLocatorDiscovery:IceLocatorDiscovery.PluginFactory"); initData.properties.setProperty("IceLocatorDiscovery.Lookup", "udp -h " + multicast + " --interface unknown"); com = Ice.Util.initialize(initData); test(com.getDefaultLocator() != null); try { com.stringToProxy("test @ TestAdapter").ice_ping(); test(false); } catch (Ice.NoEndpointException) { } com.destroy(); initData.properties = communicator.getProperties().ice_clone_(); initData.properties.setProperty("Ice.Default.Locator", ""); initData.properties.setProperty("Ice.Plugin.IceLocatorDiscovery", "IceLocatorDiscovery:IceLocatorDiscovery.PluginFactory"); { string intf = initData.properties.getProperty("IceLocatorDiscovery.Interface"); if (!intf.Equals("")) { intf = " --interface \"" + intf + "\""; } string port = app.getTestPort(99).ToString(); initData.properties.setProperty("IceLocatorDiscovery.Lookup", "udp -h " + multicast + " --interface unknown:" + "udp -h " + multicast + " -p " + port + intf); } com = Ice.Util.initialize(initData); test(com.getDefaultLocator() != null); try { com.stringToProxy("test @ TestAdapter").ice_ping(); } catch (Ice.NoEndpointException) { test(false); } com.destroy(); } Console.Out.WriteLine("ok"); Console.Out.Write("shutting down server... "); Console.Out.Flush(); obj.shutdown(); Console.Out.WriteLine("ok"); }
public static void allTests(Test.TestHelper helper, List <int> ports) { Ice.Communicator communicator = helper.communicator(); var output = helper.getWriter(); output.Write("testing stringToProxy... "); output.Flush(); string refString = "test"; for (int i = 0; i < ports.Count; i++) { refString += ":" + helper.getTestEndpoint(ports[i]); } Ice.ObjectPrx basePrx = communicator.stringToProxy(refString); test(basePrx != null); output.WriteLine("ok"); output.Write("testing checked cast... "); output.Flush(); TestIntfPrx obj = TestIntfPrxHelper.checkedCast(basePrx); test(obj != null); test(obj.Equals(basePrx)); output.WriteLine("ok"); int oldPid = 0; bool ami = false; for (int i = 1, j = 0; i <= ports.Count; ++i, ++j) { if (j > 3) { j = 0; ami = !ami; } if (!ami) { output.Write("testing server #" + i + "... "); output.Flush(); int pid = obj.pid(); test(pid != oldPid); output.WriteLine("ok"); oldPid = pid; } else { output.Write("testing server #" + i + " with AMI... "); output.Flush(); Callback cb = new Callback(); int pid = -1; obj.begin_pid().whenCompleted( (int p) => { pid = p; cb.called(); }, (Ice.Exception ex) => { output.WriteLine(ex.ToString()); test(false); }); cb.check(); test(pid != oldPid); output.WriteLine("ok"); oldPid = pid; } if (j == 0) { if (!ami) { output.Write("shutting down server #" + i + "... "); output.Flush(); obj.shutdown(); output.WriteLine("ok"); } else { output.Write("shutting down server #" + i + " with AMI... "); Callback cb = new Callback(); obj.begin_shutdown().whenCompleted( () => { cb.called(); }, (Ice.Exception ex) => { output.WriteLine(ex.ToString()); test(false); }); cb.check(); output.WriteLine("ok"); } } else if (j == 1 || i + 1 > ports.Count) { if (!ami) { output.Write("aborting server #" + i + "... "); output.Flush(); try { obj.abort(); test(false); } catch (Ice.ConnectionLostException) { output.WriteLine("ok"); } catch (Ice.ConnectFailedException) { output.WriteLine("ok"); } catch (Ice.SocketException) { output.WriteLine("ok"); } } else { output.Write("aborting server #" + i + " with AMI... "); output.Flush(); Callback cb = new Callback(); obj.begin_abort().whenCompleted( () => { test(false); }, (Ice.Exception ex) => { exceptAbortI(ex, output); cb.called(); }); cb.check(); output.WriteLine("ok"); } } else if (j == 2 || j == 3) { if (!ami) { output.Write("aborting server #" + i + " and #" + (i + 1) + " with idempotent call... "); output.Flush(); try { obj.idempotentAbort(); test(false); } catch (Ice.ConnectionLostException) { output.WriteLine("ok"); } catch (Ice.ConnectFailedException) { output.WriteLine("ok"); } catch (Ice.SocketException) { output.WriteLine("ok"); } } else { output.Write("aborting server #" + i + " and #" + (i + 1) + " with idempotent AMI call... "); output.Flush(); Callback cb = new Callback(); obj.begin_idempotentAbort().whenCompleted( () => { test(false); }, (Ice.Exception ex) => { exceptAbortI(ex, output); cb.called(); }); cb.check(); output.WriteLine("ok"); } ++i; } else { Debug.Assert(false); } } output.Write("testing whether all servers are gone... "); output.Flush(); try { obj.ice_ping(); test(false); } catch (Ice.LocalException) { output.WriteLine("ok"); } }
public static TestIntfPrx allTests(Ice.Communicator communicator) { Write("testing stringToProxy... "); Flush(); string @ref = "test:default -p 12010"; Ice.ObjectPrx @base = communicator.stringToProxy(@ref); test(@base != null); WriteLine("ok"); Write("testing checked cast... "); Flush(); TestIntfPrx obj = TestIntfPrxHelper.checkedCast(@base); test(obj != null); test(obj.Equals(@base)); WriteLine("ok"); { Write("creating/destroying/recreating object adapter... "); Flush(); Ice.ObjectAdapter adapter = communicator.createObjectAdapterWithEndpoints("TransientTestAdapter", "default"); try { communicator.createObjectAdapterWithEndpoints("TransientTestAdapter", "default"); test(false); } catch (Ice.AlreadyRegisteredException) { } adapter.destroy(); // // Use a different port than the first adapter to avoid an "address already in use" error. // adapter = communicator.createObjectAdapterWithEndpoints("TransientTestAdapter", "default"); adapter.destroy(); Console.Out.WriteLine("ok"); } Write("creating/activating/deactivating object adapter in one operation... "); Flush(); obj.transient(); obj.end_transient(obj.begin_transient()); WriteLine("ok"); { Write("testing connection closure... "); Flush(); for (int i = 0; i < 10; ++i) { Ice.InitializationData initData = new Ice.InitializationData(); initData.properties = communicator.getProperties().ice_clone_(); Ice.Communicator comm = Ice.Util.initialize(initData); comm.stringToProxy("test:default -p 12010").begin_ice_ping(); comm.destroy(); } WriteLine("ok"); } Write("deactivating object adapter in the server... "); Flush(); obj.deactivate(); WriteLine("ok"); Write("testing whether server is gone... "); Flush(); try { obj.ice_ping(); test(false); } catch (Ice.LocalException) { WriteLine("ok"); } return(obj); }
public static void allTests(Ice.Communicator communicator, List <int> ports) #endif { #if SILVERLIGHT List <int> ports = new List <int>(); { int basePort = 12340; for (int i = 0; i < 12; i++) { ports.Add(basePort + i); } } #endif Write("testing stringToProxy... "); Flush(); string refString = "test"; for (int i = 0; i < ports.Count; i++) { refString += ":default -p " + ports[i]; } Ice.ObjectPrx basePrx = communicator.stringToProxy(refString); test(basePrx != null); WriteLine("ok"); Write("testing checked cast... "); Flush(); TestIntfPrx obj = TestIntfPrxHelper.checkedCast(basePrx); test(obj != null); test(obj.Equals(basePrx)); WriteLine("ok"); if (IceInternal.AssemblyUtil.runtime_ == IceInternal.AssemblyUtil.Runtime.Mono) { WriteLine(""); WriteLine("This test aborts a number of server processes."); WriteLine("Test output may be interspersed with \"killed\" message from the shell."); WriteLine("These messages are expected and do NOT indicate a test failure."); WriteLine(""); } int oldPid = 0; bool ami = false; for (int i = 1, j = 0; i <= ports.Count; ++i, ++j) { if (j > 3) { j = 0; ami = !ami; } if (!ami) { Write("testing server #" + i + "... "); Flush(); int pid = obj.pid(); test(pid != oldPid); WriteLine("ok"); oldPid = pid; } else { Write("testing server #" + i + " with AMI... "); Flush(); Callback cb = new Callback(); obj.begin_pid().whenCompleted(cb.opPidI, cb.exception); cb.check(); int pid = cb.pid(); test(pid != oldPid); WriteLine("ok"); oldPid = pid; } if (j == 0) { if (!ami) { Write("shutting down server #" + i + "... "); Flush(); obj.shutdown(); WriteLine("ok"); } else { Write("shutting down server #" + i + " with AMI... "); Callback cb = new Callback(); obj.begin_shutdown().whenCompleted(cb.opShutdownI, cb.exception); cb.check(); WriteLine("ok"); } } else if (j == 1 || i + 1 > ports.Count) { if (!ami) { Write("aborting server #" + i + "... "); Flush(); try { obj.abort(); test(false); } catch (Ice.ConnectionLostException) { WriteLine("ok"); } catch (Ice.ConnectFailedException) { WriteLine("ok"); } catch (Ice.SocketException) { WriteLine("ok"); } } else { Write("aborting server #" + i + " with AMI... "); Flush(); Callback cb = new Callback(); obj.begin_abort().whenCompleted(cb.response, cb.exceptAbortI); cb.check(); WriteLine("ok"); } } else if (j == 2 || j == 3) { if (!ami) { Write("aborting server #" + i + " and #" + (i + 1) + " with idempotent call... "); Flush(); try { obj.idempotentAbort(); test(false); } catch (Ice.ConnectionLostException) { WriteLine("ok"); } catch (Ice.ConnectFailedException) { WriteLine("ok"); } catch (Ice.SocketException) { WriteLine("ok"); } } else { Write("aborting server #" + i + " and #" + (i + 1) + " with idempotent AMI call... "); Flush(); Callback cb = new Callback(); obj.begin_idempotentAbort().whenCompleted(cb.response, cb.exceptAbortI); cb.check(); WriteLine("ok"); } ++i; } else { Debug.Assert(false); } } Write("testing whether all servers are gone... "); Flush(); try { obj.ice_ping(); test(false); } catch (Ice.LocalException) { WriteLine("ok"); } }
self(Ice.Current current) { return(TestIntfPrxHelper.uncheckedCast(current.adapter.createProxy(current.id))); }
allTests(Ice.Communicator communicator, int num) { List <ControllerPrx> proxies = new List <ControllerPrx>(); List <ControllerPrx> indirectProxies = new List <ControllerPrx>(); for (int i = 0; i < num; ++i) { string id = "controller" + i; proxies.Add(ControllerPrxHelper.uncheckedCast(communicator.stringToProxy(id))); indirectProxies.Add(ControllerPrxHelper.uncheckedCast(communicator.stringToProxy(id + "@control" + i))); } Console.Out.Write("testing indirect proxies... "); Console.Out.Flush(); { foreach (ControllerPrx prx in indirectProxies) { prx.ice_ping(); } } Console.Out.WriteLine("ok"); Console.Out.Write("testing well-known proxies... "); Console.Out.Flush(); { foreach (ControllerPrx prx in proxies) { prx.ice_ping(); } } Console.Out.WriteLine("ok"); Console.Out.Write("testing object adapter registration... "); Console.Out.Flush(); { try { communicator.stringToProxy("object @ oa1").ice_ping(); } catch (Ice.NoEndpointException) { } proxies[0].activateObjectAdapter("oa", "oa1", ""); try { communicator.stringToProxy("object @ oa1").ice_ping(); } catch (Ice.ObjectNotExistException) { } proxies[0].deactivateObjectAdapter("oa"); try { communicator.stringToProxy("object @ oa1").ice_ping(); } catch (Ice.NoEndpointException) { } } Console.Out.WriteLine("ok"); Console.Out.Write("testing object adapter migration..."); Console.Out.Flush(); { proxies[0].activateObjectAdapter("oa", "oa1", ""); proxies[0].addObject("oa", "object"); communicator.stringToProxy("object @ oa1").ice_ping(); proxies[0].removeObject("oa", "object"); proxies[0].deactivateObjectAdapter("oa"); proxies[1].activateObjectAdapter("oa", "oa1", ""); proxies[1].addObject("oa", "object"); communicator.stringToProxy("object @ oa1").ice_ping(); proxies[1].removeObject("oa", "object"); proxies[1].deactivateObjectAdapter("oa"); } Console.Out.WriteLine("ok"); Console.Out.Write("testing object migration..."); Console.Out.Flush(); { proxies[0].activateObjectAdapter("oa", "oa1", ""); proxies[1].activateObjectAdapter("oa", "oa2", ""); proxies[0].addObject("oa", "object"); communicator.stringToProxy("object @ oa1").ice_ping(); communicator.stringToProxy("object").ice_ping(); proxies[0].removeObject("oa", "object"); proxies[1].addObject("oa", "object"); communicator.stringToProxy("object @ oa2").ice_ping(); communicator.stringToProxy("object").ice_ping(); proxies[1].removeObject("oa", "object"); try { communicator.stringToProxy("object @ oa1").ice_ping(); } catch (Ice.ObjectNotExistException) { } try { communicator.stringToProxy("object @ oa2").ice_ping(); } catch (Ice.ObjectNotExistException) { } proxies[0].deactivateObjectAdapter("oa"); proxies[1].deactivateObjectAdapter("oa"); } Console.Out.WriteLine("ok"); Console.Out.Write("testing replica groups..."); Console.Out.Flush(); { proxies[0].activateObjectAdapter("oa", "oa1", "rg"); proxies[1].activateObjectAdapter("oa", "oa2", "rg"); proxies[2].activateObjectAdapter("oa", "oa3", "rg"); proxies[0].addObject("oa", "object"); proxies[1].addObject("oa", "object"); proxies[2].addObject("oa", "object"); communicator.stringToProxy("object @ oa1").ice_ping(); communicator.stringToProxy("object @ oa2").ice_ping(); communicator.stringToProxy("object @ oa3").ice_ping(); communicator.stringToProxy("object @ rg").ice_ping(); List <string> adapterIds = new List <string>(); adapterIds.Add("oa1"); adapterIds.Add("oa2"); adapterIds.Add("oa3"); TestIntfPrx intf = TestIntfPrxHelper.uncheckedCast(communicator.stringToProxy("object")); intf = (TestIntfPrx)intf.ice_connectionCached(false).ice_locatorCacheTimeout(0); while (adapterIds.Count > 0) { adapterIds.Remove(intf.getAdapterId()); } while (true) { adapterIds.Add("oa1"); adapterIds.Add("oa2"); adapterIds.Add("oa3"); intf = TestIntfPrxHelper.uncheckedCast( communicator.stringToProxy("object @ rg").ice_connectionCached(false)); int nRetry = 100; while (adapterIds.Count > 0 && --nRetry > 0) { adapterIds.Remove(intf.getAdapterId()); } if (nRetry > 0) { break; } // The previous locator lookup probably didn't return all the replicas... try again. communicator.stringToProxy("object @ rg").ice_locatorCacheTimeout(0).ice_ping(); } proxies[0].deactivateObjectAdapter("oa"); proxies[1].deactivateObjectAdapter("oa"); test(TestIntfPrxHelper.uncheckedCast( communicator.stringToProxy("object @ rg")).getAdapterId().Equals("oa3")); proxies[2].deactivateObjectAdapter("oa"); proxies[0].activateObjectAdapter("oa", "oa1", "rg"); proxies[0].addObject("oa", "object"); test(TestIntfPrxHelper.uncheckedCast( communicator.stringToProxy("object @ rg")).getAdapterId().Equals("oa1")); proxies[0].deactivateObjectAdapter("oa"); } Console.Out.WriteLine("ok"); Console.Out.Write("shutting down... "); Console.Out.Flush(); foreach (ControllerPrx prx in proxies) { prx.shutdown(); } Console.Out.WriteLine("ok"); }
public static TestIntfPrx allTests(TestCommon.Application app) { Ice.Communicator communicator = app.communicator(); Write("testing stringToProxy... "); Flush(); string @ref = "test:" + app.getTestEndpoint(0); Ice.ObjectPrx @base = communicator.stringToProxy(@ref); test(@base != null); WriteLine("ok"); Write("testing checked cast... "); Flush(); TestIntfPrx obj = TestIntfPrxHelper.checkedCast(@base); test(obj != null); test(obj.Equals(@base)); WriteLine("ok"); { Write("creating/destroying/recreating object adapter... "); Flush(); Ice.ObjectAdapter adapter = communicator.createObjectAdapterWithEndpoints("TransientTestAdapter", "default"); try { communicator.createObjectAdapterWithEndpoints("TransientTestAdapter", "default"); test(false); } catch (Ice.AlreadyRegisteredException) { } adapter.destroy(); // // Use a different port than the first adapter to avoid an "address already in use" error. // adapter = communicator.createObjectAdapterWithEndpoints("TransientTestAdapter", "default"); adapter.destroy(); Console.Out.WriteLine("ok"); } Write("creating/activating/deactivating object adapter in one operation... "); Flush(); obj.transient(); obj.end_transient(obj.begin_transient()); WriteLine("ok"); { Write("testing connection closure... "); Flush(); for (int i = 0; i < 10; ++i) { Ice.InitializationData initData = new Ice.InitializationData(); initData.properties = communicator.getProperties().ice_clone_(); Ice.Communicator comm = Ice.Util.initialize(initData); comm.stringToProxy("test:" + app.getTestEndpoint(0)).begin_ice_ping(); comm.destroy(); } WriteLine("ok"); } Write("testing object adapter published endpoints... "); Flush(); { communicator.getProperties().setProperty("PAdapter.PublishedEndpoints", "tcp -h localhost -p 12345 -t 30000"); Ice.ObjectAdapter adapter = communicator.createObjectAdapter("PAdapter"); test(adapter.getPublishedEndpoints().Length == 1); Ice.Endpoint endpt = adapter.getPublishedEndpoints()[0]; test(endpt.ToString().Equals("tcp -h localhost -p 12345 -t 30000")); Ice.ObjectPrx prx = communicator.stringToProxy("dummy:tcp -h localhost -p 12346 -t 20000:tcp -h localhost -p 12347 -t 10000"); adapter.setPublishedEndpoints(prx.ice_getEndpoints()); test(adapter.getPublishedEndpoints().Length == 2); Ice.Identity id = new Ice.Identity(); id.name = "dummy"; test(IceUtilInternal.Arrays.Equals(adapter.createProxy(id).ice_getEndpoints(), prx.ice_getEndpoints())); test(IceUtilInternal.Arrays.Equals(adapter.getPublishedEndpoints(), prx.ice_getEndpoints())); adapter.refreshPublishedEndpoints(); test(adapter.getPublishedEndpoints().Length == 1); test(adapter.getPublishedEndpoints()[0].Equals(endpt)); communicator.getProperties().setProperty("PAdapter.PublishedEndpoints", "tcp -h localhost -p 12345 -t 20000"); adapter.refreshPublishedEndpoints(); test(adapter.getPublishedEndpoints().Length == 1); test(adapter.getPublishedEndpoints()[0].ToString().Equals("tcp -h localhost -p 12345 -t 20000")); adapter.destroy(); test(adapter.getPublishedEndpoints().Length == 0); } WriteLine("ok"); if (obj.ice_getConnection() != null) { Write("testing object adapter with bi-dir connection... "); Flush(); Ice.ObjectAdapter adapter = communicator.createObjectAdapter(""); obj.ice_getConnection().setAdapter(adapter); obj.ice_getConnection().setAdapter(null); adapter.deactivate(); try { obj.ice_getConnection().setAdapter(adapter); test(false); } catch (Ice.ObjectAdapterDeactivatedException) { } WriteLine("ok"); } Write("testing object adapter with router... "); Flush(); { Ice.Identity routerId = new Ice.Identity(); routerId.name = "router"; Ice.RouterPrx router = Ice.RouterPrxHelper.uncheckedCast(@base.ice_identity(routerId).ice_connectionId("rc")); Ice.ObjectAdapter adapter = communicator.createObjectAdapterWithRouter("", router); test(adapter.getPublishedEndpoints().Length == 1); test(adapter.getPublishedEndpoints()[0].ToString().Equals("tcp -h localhost -p 23456 -t 30000")); adapter.refreshPublishedEndpoints(); test(adapter.getPublishedEndpoints().Length == 1); test(adapter.getPublishedEndpoints()[0].ToString().Equals("tcp -h localhost -p 23457 -t 30000")); try { adapter.setPublishedEndpoints(router.ice_getEndpoints()); test(false); } catch (ArgumentException) { // Expected. } adapter.destroy(); try { routerId.name = "test"; router = Ice.RouterPrxHelper.uncheckedCast(@base.ice_identity(routerId)); communicator.createObjectAdapterWithRouter("", router); test(false); } catch (Ice.OperationNotExistException) { // Expected: the "test" object doesn't implement Ice::Router! } try { router = Ice.RouterPrxHelper.uncheckedCast(communicator.stringToProxy("test:" + app.getTestEndpoint(1))); communicator.createObjectAdapterWithRouter("", router); test(false); } catch (Ice.ConnectFailedException) { } } WriteLine("ok"); Write("testing object adapter creation with port in use... "); Flush(); { var adapter1 = communicator.createObjectAdapterWithEndpoints("Adpt1", app.getTestEndpoint(10)); try { communicator.createObjectAdapterWithEndpoints("Adpt2", app.getTestEndpoint(10)); test(false); } catch (Ice.LocalException) { // Expected can't re-use the same endpoint. } adapter1.destroy(); } WriteLine("ok"); Write("deactivating object adapter in the server... "); Flush(); obj.deactivate(); WriteLine("ok"); Write("testing whether server is gone... "); Flush(); try { obj.ice_timeout(100).ice_ping(); // Use timeout to speed up testing on Windows test(false); } catch (Ice.LocalException) { WriteLine("ok"); } return(obj); }
allTests(Test.TestHelper helper, int num) { var output = helper.getWriter(); Ice.Communicator communicator = helper.communicator(); List <ControllerPrx> proxies = new List <ControllerPrx>(); List <ControllerPrx> indirectProxies = new List <ControllerPrx>(); for (int i = 0; i < num; ++i) { string id = "controller" + i; proxies.Add(ControllerPrxHelper.uncheckedCast(communicator.stringToProxy(id))); indirectProxies.Add(ControllerPrxHelper.uncheckedCast(communicator.stringToProxy(id + "@control" + i))); } output.Write("testing indirect proxies... "); output.Flush(); { foreach (ControllerPrx prx in indirectProxies) { prx.ice_ping(); } } output.WriteLine("ok"); output.Write("testing well-known proxies... "); output.Flush(); { foreach (ControllerPrx prx in proxies) { prx.ice_ping(); } } output.WriteLine("ok"); output.Write("testing object adapter registration... "); output.Flush(); { try { communicator.stringToProxy("object @ oa1").ice_ping(); test(false); } catch (Ice.NoEndpointException) { } proxies[0].activateObjectAdapter("oa", "oa1", ""); try { communicator.stringToProxy("object @ oa1").ice_ping(); test(false); } catch (Ice.ObjectNotExistException) { } proxies[0].deactivateObjectAdapter("oa"); try { communicator.stringToProxy("object @ oa1").ice_ping(); test(false); } catch (Ice.NoEndpointException) { } } output.WriteLine("ok"); output.Write("testing object adapter migration..."); output.Flush(); { proxies[0].activateObjectAdapter("oa", "oa1", ""); proxies[0].addObject("oa", "object"); communicator.stringToProxy("object @ oa1").ice_ping(); proxies[0].removeObject("oa", "object"); proxies[0].deactivateObjectAdapter("oa"); proxies[1].activateObjectAdapter("oa", "oa1", ""); proxies[1].addObject("oa", "object"); communicator.stringToProxy("object @ oa1").ice_ping(); proxies[1].removeObject("oa", "object"); proxies[1].deactivateObjectAdapter("oa"); } output.WriteLine("ok"); output.Write("testing object migration..."); output.Flush(); { proxies[0].activateObjectAdapter("oa", "oa1", ""); proxies[1].activateObjectAdapter("oa", "oa2", ""); proxies[0].addObject("oa", "object"); communicator.stringToProxy("object @ oa1").ice_ping(); communicator.stringToProxy("object").ice_ping(); proxies[0].removeObject("oa", "object"); proxies[1].addObject("oa", "object"); communicator.stringToProxy("object @ oa2").ice_ping(); communicator.stringToProxy("object").ice_ping(); proxies[1].removeObject("oa", "object"); try { communicator.stringToProxy("object @ oa1").ice_ping(); } catch (Ice.ObjectNotExistException) { } try { communicator.stringToProxy("object @ oa2").ice_ping(); } catch (Ice.ObjectNotExistException) { } proxies[0].deactivateObjectAdapter("oa"); proxies[1].deactivateObjectAdapter("oa"); } output.WriteLine("ok"); output.Write("testing replica groups..."); output.Flush(); { proxies[0].activateObjectAdapter("oa", "oa1", "rg"); proxies[1].activateObjectAdapter("oa", "oa2", "rg"); proxies[2].activateObjectAdapter("oa", "oa3", "rg"); proxies[0].addObject("oa", "object"); proxies[1].addObject("oa", "object"); proxies[2].addObject("oa", "object"); communicator.stringToProxy("object @ oa1").ice_ping(); communicator.stringToProxy("object @ oa2").ice_ping(); communicator.stringToProxy("object @ oa3").ice_ping(); communicator.stringToProxy("object @ rg").ice_ping(); List <string> adapterIds = new List <string>(); adapterIds.Add("oa1"); adapterIds.Add("oa2"); adapterIds.Add("oa3"); TestIntfPrx intf = TestIntfPrxHelper.uncheckedCast(communicator.stringToProxy("object")); intf = (TestIntfPrx)intf.ice_connectionCached(false).ice_locatorCacheTimeout(0); while (adapterIds.Count > 0) { adapterIds.Remove(intf.getAdapterId()); } while (true) { adapterIds.Add("oa1"); adapterIds.Add("oa2"); adapterIds.Add("oa3"); intf = TestIntfPrxHelper.uncheckedCast( communicator.stringToProxy("object @ rg").ice_connectionCached(false)); int nRetry = 100; while (adapterIds.Count > 0 && --nRetry > 0) { adapterIds.Remove(intf.getAdapterId()); } if (nRetry > 0) { break; } // The previous locator lookup probably didn't return all the replicas... try again. communicator.stringToProxy("object @ rg").ice_locatorCacheTimeout(0).ice_ping(); } proxies[0].deactivateObjectAdapter("oa"); proxies[1].deactivateObjectAdapter("oa"); test(TestIntfPrxHelper.uncheckedCast( communicator.stringToProxy("object @ rg")).getAdapterId().Equals("oa3")); proxies[2].deactivateObjectAdapter("oa"); proxies[0].activateObjectAdapter("oa", "oa1", "rg"); proxies[0].addObject("oa", "object"); test(TestIntfPrxHelper.uncheckedCast( communicator.stringToProxy("object @ rg")).getAdapterId().Equals("oa1")); proxies[0].deactivateObjectAdapter("oa"); } output.WriteLine("ok"); output.Write("testing invalid lookup endpoints... "); output.Flush(); { String multicast; if (communicator.getProperties().getProperty("Ice.IPv6").Equals("1")) { multicast = "\"ff15::1\""; } else { multicast = "239.255.0.1"; } { Ice.InitializationData initData = new Ice.InitializationData(); initData.properties = communicator.getProperties().ice_clone_(); initData.properties.setProperty("IceDiscovery.Lookup", "udp -h " + multicast + " --interface unknown"); Ice.Communicator comm = Ice.Util.initialize(initData); test(comm.getDefaultLocator() != null); try { comm.stringToProxy("controller0@control0").ice_ping(); test(false); } catch (Ice.LocalException) { } comm.destroy(); } { Ice.InitializationData initData = new Ice.InitializationData(); initData.properties = communicator.getProperties().ice_clone_(); string intf = initData.properties.getProperty("IceDiscovery.Interface"); if (!intf.Equals("")) { intf = " --interface \"" + intf + "\""; } string port = initData.properties.getProperty("IceDiscovery.Port"); initData.properties.setProperty("IceDiscovery.Lookup", "udp -h " + multicast + " --interface unknown:" + "udp -h " + multicast + " -p " + port + intf); Ice.Communicator comm = Ice.Util.initialize(initData); test(comm.getDefaultLocator() != null); comm.stringToProxy("controller0@control0").ice_ping(); comm.destroy(); } } output.WriteLine("ok"); output.Write("shutting down... "); output.Flush(); foreach (ControllerPrx prx in proxies) { prx.shutdown(); } output.WriteLine("ok"); }
public static TestIntfPrx allTests(Ice.Communicator communicator) #endif { string sref = "test:default -p 12010"; Ice.ObjectPrx obj = communicator.stringToProxy(sref); test(obj != null); TestIntfPrx proxy = TestIntfPrxHelper.uncheckedCast(obj); test(proxy != null); Console.Out.Write("testing enum values... "); Console.Out.Flush(); test((int)ByteEnum.benum1 == 0); test((int)ByteEnum.benum2 == 1); test((int)ByteEnum.benum3 == ByteConst1.value); test((int)ByteEnum.benum4 == ByteConst1.value + 1); test((int)ByteEnum.benum5 == ShortConst1.value); test((int)ByteEnum.benum6 == ShortConst1.value + 1); test((int)ByteEnum.benum7 == IntConst1.value); test((int)ByteEnum.benum8 == IntConst1.value + 1); test((int)ByteEnum.benum9 == LongConst1.value); test((int)ByteEnum.benum10 == LongConst1.value + 1); test((int)ByteEnum.benum11 == ByteConst2.value); test((int)ShortEnum.senum1 == 3); test((int)ShortEnum.senum2 == 4); test((int)ShortEnum.senum3 == ByteConst1.value); test((int)ShortEnum.senum4 == ByteConst1.value + 1); test((int)ShortEnum.senum5 == ShortConst1.value); test((int)ShortEnum.senum6 == ShortConst1.value + 1); test((int)ShortEnum.senum7 == IntConst1.value); test((int)ShortEnum.senum8 == IntConst1.value + 1); test((int)ShortEnum.senum9 == LongConst1.value); test((int)ShortEnum.senum10 == LongConst1.value + 1); test((int)ShortEnum.senum11 == ShortConst2.value); test((int)IntEnum.ienum1 == 0); test((int)IntEnum.ienum2 == 1); test((int)IntEnum.ienum3 == ByteConst1.value); test((int)IntEnum.ienum4 == ByteConst1.value + 1); test((int)IntEnum.ienum5 == ShortConst1.value); test((int)IntEnum.ienum6 == ShortConst1.value + 1); test((int)IntEnum.ienum7 == IntConst1.value); test((int)IntEnum.ienum8 == IntConst1.value + 1); test((int)IntEnum.ienum9 == LongConst1.value); test((int)IntEnum.ienum10 == LongConst1.value + 1); test((int)IntEnum.ienum11 == IntConst2.value); test((int)IntEnum.ienum12 == LongConst2.value); test((int)SimpleEnum.red == 0); test((int)SimpleEnum.green == 1); test((int)SimpleEnum.blue == 2); Console.Out.WriteLine("ok"); Console.Out.Write("testing enum streaming... "); Console.Out.Flush(); Ice.OutputStream ostr; byte[] bytes; bool encoding_1_0 = communicator.getProperties().getProperty("Ice.Default.EncodingVersion").Equals("1.0"); ostr = new Ice.OutputStream(communicator); ostr.writeEnum((int)ByteEnum.benum11, (int)ByteEnum.benum11); bytes = ostr.finished(); test(bytes.Length == 1); // ByteEnum should require one byte ostr = new Ice.OutputStream(communicator); ostr.writeEnum((int)ShortEnum.senum11, (int)ShortEnum.senum11); bytes = ostr.finished(); test(bytes.Length == (encoding_1_0 ? 2 : 5)); ostr = new Ice.OutputStream(communicator); ostr.writeEnum((int)IntEnum.ienum11, (int)IntEnum.ienum12); bytes = ostr.finished(); test(bytes.Length == (encoding_1_0 ? 4 : 5)); ostr = new Ice.OutputStream(communicator); ostr.writeEnum((int)SimpleEnum.blue, (int)SimpleEnum.blue); bytes = ostr.finished(); test(bytes.Length == 1); // SimpleEnum should require one byte Console.Out.WriteLine("ok"); Console.Out.Write("testing enum operations... "); Console.Out.Flush(); ByteEnum byteEnum; test(proxy.opByte(ByteEnum.benum1, out byteEnum) == ByteEnum.benum1); test(byteEnum == ByteEnum.benum1); test(proxy.opByte(ByteEnum.benum11, out byteEnum) == ByteEnum.benum11); test(byteEnum == ByteEnum.benum11); ShortEnum shortEnum; test(proxy.opShort(ShortEnum.senum1, out shortEnum) == ShortEnum.senum1); test(shortEnum == ShortEnum.senum1); test(proxy.opShort(ShortEnum.senum11, out shortEnum) == ShortEnum.senum11); test(shortEnum == ShortEnum.senum11); IntEnum intEnum; test(proxy.opInt(IntEnum.ienum1, out intEnum) == IntEnum.ienum1); test(intEnum == IntEnum.ienum1); test(proxy.opInt(IntEnum.ienum11, out intEnum) == IntEnum.ienum11); test(intEnum == IntEnum.ienum11); test(proxy.opInt(IntEnum.ienum12, out intEnum) == IntEnum.ienum12); test(intEnum == IntEnum.ienum12); SimpleEnum s; test(proxy.opSimple(SimpleEnum.green, out s) == SimpleEnum.green); test(s == SimpleEnum.green); Console.Out.WriteLine("ok"); Console.Out.Write("testing enum sequences operations... "); Console.Out.Flush(); { ByteEnum[] b1 = new ByteEnum[11] { ByteEnum.benum1, ByteEnum.benum2, ByteEnum.benum3, ByteEnum.benum4, ByteEnum.benum5, ByteEnum.benum6, ByteEnum.benum7, ByteEnum.benum8, ByteEnum.benum9, ByteEnum.benum10, ByteEnum.benum11 }; ByteEnum[] b2; ByteEnum[] b3 = proxy.opByteSeq(b1, out b2); for (int i = 0; i < b1.Length; ++i) { test(b1[i] == b2[i]); test(b1[i] == b3[i]); } } { ShortEnum[] s1 = new ShortEnum[11] { ShortEnum.senum1, ShortEnum.senum2, ShortEnum.senum3, ShortEnum.senum4, ShortEnum.senum5, ShortEnum.senum6, ShortEnum.senum7, ShortEnum.senum8, ShortEnum.senum9, ShortEnum.senum10, ShortEnum.senum11 }; ShortEnum[] s2; ShortEnum[] s3 = proxy.opShortSeq(s1, out s2); for (int i = 0; i < s1.Length; ++i) { test(s1[i] == s2[i]); test(s1[i] == s3[i]); } } { IntEnum[] i1 = new IntEnum[11] { IntEnum.ienum1, IntEnum.ienum2, IntEnum.ienum3, IntEnum.ienum4, IntEnum.ienum5, IntEnum.ienum6, IntEnum.ienum7, IntEnum.ienum8, IntEnum.ienum9, IntEnum.ienum10, IntEnum.ienum11 }; IntEnum[] i2; IntEnum[] i3 = proxy.opIntSeq(i1, out i2); for (int i = 0; i < i1.Length; ++i) { test(i1[i] == i2[i]); test(i1[i] == i3[i]); } } { SimpleEnum[] s1 = new SimpleEnum[3] { SimpleEnum.red, SimpleEnum.green, SimpleEnum.blue }; SimpleEnum[] s2; SimpleEnum[] s3 = proxy.opSimpleSeq(s1, out s2); for (int i = 0; i < s1.Length; ++i) { test(s1[i] == s2[i]); test(s1[i] == s3[i]); } } Console.Out.WriteLine("ok"); #if SILVERLIGHT proxy.shutdown(); #else return(proxy); #endif }
opWithResult(Ice.AsyncResult result) { test(result.AsyncState == _cookie); test(TestIntfPrxHelper.uncheckedCast(result.getProxy()).end_opWithResult(result) == 15); called(); }