コード例 #1
0
        public static ITestIntfPrx allTests(TestHelper helper)
        {
            Communicator?communicator = helper.Communicator();

            TestHelper.Assert(communicator != null);
            var output = helper.GetWriter();

            output.Write("testing stringToProxy... ");
            output.Flush();
            ITestIntfPrx testPrx = ITestIntfPrx.Parse($"Test:{helper.GetTestEndpoint(0)} -t 2000", communicator);

            output.WriteLine("ok");

            output.Write("base... ");
            output.Flush();
            {
                try
                {
                    testPrx.baseAsBase();
                    TestHelper.Assert(false);
                }
                catch (Base b)
                {
                    TestHelper.Assert(b.b.Equals("Base.b"));
                    TestHelper.Assert(b.GetType().FullName !.Equals("ZeroC.Ice.Test.Slicing.Exceptions.Base"));
                }
                catch (Exception)
                {
                    TestHelper.Assert(false);
                }
            }
            output.WriteLine("ok");

            output.Write("base (AMI)... ");
            output.Flush();
            {
                try
                {
                    testPrx.baseAsBaseAsync().Wait();
                    TestHelper.Assert(false);
                }
                catch (AggregateException ae)
                {
                    try
                    {
                        TestHelper.Assert(ae.InnerException != null);
                        throw ae.InnerException;
                    }
                    catch (Base b)
                    {
                        TestHelper.Assert(b.b.Equals("Base.b"));
                        TestHelper.Assert(b.GetType().Name.Equals("Base"));
                    }
                    catch (Exception)
                    {
                        TestHelper.Assert(false);
                    }
                }
            }
            output.WriteLine("ok");

            output.Write("slicing of unknown derived... ");
            output.Flush();
            {
                try
                {
                    testPrx.unknownDerivedAsBase();
                    TestHelper.Assert(false);
                }
                catch (Base b)
                {
                    TestHelper.Assert(b.b.Equals("UnknownDerived.b"));
                    TestHelper.Assert(b.GetType().FullName !.Equals("ZeroC.Ice.Test.Slicing.Exceptions.Base"));
                }
                catch (System.Exception)
                {
                    TestHelper.Assert(false);
                }
            }
            output.WriteLine("ok");

            output.Write("slicing of unknown derived (AMI)... ");
            output.Flush();
            {
                try
                {
                    testPrx.unknownDerivedAsBaseAsync().Wait();
                    TestHelper.Assert(false);
                }
                catch (AggregateException ae)
                {
                    try
                    {
                        TestHelper.Assert(ae.InnerException != null);
                        throw ae.InnerException;
                    }
                    catch (Base b)
                    {
                        TestHelper.Assert(b.b.Equals("UnknownDerived.b"));
                        TestHelper.Assert(b.GetType().Name.Equals("Base"));
                    }
                    catch (Exception)
                    {
                        TestHelper.Assert(false);
                    }
                }
            }
            output.WriteLine("ok");

            output.Write("non-slicing of known derived as base... ");
            output.Flush();
            {
                try
                {
                    testPrx.knownDerivedAsBase();
                    TestHelper.Assert(false);
                }
                catch (KnownDerived k)
                {
                    TestHelper.Assert(k.b.Equals("KnownDerived.b"));
                    TestHelper.Assert(k.kd.Equals("KnownDerived.kd"));
                    TestHelper.Assert(k.GetType().FullName !.Equals("ZeroC.Ice.Test.Slicing.Exceptions.KnownDerived"));
                }
                catch (System.Exception)
                {
                    TestHelper.Assert(false);
                }
            }
            output.WriteLine("ok");

            output.Write("non-slicing of known derived as base (AMI)... ");
            output.Flush();
            {
                try
                {
                    testPrx.knownDerivedAsBaseAsync().Wait();
                    TestHelper.Assert(false);
                }
                catch (AggregateException ae)
                {
                    try
                    {
                        TestHelper.Assert(ae.InnerException != null);
                        throw ae.InnerException;
                    }
                    catch (KnownDerived k)
                    {
                        TestHelper.Assert(k.b.Equals("KnownDerived.b"));
                        TestHelper.Assert(k.kd.Equals("KnownDerived.kd"));
                        TestHelper.Assert(k.GetType().Name.Equals("KnownDerived"));
                    }
                    catch (Exception)
                    {
                        TestHelper.Assert(false);
                    }
                }
            }
            output.WriteLine("ok");

            output.Write("non-slicing of known derived as derived... ");
            output.Flush();
            {
                try
                {
                    testPrx.knownDerivedAsKnownDerived();
                    TestHelper.Assert(false);
                }
                catch (KnownDerived k)
                {
                    TestHelper.Assert(k.b.Equals("KnownDerived.b"));
                    TestHelper.Assert(k.kd.Equals("KnownDerived.kd"));
                    TestHelper.Assert(k.GetType().FullName !.Equals("ZeroC.Ice.Test.Slicing.Exceptions.KnownDerived"));
                }
                catch (System.Exception)
                {
                    TestHelper.Assert(false);
                }
            }
            output.WriteLine("ok");

            output.Write("non-slicing of known derived as derived (AMI)... ");
            output.Flush();
            {
                try
                {
                    testPrx.knownDerivedAsKnownDerivedAsync().Wait();
                    TestHelper.Assert(false);
                }
                catch (AggregateException ae)
                {
                    try
                    {
                        TestHelper.Assert(ae.InnerException != null);
                        throw ae.InnerException;
                    }
                    catch (KnownDerived k)
                    {
                        TestHelper.Assert(k.b.Equals("KnownDerived.b"));
                        TestHelper.Assert(k.kd.Equals("KnownDerived.kd"));
                        TestHelper.Assert(k.GetType().Name.Equals("KnownDerived"));
                    }
                    catch (Exception)
                    {
                        TestHelper.Assert(false);
                    }
                }
            }
            output.WriteLine("ok");

            output.Write("slicing of unknown intermediate as base... ");
            output.Flush();
            {
                try
                {
                    testPrx.unknownIntermediateAsBase();
                    TestHelper.Assert(false);
                }
                catch (Base b)
                {
                    TestHelper.Assert(b.b.Equals("UnknownIntermediate.b"));
                    TestHelper.Assert(b.GetType().FullName !.Equals("ZeroC.Ice.Test.Slicing.Exceptions.Base"));
                }
                catch (Exception)
                {
                    TestHelper.Assert(false);
                }
            }
            output.WriteLine("ok");

            output.Write("slicing of unknown intermediate as base (AMI)... ");
            output.Flush();
            {
                try
                {
                    testPrx.unknownIntermediateAsBaseAsync().Wait();
                    TestHelper.Assert(false);
                }
                catch (AggregateException ae)
                {
                    try
                    {
                        TestHelper.Assert(ae.InnerException != null);
                        throw ae.InnerException;
                    }
                    catch (Base b)
                    {
                        TestHelper.Assert(b.b.Equals("UnknownIntermediate.b"));
                        TestHelper.Assert(b.GetType().Name.Equals("Base"));
                    }
                    catch (Exception)
                    {
                        TestHelper.Assert(false);
                    }
                }
            }
            output.WriteLine("ok");

            output.Write("slicing of known intermediate as base... ");
            output.Flush();
            {
                try
                {
                    testPrx.knownIntermediateAsBase();
                    TestHelper.Assert(false);
                }
                catch (KnownIntermediate ki)
                {
                    TestHelper.Assert(ki.b.Equals("KnownIntermediate.b"));
                    TestHelper.Assert(ki.ki.Equals("KnownIntermediate.ki"));
                    TestHelper.Assert(ki.GetType().FullName !.Equals("ZeroC.Ice.Test.Slicing.Exceptions.KnownIntermediate"));
                }
                catch (Exception)
                {
                    TestHelper.Assert(false);
                }
            }
            output.WriteLine("ok");

            output.Write("slicing of known intermediate as base (AMI)... ");
            output.Flush();
            {
                try
                {
                    testPrx.knownIntermediateAsBaseAsync().Wait();
                    TestHelper.Assert(false);
                }
                catch (AggregateException ae)
                {
                    try
                    {
                        TestHelper.Assert(ae.InnerException != null);
                        throw ae.InnerException;
                    }
                    catch (KnownIntermediate ki)
                    {
                        TestHelper.Assert(ki.b.Equals("KnownIntermediate.b"));
                        TestHelper.Assert(ki.ki.Equals("KnownIntermediate.ki"));
                        TestHelper.Assert(ki.GetType().Name.Equals("KnownIntermediate"));
                    }
                    catch (Exception)
                    {
                        TestHelper.Assert(false);
                    }
                }
            }
            output.WriteLine("ok");

            output.Write("slicing of known most derived as base... ");
            output.Flush();
            {
                try
                {
                    testPrx.knownMostDerivedAsBase();
                    TestHelper.Assert(false);
                }
                catch (KnownMostDerived kmd)
                {
                    TestHelper.Assert(kmd.b.Equals("KnownMostDerived.b"));
                    TestHelper.Assert(kmd.ki.Equals("KnownMostDerived.ki"));
                    TestHelper.Assert(kmd.kmd.Equals("KnownMostDerived.kmd"));
                    TestHelper.Assert(kmd.GetType().FullName !.Equals("ZeroC.Ice.Test.Slicing.Exceptions.KnownMostDerived"));
                }
                catch (Exception)
                {
                    TestHelper.Assert(false);
                }
            }
            output.WriteLine("ok");

            output.Write("slicing of known most derived as base (AMI)... ");
            output.Flush();
            {
                try
                {
                    testPrx.knownMostDerivedAsBaseAsync().Wait();
                    TestHelper.Assert(false);
                }
                catch (AggregateException ae)
                {
                    try
                    {
                        TestHelper.Assert(ae.InnerException != null);
                        throw ae.InnerException;
                    }
                    catch (KnownMostDerived kmd)
                    {
                        TestHelper.Assert(kmd.b.Equals("KnownMostDerived.b"));
                        TestHelper.Assert(kmd.ki.Equals("KnownMostDerived.ki"));
                        TestHelper.Assert(kmd.kmd.Equals("KnownMostDerived.kmd"));
                        TestHelper.Assert(kmd.GetType().Name.Equals("KnownMostDerived"));
                    }
                    catch (Exception)
                    {
                        TestHelper.Assert(false);
                    }
                }
            }
            output.WriteLine("ok");

            output.Write("non-slicing of known intermediate as intermediate... ");
            output.Flush();
            {
                try
                {
                    testPrx.knownIntermediateAsKnownIntermediate();
                    TestHelper.Assert(false);
                }
                catch (KnownIntermediate ki)
                {
                    TestHelper.Assert(ki.b.Equals("KnownIntermediate.b"));
                    TestHelper.Assert(ki.ki.Equals("KnownIntermediate.ki"));
                    TestHelper.Assert(ki.GetType().FullName !.Equals("ZeroC.Ice.Test.Slicing.Exceptions.KnownIntermediate"));
                }
                catch (Exception)
                {
                    TestHelper.Assert(false);
                }
            }
            output.WriteLine("ok");

            output.Write("non-slicing of known intermediate as intermediate (AMI)... ");
            output.Flush();
            {
                try
                {
                    testPrx.knownIntermediateAsKnownIntermediateAsync().Wait();
                    TestHelper.Assert(false);
                }
                catch (AggregateException ae)
                {
                    try
                    {
                        TestHelper.Assert(ae.InnerException != null);
                        throw ae.InnerException;
                    }
                    catch (KnownIntermediate ki)
                    {
                        TestHelper.Assert(ki.b.Equals("KnownIntermediate.b"));
                        TestHelper.Assert(ki.ki.Equals("KnownIntermediate.ki"));
                        TestHelper.Assert(ki.GetType().Name.Equals("KnownIntermediate"));
                    }
                    catch (Exception)
                    {
                        TestHelper.Assert(false);
                    }
                }
            }
            output.WriteLine("ok");

            output.Write("non-slicing of known most derived as intermediate... ");
            output.Flush();
            {
                try
                {
                    testPrx.knownMostDerivedAsKnownIntermediate();
                    TestHelper.Assert(false);
                }
                catch (KnownMostDerived kmd)
                {
                    TestHelper.Assert(kmd.b.Equals("KnownMostDerived.b"));
                    TestHelper.Assert(kmd.ki.Equals("KnownMostDerived.ki"));
                    TestHelper.Assert(kmd.kmd.Equals("KnownMostDerived.kmd"));
                    TestHelper.Assert(kmd.GetType().FullName !.Equals("ZeroC.Ice.Test.Slicing.Exceptions.KnownMostDerived"));
                }
                catch (Exception)
                {
                    TestHelper.Assert(false);
                }
            }
            output.WriteLine("ok");

            output.Write("non-slicing of known most derived as intermediate (AMI)... ");
            output.Flush();
            {
                try
                {
                    testPrx.knownMostDerivedAsKnownIntermediateAsync().Wait();
                    TestHelper.Assert(false);
                }
                catch (AggregateException ae)
                {
                    try
                    {
                        TestHelper.Assert(ae.InnerException != null);
                        throw ae.InnerException;
                    }
                    catch (KnownMostDerived kmd)
                    {
                        TestHelper.Assert(kmd.b.Equals("KnownMostDerived.b"));
                        TestHelper.Assert(kmd.ki.Equals("KnownMostDerived.ki"));
                        TestHelper.Assert(kmd.kmd.Equals("KnownMostDerived.kmd"));
                        TestHelper.Assert(kmd.GetType().Name.Equals("KnownMostDerived"));
                    }
                    catch (Exception)
                    {
                        TestHelper.Assert(false);
                    }
                }
            }
            output.WriteLine("ok");

            output.Write("non-slicing of known most derived as most derived... ");
            output.Flush();
            {
                try
                {
                    testPrx.knownMostDerivedAsKnownMostDerived();
                    TestHelper.Assert(false);
                }
                catch (KnownMostDerived kmd)
                {
                    TestHelper.Assert(kmd.b.Equals("KnownMostDerived.b"));
                    TestHelper.Assert(kmd.ki.Equals("KnownMostDerived.ki"));
                    TestHelper.Assert(kmd.kmd.Equals("KnownMostDerived.kmd"));
                    TestHelper.Assert(kmd.GetType().FullName !.Equals("ZeroC.Ice.Test.Slicing.Exceptions.KnownMostDerived"));
                }
                catch (Exception)
                {
                    TestHelper.Assert(false);
                }
            }
            output.WriteLine("ok");

            output.Write("non-slicing of known most derived as most derived (AMI)... ");
            output.Flush();
            {
                try
                {
                    testPrx.knownMostDerivedAsKnownMostDerivedAsync().Wait();
                    TestHelper.Assert(false);
                }
                catch (AggregateException ae)
                {
                    try
                    {
                        TestHelper.Assert(ae.InnerException != null);
                        throw ae.InnerException;
                    }
                    catch (KnownMostDerived kmd)
                    {
                        TestHelper.Assert(kmd.b.Equals("KnownMostDerived.b"));
                        TestHelper.Assert(kmd.ki.Equals("KnownMostDerived.ki"));
                        TestHelper.Assert(kmd.kmd.Equals("KnownMostDerived.kmd"));
                        TestHelper.Assert(kmd.GetType().Name.Equals("KnownMostDerived"));
                    }
                    catch (Exception)
                    {
                        TestHelper.Assert(false);
                    }
                }
            }
            output.WriteLine("ok");

            output.Write("slicing of unknown most derived, known intermediate as base... ");
            output.Flush();
            {
                try
                {
                    testPrx.unknownMostDerived1AsBase();
                    TestHelper.Assert(false);
                }
                catch (KnownIntermediate ki)
                {
                    TestHelper.Assert(ki.b.Equals("UnknownMostDerived1.b"));
                    TestHelper.Assert(ki.ki.Equals("UnknownMostDerived1.ki"));
                    TestHelper.Assert(ki.GetType().FullName !.Equals("ZeroC.Ice.Test.Slicing.Exceptions.KnownIntermediate"));
                }
                catch (Exception)
                {
                    TestHelper.Assert(false);
                }
            }
            output.WriteLine("ok");

            output.Write("slicing of unknown most derived, known intermediate as base (AMI)... ");
            output.Flush();
            {
                try
                {
                    testPrx.unknownMostDerived1AsBaseAsync().Wait();
                    TestHelper.Assert(false);
                }
                catch (AggregateException ae)
                {
                    try
                    {
                        TestHelper.Assert(ae.InnerException != null);
                        throw ae.InnerException;
                    }
                    catch (KnownIntermediate ki)
                    {
                        TestHelper.Assert(ki.b.Equals("UnknownMostDerived1.b"));
                        TestHelper.Assert(ki.ki.Equals("UnknownMostDerived1.ki"));
                        TestHelper.Assert(ki.GetType().Name.Equals("KnownIntermediate"));
                    }
                    catch (Exception)
                    {
                        TestHelper.Assert(false);
                    }
                }
            }
            output.WriteLine("ok");

            output.Write("slicing of unknown most derived, known intermediate as intermediate... ");
            output.Flush();
            {
                try
                {
                    testPrx.unknownMostDerived1AsKnownIntermediate();
                    TestHelper.Assert(false);
                }
                catch (KnownIntermediate ki)
                {
                    TestHelper.Assert(ki.b.Equals("UnknownMostDerived1.b"));
                    TestHelper.Assert(ki.ki.Equals("UnknownMostDerived1.ki"));
                    TestHelper.Assert(ki.GetType().FullName !.Equals("ZeroC.Ice.Test.Slicing.Exceptions.KnownIntermediate"));
                }
                catch (Exception)
                {
                    TestHelper.Assert(false);
                }
            }
            output.WriteLine("ok");

            output.Write("slicing of unknown most derived, known intermediate as intermediate (AMI)... ");
            output.Flush();
            {
                try
                {
                    testPrx.unknownMostDerived1AsKnownIntermediateAsync().Wait();
                    TestHelper.Assert(false);
                }
                catch (AggregateException ae)
                {
                    try
                    {
                        TestHelper.Assert(ae.InnerException != null);
                        throw ae.InnerException;
                    }
                    catch (KnownIntermediate ki)
                    {
                        TestHelper.Assert(ki.b.Equals("UnknownMostDerived1.b"));
                        TestHelper.Assert(ki.ki.Equals("UnknownMostDerived1.ki"));
                        TestHelper.Assert(ki.GetType().Name.Equals("KnownIntermediate"));
                    }
                    catch (Exception)
                    {
                        TestHelper.Assert(false);
                    }
                }
            }
            output.WriteLine("ok");

            output.Write("slicing of unknown most derived, unknown intermediate thrown as base... ");
            output.Flush();
            {
                try
                {
                    testPrx.unknownMostDerived2AsBase();
                    TestHelper.Assert(false);
                }
                catch (Base b)
                {
                    TestHelper.Assert(b.b.Equals("UnknownMostDerived2.b"));
                    TestHelper.Assert(b.GetType().FullName !.Equals("ZeroC.Ice.Test.Slicing.Exceptions.Base"));
                }
                catch (Exception)
                {
                    TestHelper.Assert(false);
                }
            }
            output.WriteLine("ok");

            output.Write("slicing of unknown most derived, unknown intermediate thrown as base (AMI)... ");
            output.Flush();
            {
                try
                {
                    testPrx.unknownMostDerived2AsBaseAsync().Wait();
                    TestHelper.Assert(false);
                }
                catch (AggregateException ae)
                {
                    try
                    {
                        TestHelper.Assert(ae.InnerException != null);
                        throw ae.InnerException;
                    }
                    catch (Base b)
                    {
                        TestHelper.Assert(b.b.Equals("UnknownMostDerived2.b"));
                        TestHelper.Assert(b.GetType().Name.Equals("Base"));
                    }
                    catch (Exception)
                    {
                        TestHelper.Assert(false);
                    }
                }
            }
            output.WriteLine("ok");

            output.Write("unknown most derived in compact format... ");
            output.Flush();
            {
                try
                {
                    testPrx.unknownMostDerived2AsBaseCompact();
                    TestHelper.Assert(false);
                }
                catch (Base)
                {
                    // Exceptions are always marshaled in sliced format; format:compact applies only to in-parameters and
                    // return values.
                }
                catch (OperationNotExistException)
                {
                }
                catch (Exception)
                {
                    TestHelper.Assert(false);
                }
            }
            output.WriteLine("ok");

            output.Write("completely unknown server-private exception... ");
            output.Flush();
            {
                try
                {
                    testPrx.serverPrivateException();
                    TestHelper.Assert(false);
                }
                catch (RemoteException ex)
                {
                    SlicedData slicedData = ex.GetSlicedData() !.Value;
                    TestHelper.Assert(slicedData.Slices.Count == 1);
                    TestHelper.Assert(slicedData.Slices[0].TypeId ! == "::Slicing::Exceptions::ServerPrivateException");
                }
                catch (Exception)
                {
                    TestHelper.Assert(false);
                }
            }
            output.WriteLine("ok");

            output.Write("preserved exceptions... ");
            output.Flush();
            {
                try
                {
                    testPrx.unknownPreservedAsBase();
                    TestHelper.Assert(false);
                }
                catch (Base ex)
                {
                    IReadOnlyList <SliceInfo> slices = ex.GetSlicedData() !.Value.Slices;
                    TestHelper.Assert(slices.Count == 2);
                    TestHelper.Assert(slices[1].TypeId !.Equals("::Slicing::Exceptions::SPreserved1"));
                    TestHelper.Assert(slices[0].TypeId !.Equals("::Slicing::Exceptions::SPreserved2"));
                }

                try
                {
                    testPrx.unknownPreservedAsKnownPreserved();
                    TestHelper.Assert(false);
                }
                catch (KnownPreserved ex)
                {
                    TestHelper.Assert(ex.kp.Equals("preserved"));
                    IReadOnlyList <SliceInfo> slices = ex.GetSlicedData() !.Value.Slices;
                    TestHelper.Assert(slices.Count == 2);
                    TestHelper.Assert(slices[1].TypeId !.Equals("::Slicing::Exceptions::SPreserved1"));
                    TestHelper.Assert(slices[0].TypeId !.Equals("::Slicing::Exceptions::SPreserved2"));
                }

                ObjectAdapter adapter = communicator.CreateObjectAdapter();
                IRelayPrx     relay   = adapter.AddWithUUID(new Relay(), IRelayPrx.Factory);
                adapter.Activate();
                testPrx.GetConnection().Adapter = adapter;

                try
                {
                    testPrx.relayKnownPreservedAsBase(relay);
                    TestHelper.Assert(false);
                }
                catch (KnownPreservedDerived ex)
                {
                    TestHelper.Assert(ex.b.Equals("base"));
                    TestHelper.Assert(ex.kp.Equals("preserved"));
                    TestHelper.Assert(ex.kpd.Equals("derived"));
                }
                catch (OperationNotExistException)
                {
                }
                catch (System.Exception)
                {
                    TestHelper.Assert(false);
                }

                try
                {
                    testPrx.relayKnownPreservedAsKnownPreserved(relay);
                    TestHelper.Assert(false);
                }
                catch (KnownPreservedDerived ex)
                {
                    TestHelper.Assert(ex.b.Equals("base"));
                    TestHelper.Assert(ex.kp.Equals("preserved"));
                    TestHelper.Assert(ex.kpd.Equals("derived"));
                }
                catch (OperationNotExistException)
                {
                }
                catch (System.Exception)
                {
                    TestHelper.Assert(false);
                }

                try
                {
                    testPrx.relayUnknownPreservedAsBase(relay);
                    TestHelper.Assert(false);
                }
                catch (Preserved2 ex)
                {
                    TestHelper.Assert(ex.b.Equals("base"));
                    TestHelper.Assert(ex.kp.Equals("preserved"));
                    TestHelper.Assert(ex.kpd.Equals("derived"));
                    TestHelper.Assert(ex.p1 !.GetType().GetIceTypeId() !.Equals(typeof(PreservedClass).GetIceTypeId()));
                    var pc = ex.p1 as PreservedClass;
                    TestHelper.Assert(pc !.bc.Equals("bc"));
                    TestHelper.Assert(pc !.pc.Equals("pc"));
                    TestHelper.Assert(ex.p2 == ex.p1);
                }
                catch (OperationNotExistException)
                {
                }
                catch (Exception)
                {
                    TestHelper.Assert(false);
                }

                try
                {
                    testPrx.relayUnknownPreservedAsKnownPreserved(relay);
                    TestHelper.Assert(false);
                }
                catch (Preserved2 ex)
                {
                    TestHelper.Assert(ex.b.Equals("base"));
                    TestHelper.Assert(ex.kp.Equals("preserved"));
                    TestHelper.Assert(ex.kpd.Equals("derived"));
                    TestHelper.Assert(ex.p1 !.GetType().GetIceTypeId() !.Equals(typeof(PreservedClass).GetIceTypeId()));
                    var pc = ex.p1 as PreservedClass;
                    TestHelper.Assert(pc !.bc.Equals("bc"));
                    TestHelper.Assert(pc !.pc.Equals("pc"));
                    TestHelper.Assert(ex.p2 == ex.p1);
                }
                catch (OperationNotExistException)
                {
                }
                catch (Exception)
                {
                    TestHelper.Assert(false);
                }

                try
                {
                    testPrx.relayClientPrivateException(relay);
                    TestHelper.Assert(false);
                }
                catch (ClientPrivateException ex)
                {
                    TestHelper.Assert(ex.cpe == "ClientPrivate");
                }
                catch (System.Exception)
                {
                    TestHelper.Assert(false);
                }

                adapter.Destroy();
            }
            output.WriteLine("ok");

            return(testPrx);
        }
コード例 #2
0
ファイル: AllTests.cs プロジェクト: tchernobog/ice
    public static ITestIntfPrx allTests(Test.TestHelper helper, bool collocated)
    {
        Communicator communicator = helper.communicator();
        var          output       = helper.getWriter();

        output.Write("testing stringToProxy... ");
        output.Flush();
        string @ref  = "Test:" + helper.getTestEndpoint(0) + " -t 2000";
        var    @base = IObjectPrx.Parse(@ref, communicator);

        test(@base != null);
        output.WriteLine("ok");

        output.Write("testing checked cast... ");
        output.Flush();
        ITestIntfPrx testPrx = ITestIntfPrx.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 (System.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 (System.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 (System.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 (System.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 (System.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 (System.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 (System.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 (System.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 (System.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 (System.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 (System.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 (System.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 (System.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 (System.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 (System.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 (System.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 (System.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 (System.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 (System.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 (System.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 (System.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 (System.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 (System.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 (System.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 (System.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 (System.Exception)
                {
                    test(false);
                }
            }
        }
        output.WriteLine("ok");

        output.Write("unknown most derived in compact format... ");
        output.Flush();
        {
            try
            {
                testPrx.unknownMostDerived2AsBaseCompact();
                test(false);
            }
            catch (Base)
            {
                test(false);
            }
            catch (Ice.UnknownUserException)
            {
                //
                // A MarshalException is raised for the compact format because the
                // most-derived type is unknown and the exception cannot be sliced.
                //
            }
            catch (Ice.OperationNotExistException)
            {
            }
            catch (System.Exception)
            {
                test(false);
            }
        }
        output.WriteLine("ok");

        output.Write("preserved exceptions... ");
        output.Flush();
        {
            try
            {
                testPrx.unknownPreservedAsBase();
                test(false);
            }
            catch (Base ex)
            {
                IReadOnlyList <Ice.SliceInfo> slices = ex.GetSlicedData().Value.Slices;
                test(slices.Count == 2);
                test(slices[1].TypeId.Equals("::Test::SPreserved1"));
                test(slices[0].TypeId.Equals("::Test::SPreserved2"));
            }

            try
            {
                testPrx.unknownPreservedAsKnownPreserved();
                test(false);
            }
            catch (KnownPreserved ex)
            {
                test(ex.kp.Equals("preserved"));
                IReadOnlyList <Ice.SliceInfo> slices = ex.GetSlicedData().Value.Slices;
                test(slices.Count == 2);
                test(slices[1].TypeId.Equals("::Test::SPreserved1"));
                test(slices[0].TypeId.Equals("::Test::SPreserved2"));
            }

            ObjectAdapter adapter = communicator.CreateObjectAdapter("");
            IRelayPrx     relay   = adapter.Add(new Relay(), IRelayPrx.Factory);
            adapter.Activate();
            testPrx.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 (System.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 (System.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.GetType().GetIceTypeId().Equals(typeof(PreservedClass).GetIceTypeId()));
                PreservedClass pc = ex.p1 as PreservedClass;
                test(pc.bc.Equals("bc"));
                test(pc.pc.Equals("pc"));
                test(ex.p2 == ex.p1);
            }
            catch (Ice.OperationNotExistException)
            {
            }
            catch (System.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.GetType().GetIceTypeId().Equals(typeof(PreservedClass).GetIceTypeId()));
                PreservedClass pc = ex.p1 as PreservedClass;
                test(pc.bc.Equals("bc"));
                test(pc.pc.Equals("pc"));
                test(ex.p2 == ex.p1);
            }
            catch (Ice.OperationNotExistException)
            {
            }
            catch (System.Exception)
            {
                test(false);
            }

            adapter.Destroy();
        }
        output.WriteLine("ok");

        return(testPrx);
    }