Example #1
0
    public static GPrx allTests(Ice.Communicator communicator)
#endif
    {
        
        Write("testing Ice.Admin.Facets property... ");
        test(communicator.getProperties().getPropertyAsList("Ice.Admin.Facets").Length == 0);
        communicator.getProperties().setProperty("Ice.Admin.Facets", "foobar");
        String[] facetFilter = communicator.getProperties().getPropertyAsList("Ice.Admin.Facets");
        test(facetFilter.Length == 1 && facetFilter[0].Equals("foobar"));
        communicator.getProperties().setProperty("Ice.Admin.Facets", "foo\\'bar");
        facetFilter = communicator.getProperties().getPropertyAsList("Ice.Admin.Facets");
        test(facetFilter.Length == 1 && facetFilter[0].Equals("foo'bar"));
        communicator.getProperties().setProperty("Ice.Admin.Facets", "'foo bar' toto 'titi'");
        facetFilter = communicator.getProperties().getPropertyAsList("Ice.Admin.Facets");
        test(facetFilter.Length == 3 && facetFilter[0].Equals("foo bar") && facetFilter[1].Equals("toto")
             && facetFilter[2].Equals("titi"));
        communicator.getProperties().setProperty("Ice.Admin.Facets", "'foo bar\\' toto' 'titi'");
        facetFilter = communicator.getProperties().getPropertyAsList("Ice.Admin.Facets");
        test(facetFilter.Length == 2 && facetFilter[0].Equals("foo bar' toto") && facetFilter[1].Equals("titi"));
        //  communicator.getProperties().setProperty("Ice.Admin.Facets", "'foo bar' 'toto titi");
        // facetFilter = communicator.getProperties().getPropertyAsList("Ice.Admin.Facets");
        // test(facetFilter.Length == 0);
        communicator.getProperties().setProperty("Ice.Admin.Facets", "");
        WriteLine("ok");

#if !SILVERLIGHT
        Write("testing facet registration exceptions... ");
        communicator.getProperties().setProperty("FacetExceptionTestAdapter.Endpoints", "default");
        Ice.ObjectAdapter adapter = communicator.createObjectAdapter("FacetExceptionTestAdapter");
        Ice.Object obj = new EmptyI();
        adapter.add(obj, communicator.stringToIdentity("d"));
        adapter.addFacet(obj, communicator.stringToIdentity("d"), "facetABCD");
        try
        {
            adapter.addFacet(obj, communicator.stringToIdentity("d"), "facetABCD");
            test(false);
        }
        catch(Ice.AlreadyRegisteredException)
        {
        }
        adapter.removeFacet(communicator.stringToIdentity("d"), "facetABCD");
        try
        {
            adapter.removeFacet(communicator.stringToIdentity("d"), "facetABCD");
            test(false);
        }
        catch(Ice.NotRegisteredException)
        {
        }
        WriteLine("ok");

        Write("testing removeAllFacets... ");
        Ice.Object obj1 = new EmptyI();
        Ice.Object obj2 = new EmptyI();
        adapter.addFacet(obj1, communicator.stringToIdentity("id1"), "f1");
        adapter.addFacet(obj2, communicator.stringToIdentity("id1"), "f2");
        Ice.Object obj3 = new EmptyI();
        adapter.addFacet(obj1, communicator.stringToIdentity("id2"), "f1");
        adapter.addFacet(obj2, communicator.stringToIdentity("id2"), "f2");
        adapter.addFacet(obj3, communicator.stringToIdentity("id2"), "");
        Dictionary<string, Ice.Object> fm
            = adapter.removeAllFacets(communicator.stringToIdentity("id1"));
        test(fm.Count == 2);
        test(fm["f1"] == obj1);
        test(fm["f2"] == obj2);
        try
        {
            adapter.removeAllFacets(communicator.stringToIdentity("id1"));
            test(false);
        }
        catch(Ice.NotRegisteredException)
        {
        }
        fm = adapter.removeAllFacets(communicator.stringToIdentity("id2"));
        test(fm.Count == 3);
        test(fm["f1"] == obj1);
        test(fm["f2"] == obj2);
        test(fm[""] == obj3);
        WriteLine("ok");

        adapter.deactivate();
#endif
        Write("testing stringToProxy... ");
        Flush();
        string @ref = "d:default -p 12010";
        Ice.ObjectPrx db = communicator.stringToProxy(@ref);
        test(db != null);
        WriteLine("ok");

        Write("testing unchecked cast... ");
        Flush();
        Ice.ObjectPrx prx = Ice.ObjectPrxHelper.uncheckedCast(db);
        test(prx.ice_getFacet().Length == 0);
        prx = Ice.ObjectPrxHelper.uncheckedCast(db, "facetABCD");
        test(prx.ice_getFacet() == "facetABCD");
        Ice.ObjectPrx prx2 = Ice.ObjectPrxHelper.uncheckedCast(prx);
        test(prx2.ice_getFacet() == "facetABCD");
        Ice.ObjectPrx prx3 = Ice.ObjectPrxHelper.uncheckedCast(prx, "");
        test(prx3.ice_getFacet().Length == 0);
        DPrx d = Test.DPrxHelper.uncheckedCast(db);
        test(d.ice_getFacet().Length == 0);
        DPrx df = Test.DPrxHelper.uncheckedCast(db, "facetABCD");
        test(df.ice_getFacet() == "facetABCD");
        DPrx df2 = Test.DPrxHelper.uncheckedCast(df);
        test(df2.ice_getFacet() == "facetABCD");
        DPrx df3 = Test.DPrxHelper.uncheckedCast(df, "");
        test(df3.ice_getFacet().Length == 0);
        WriteLine("ok");

        Write("testing checked cast... ");
        Flush();
        prx = Ice.ObjectPrxHelper.checkedCast(db);
        test(prx.ice_getFacet().Length == 0);
        prx = Ice.ObjectPrxHelper.checkedCast(db, "facetABCD");
        test(prx.ice_getFacet() == "facetABCD");
        prx2 = Ice.ObjectPrxHelper.checkedCast(prx);
        test(prx2.ice_getFacet() == "facetABCD");
        prx3 = Ice.ObjectPrxHelper.checkedCast(prx, "");
        test(prx3.ice_getFacet().Length == 0);
        d = Test.DPrxHelper.checkedCast(db);
        test(d.ice_getFacet().Length == 0);
        df = Test.DPrxHelper.checkedCast(db, "facetABCD");
        test(df.ice_getFacet() == "facetABCD");
        df2 = Test.DPrxHelper.checkedCast(df);
        test(df2.ice_getFacet() == "facetABCD");
        df3 = Test.DPrxHelper.checkedCast(df, "");
        test(df3.ice_getFacet().Length == 0);
        WriteLine("ok");

        Write("testing non-facets A, B, C, and D... ");
        Flush();
        d = DPrxHelper.checkedCast(db);
        test(d != null);
        test(d.Equals(db));
        test(d.callA().Equals("A"));
        test(d.callB().Equals("B"));
        test(d.callC().Equals("C"));
        test(d.callD().Equals("D"));
        WriteLine("ok");
     
        Write("testing facets A, B, C, and D... ");
        Flush();
        df = DPrxHelper.checkedCast(d, "facetABCD");
        test(df != null);
        test(df.callA().Equals("A"));
        test(df.callB().Equals("B"));
        test(df.callC().Equals("C"));
        test(df.callD().Equals("D"));
        WriteLine("ok");
        
        Write("testing facets E and F... ");
        Flush();
        FPrx ff = FPrxHelper.checkedCast(d, "facetEF");
        test(ff != null);
        test(ff.callE().Equals("E"));
        test(ff.callF().Equals("F"));
        WriteLine("ok");
        
        Write("testing facet G... ");
        Flush();
        GPrx gf = GPrxHelper.checkedCast(ff, "facetGH");
        test(gf != null);
        test(gf.callG().Equals("G"));
        WriteLine("ok");
        
        Write("testing whether casting preserves the facet... ");
        Flush();
        HPrx hf = HPrxHelper.checkedCast(gf);
        test(hf != null);
        test(hf.callG().Equals("G"));
        test(hf.callH().Equals("H"));
        WriteLine("ok");
        
#if SILVERLIGHT
        gf.shutdown();
#else
        return gf;
#endif
    }
Example #2
0
    public static ThrowerPrx allTests(Ice.Communicator communicator)
#endif
    {
#if SILVERLIGHT
        WriteLine("Ice.FactoryAssemblies: " + communicator.getProperties().getProperty("Ice.FactoryAssemblies"));
#endif

#if !SILVERLIGHT
        {
            Write("testing object adapter registration exceptions... ");
            Ice.ObjectAdapter first;
            try
            {
                first = communicator.createObjectAdapter("TestAdapter0");
            }
            catch (Ice.InitializationException)
            {
                // Expected
            }

            communicator.getProperties().setProperty("TestAdapter0.Endpoints", "default");
            first = communicator.createObjectAdapter("TestAdapter0");
            try
            {
                communicator.createObjectAdapter("TestAdapter0");
                test(false);
            }
            catch (Ice.AlreadyRegisteredException)
            {
                // Expected.
            }

            try
            {
                Ice.ObjectAdapter second =
                    communicator.createObjectAdapterWithEndpoints("TestAdapter0", "ssl -h foo -p 12011");
                test(false);

                //
                // Quell mono error that variable second isn't used.
                //
                second.deactivate();
            }
            catch (Ice.AlreadyRegisteredException)
            {
                // Expected
            }
            first.deactivate();
            WriteLine("ok");
        }

        {
            Write("testing servant registration exceptions... ");
            communicator.getProperties().setProperty("TestAdapter1.Endpoints", "default");
            Ice.ObjectAdapter adapter = communicator.createObjectAdapter("TestAdapter1");
            Ice.Object        obj     = new EmptyI();
            adapter.add(obj, communicator.stringToIdentity("x"));
            try
            {
                adapter.add(obj, communicator.stringToIdentity("x"));
                test(false);
            }
            catch (Ice.AlreadyRegisteredException)
            {
            }

            try
            {
                adapter.add(obj, communicator.stringToIdentity(""));
                test(false);
            }
            catch (Ice.IllegalIdentityException e)
            {
                test(e.id.name.Equals(""));
            }

            try
            {
                adapter.add(null, communicator.stringToIdentity("x"));
                test(false);
            }
            catch (Ice.IllegalServantException)
            {
            }

            adapter.remove(communicator.stringToIdentity("x"));
            try
            {
                adapter.remove(communicator.stringToIdentity("x"));
                test(false);
            }
            catch (Ice.NotRegisteredException)
            {
            }
            adapter.deactivate();
            WriteLine("ok");
        }

        {
            Write("testing servant locator registration exceptions... ");
            communicator.getProperties().setProperty("TestAdapter2.Endpoints", "default");
            Ice.ObjectAdapter  adapter = communicator.createObjectAdapter("TestAdapter2");
            Ice.ServantLocator loc     = new ServantLocatorI();
            adapter.addServantLocator(loc, "x");
            try
            {
                adapter.addServantLocator(loc, "x");
                test(false);
            }
            catch (Ice.AlreadyRegisteredException)
            {
            }

            adapter.deactivate();
            WriteLine("ok");
        }
#endif
        {
            Write("testing object factory registration exception... ");
            communicator.addValueFactory(_ => { return(null); }, "::x");
            try
            {
                communicator.addValueFactory(_ => { return(null); }, "::x");
                test(false);
            }
            catch (Ice.AlreadyRegisteredException)
            {
            }
            WriteLine("ok");
        }

        Write("testing stringToProxy... ");
        Flush();
        String        @ref  = "thrower:default -p 12010";
        Ice.ObjectPrx @base = communicator.stringToProxy(@ref);
        test(@base != null);
        WriteLine("ok");

        Write("testing checked cast... ");
        Flush();
        ThrowerPrx thrower = ThrowerPrxHelper.checkedCast(@base);

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

        Write("catching exact types... ");
        Flush();

        try
        {
            thrower.throwAasA(1);
            test(false);
        }
        catch (A ex)
        {
            test(ex.aMem == 1);
        }
        catch (Exception)
        {
            test(false);
        }

        try
        {
            thrower.throwAorDasAorD(1);
            test(false);
        }
        catch (A ex)
        {
            test(ex.aMem == 1);
        }
        catch (Exception)
        {
            test(false);
        }

        try
        {
            thrower.throwAorDasAorD(-1);
            test(false);
        }
        catch (D ex)
        {
            test(ex.dMem == -1);
        }
        catch (Exception)
        {
            test(false);
        }

        try
        {
            thrower.throwBasB(1, 2);
            test(false);
        }
        catch (B ex)
        {
            test(ex.aMem == 1);
            test(ex.bMem == 2);
        }
        catch (Exception)
        {
            test(false);
        }

        try
        {
            thrower.throwCasC(1, 2, 3);
            test(false);
        }
        catch (C ex)
        {
            test(ex.aMem == 1);
            test(ex.bMem == 2);
            test(ex.cMem == 3);
        }
        catch (Exception)
        {
            test(false);
        }

        WriteLine("ok");

        Write("catching base types... ");
        Flush();

        try
        {
            thrower.throwBasB(1, 2);
            test(false);
        }
        catch (A ex)
        {
            test(ex.aMem == 1);
        }
        catch (Exception)
        {
            test(false);
        }

        try
        {
            thrower.throwCasC(1, 2, 3);
            test(false);
        }
        catch (B ex)
        {
            test(ex.aMem == 1);
            test(ex.bMem == 2);
        }
        catch (Exception)
        {
            test(false);
        }

        WriteLine("ok");

        Write("catching derived types... ");
        Flush();

        try
        {
            thrower.throwBasA(1, 2);
            test(false);
        }
        catch (B ex)
        {
            test(ex.aMem == 1);
            test(ex.bMem == 2);
        }
        catch (Exception)
        {
            test(false);
        }

        try
        {
            thrower.throwCasA(1, 2, 3);
            test(false);
        }
        catch (C ex)
        {
            test(ex.aMem == 1);
            test(ex.bMem == 2);
            test(ex.cMem == 3);
        }
        catch (Exception)
        {
            test(false);
        }

        try
        {
            thrower.throwCasB(1, 2, 3);
            test(false);
        }
        catch (C ex)
        {
            test(ex.aMem == 1);
            test(ex.bMem == 2);
            test(ex.cMem == 3);
        }
        catch (Exception)
        {
            test(false);
        }

        WriteLine("ok");

        if (thrower.supportsUndeclaredExceptions())
        {
            Write("catching unknown user exception... ");
            Flush();

            try
            {
                thrower.throwUndeclaredA(1);
                test(false);
            }
            catch (Ice.UnknownUserException)
            {
            }
            catch (Exception)
            {
                test(false);
            }

            try
            {
                thrower.throwUndeclaredB(1, 2);
                test(false);
            }
            catch (Ice.UnknownUserException)
            {
            }
            catch (Exception)
            {
                test(false);
            }

            try
            {
                thrower.throwUndeclaredC(1, 2, 3);
                test(false);
            }
            catch (Ice.UnknownUserException)
            {
            }
            catch (Exception)
            {
                test(false);
            }

            WriteLine("ok");
        }

        if (thrower.ice_getConnection() != null)
        {
            Write("testing memory limit marshal exception...");
            Flush();
            try
            {
                thrower.throwMemoryLimitException(null);
                test(false);
            }
            catch (Ice.MemoryLimitException)
            {
            }
            catch (Exception)
            {
                test(false);
            }

            try
            {
                thrower.throwMemoryLimitException(new byte[20 * 1024]); // 20KB
                test(false);
            }
            catch (Ice.ConnectionLostException)
            {
            }
            catch (Exception)
            {
                test(false);
            }

            ThrowerPrx thrower2 = ThrowerPrxHelper.uncheckedCast(
                communicator.stringToProxy("thrower:default -p 12011"));
            try
            {
                thrower2.throwMemoryLimitException(new byte[2 * 1024 * 1024]); // 2MB (no limits)
            }
            catch (Ice.MemoryLimitException)
            {
            }
            ThrowerPrx thrower3 = ThrowerPrxHelper.uncheckedCast(
                communicator.stringToProxy("thrower:default -p 12012"));
            try
            {
                thrower3.throwMemoryLimitException(new byte[1024]); // 1KB limit
                test(false);
            }
            catch (Ice.ConnectionLostException)
            {
            }

            WriteLine("ok");
        }

        Write("catching object not exist exception... ");
        Flush();

        {
            Ice.Identity id = communicator.stringToIdentity("does not exist");
            try
            {
                ThrowerPrx thrower2 = ThrowerPrxHelper.uncheckedCast(thrower.ice_identity(id));
                thrower2.ice_ping();
                test(false);
            }
            catch (Ice.ObjectNotExistException ex)
            {
                test(ex.id.Equals(id));
            }
            catch (Exception)
            {
                test(false);
            }
        }

        WriteLine("ok");

        Write("catching facet not exist exception... ");
        Flush();

        try
        {
            ThrowerPrx thrower2 = ThrowerPrxHelper.uncheckedCast(thrower, "no such facet");
            try
            {
                thrower2.ice_ping();
                test(false);
            }
            catch (Ice.FacetNotExistException ex)
            {
                test(ex.facet.Equals("no such facet"));
            }
        }
        catch (Exception)
        {
            test(false);
        }

        WriteLine("ok");

        Write("catching operation not exist exception... ");
        Flush();

        try
        {
            WrongOperationPrx thrower2 = WrongOperationPrxHelper.uncheckedCast(thrower);
            thrower2.noSuchOperation();
            test(false);
        }
        catch (Ice.OperationNotExistException ex)
        {
            test(ex.operation.Equals("noSuchOperation"));
        }
        catch (Exception)
        {
            test(false);
        }

        WriteLine("ok");

        Write("catching unknown local exception... ");
        Flush();

        try
        {
            thrower.throwLocalException();
            test(false);
        }
        catch (Ice.UnknownLocalException)
        {
        }
        catch (Exception)
        {
            test(false);
        }
        try
        {
            thrower.throwLocalExceptionIdempotent();
            test(false);
        }
        catch (Ice.UnknownLocalException)
        {
        }
        catch (Ice.OperationNotExistException)
        {
        }
        catch (Exception)
        {
            test(false);
        }

        WriteLine("ok");

        Write("catching unknown non-Ice exception... ");
        Flush();

        try
        {
            thrower.throwNonIceException();
            test(false);
        }
        catch (Ice.UnknownException)
        {
        }
        catch (System.Exception)
        {
            test(false);
        }

        WriteLine("ok");

        Write("testing asynchronous exceptions... ");
        Flush();

        try
        {
            thrower.throwAfterResponse();
        }
        catch (Exception)
        {
            test(false);
        }

        try
        {
            thrower.throwAfterException();
            test(false);
        }
        catch (A)
        {
        }
        catch (Exception)
        {
            test(false);
        }

        WriteLine("ok");

        Write("catching exact types with AMI mapping... ");
        Flush();

        {
            Callback cb = new Callback();
            thrower.begin_throwAasA(1).whenCompleted(
                () =>
            {
                test(false);
            },
                (Ice.Exception exc) =>
            {
                test(exc is A);
                A ex = exc as A;
                test(ex.aMem == 1);
                cb.called();
            });
            cb.check();
        }

        {
            Callback cb = new Callback();
            thrower.begin_throwAorDasAorD(1).whenCompleted(
                () =>
            {
                test(false);
            },
                (Ice.Exception exc) =>
            {
                try
                {
                    throw exc;
                }
                catch (A ex)
                {
                    test(ex.aMem == 1);
                }
                catch (D ex)
                {
                    test(ex.dMem == -1);
                }
                catch (Exception)
                {
                    test(false);
                }
                cb.called();
            });
            cb.check();
        }

        {
            Callback cb = new Callback();
            thrower.begin_throwAorDasAorD(-1).whenCompleted(
                () =>
            {
                test(false);
            },
                (Ice.Exception exc) =>
            {
                try
                {
                    throw exc;
                }
                catch (A ex)
                {
                    test(ex.aMem == 1);
                }
                catch (D ex)
                {
                    test(ex.dMem == -1);
                }
                catch (Exception)
                {
                    test(false);
                }
                cb.called();
            });
            cb.check();
        }

        {
            Callback cb = new Callback();
            thrower.begin_throwBasB(1, 2).whenCompleted(
                () =>
            {
                test(false);
            },
                (Ice.Exception exc) =>
            {
                try
                {
                    throw exc;
                }
                catch (B ex)
                {
                    test(ex.aMem == 1);
                    test(ex.bMem == 2);
                }
                catch (Exception)
                {
                    test(false);
                }
                cb.called();
            });
            cb.check();
        }

        {
            Callback cb = new Callback();
            thrower.begin_throwCasC(1, 2, 3).whenCompleted(
                () =>
            {
                test(false);
            },
                (Ice.Exception exc) =>
            {
                try
                {
                    throw exc;
                }
                catch (C ex)
                {
                    test(ex.aMem == 1);
                    test(ex.bMem == 2);
                    test(ex.cMem == 3);
                }
                catch (Exception)
                {
                    test(false);
                }
                cb.called();
            });
            cb.check();
        }

        WriteLine("ok");

        Write("catching derived types with new AMI mapping... ");
        Flush();

        {
            Callback cb = new Callback();
            thrower.begin_throwBasA(1, 2).whenCompleted(
                () =>
            {
                test(false);
            },
                (Ice.Exception exc) =>
            {
                try
                {
                    throw exc;
                }
                catch (B ex)
                {
                    test(ex.aMem == 1);
                    test(ex.bMem == 2);
                }
                catch (Exception)
                {
                    test(false);
                }
                cb.called();
            });
            cb.check();
        }

        {
            Callback cb = new Callback();
            thrower.begin_throwCasA(1, 2, 3).whenCompleted(
                () =>
            {
                test(false);
            },
                (Ice.Exception exc) =>
            {
                try
                {
                    throw exc;
                }
                catch (C ex)
                {
                    test(ex.aMem == 1);
                    test(ex.bMem == 2);
                    test(ex.cMem == 3);
                }
                catch (Exception)
                {
                    test(false);
                }
                cb.called();
            });
            cb.check();
        }

        {
            Callback cb = new Callback();
            thrower.begin_throwCasB(1, 2, 3).whenCompleted(
                () =>
            {
                test(false);
            },
                (Ice.Exception exc) =>
            {
                try
                {
                    throw exc;
                }
                catch (C ex)
                {
                    test(ex.aMem == 1);
                    test(ex.bMem == 2);
                    test(ex.cMem == 3);
                }
                catch (Exception)
                {
                    test(false);
                }
                cb.called();
            });
            cb.check();
        }

        WriteLine("ok");

        if (thrower.supportsUndeclaredExceptions())
        {
            Write("catching unknown user exception with new AMI mapping... ");
            Flush();

            {
                Callback cb = new Callback();
                thrower.begin_throwUndeclaredA(1).whenCompleted(
                    () =>
                {
                    test(false);
                },
                    (Ice.Exception exc) =>
                {
                    try
                    {
                        throw exc;
                    }
                    catch (Ice.UnknownUserException)
                    {
                    }
                    catch (Exception)
                    {
                        test(false);
                    }
                    cb.called();
                });
                cb.check();
            }

            {
                Callback cb = new Callback();
                thrower.begin_throwUndeclaredB(1, 2).whenCompleted(
                    () =>
                {
                    test(false);
                },
                    (Ice.Exception exc) =>
                {
                    try
                    {
                        throw exc;
                    }
                    catch (Ice.UnknownUserException)
                    {
                    }
                    catch (Exception)
                    {
                        test(false);
                    }
                    cb.called();
                });
                cb.check();
            }

            {
                Callback cb = new Callback();
                thrower.begin_throwUndeclaredC(1, 2, 3).whenCompleted(
                    () =>
                {
                    test(false);
                },
                    (Ice.Exception exc) =>
                {
                    try
                    {
                        throw exc;
                    }
                    catch (Ice.UnknownUserException)
                    {
                    }
                    catch (Exception)
                    {
                        test(false);
                    }
                    cb.called();
                });
                cb.check();
            }

            WriteLine("ok");
        }

        Write("catching object not exist exception with new AMI mapping... ");
        Flush();

        {
            Ice.Identity id       = communicator.stringToIdentity("does not exist");
            ThrowerPrx   thrower2 = ThrowerPrxHelper.uncheckedCast(thrower.ice_identity(id));
            Callback     cb       = new Callback();
            thrower2.begin_throwAasA(1).whenCompleted(
                () =>
            {
                test(false);
            },
                (Ice.Exception exc) =>
            {
                try
                {
                    throw exc;
                }
                catch (Ice.ObjectNotExistException ex)
                {
                    test(ex.id.Equals(id));
                }
                catch (Exception)
                {
                    test(false);
                }
                cb.called();
            });
            cb.check();
        }

        WriteLine("ok");

        Write("catching facet not exist exception with new AMI mapping... ");
        Flush();

        {
            ThrowerPrx thrower2 = ThrowerPrxHelper.uncheckedCast(thrower, "no such facet");
            Callback   cb       = new Callback();
            thrower2.begin_throwAasA(1).whenCompleted(
                () =>
            {
                test(false);
            },
                (Ice.Exception exc) =>
            {
                try
                {
                    throw exc;
                }
                catch (Ice.FacetNotExistException ex)
                {
                    test(ex.facet.Equals("no such facet"));
                }
                catch (Exception)
                {
                    test(false);
                }
                cb.called();
            });
            cb.check();
        }

        WriteLine("ok");

        Write("catching operation not exist exception with new AMI mapping... ");
        Flush();

        {
            Callback          cb       = new Callback();
            WrongOperationPrx thrower4 = WrongOperationPrxHelper.uncheckedCast(thrower);
            thrower4.begin_noSuchOperation().whenCompleted(
                () =>
            {
                test(false);
            },
                (Ice.Exception exc) =>
            {
                try
                {
                    throw exc;
                }
                catch (Ice.OperationNotExistException ex)
                {
                    test(ex.operation.Equals("noSuchOperation"));
                }
                catch (Exception)
                {
                    test(false);
                }
                cb.called();
            });
            cb.check();
        }

        WriteLine("ok");

        Write("catching unknown local exception with new AMI mapping... ");
        Flush();

        {
            Callback cb = new Callback();
            thrower.begin_throwLocalException().whenCompleted(
                () =>
            {
                test(false);
            },
                (Ice.Exception exc) =>
            {
                try
                {
                    throw exc;
                }
                catch (Ice.UnknownLocalException)
                {
                }
                catch (Ice.OperationNotExistException)
                {
                }
                catch (Exception)
                {
                    test(false);
                }
                cb.called();
            });
            cb.check();
        }

        {
            Callback cb = new Callback();
            thrower.begin_throwLocalExceptionIdempotent().whenCompleted(
                () =>
            {
                test(false);
            },
                (Ice.Exception exc) =>
            {
                try
                {
                    throw exc;
                }
                catch (Ice.UnknownLocalException)
                {
                }
                catch (Ice.OperationNotExistException)
                {
                }
                catch (Exception)
                {
                    test(false);
                }
                cb.called();
            });
            cb.check();
        }

        WriteLine("ok");

        Write("catching unknown non-Ice exception with new AMI mapping... ");
        Flush();

        {
            Callback cb = new Callback();
            thrower.begin_throwNonIceException().whenCompleted(
                () =>
            {
                test(false);
            },
                (Ice.Exception exc) =>
            {
                try
                {
                    throw exc;
                }
                catch (Ice.UnknownException)
                {
                }
                catch (Exception)
                {
                    test(false);
                }
                cb.called();
            });
            cb.check();
        }

        WriteLine("ok");

        // ----------------------------------------
        if (thrower.supportsUndeclaredExceptions())
        {
            Write("catching unknown user exception with new AMI mapping... ");
            Flush();

            {
                Callback cb = new Callback();
                thrower.begin_throwUndeclaredA(1).whenCompleted(
                    () =>
                {
                    test(false);
                },
                    (Ice.Exception exc) =>
                {
                    try
                    {
                        throw exc;
                    }
                    catch (Ice.UnknownUserException)
                    {
                    }
                    catch (Exception)
                    {
                        test(false);
                    }
                    cb.called();
                });
                cb.check();
            }

            {
                Callback cb = new Callback();
                thrower.begin_throwUndeclaredB(1, 2).whenCompleted(
                    () =>
                {
                    test(false);
                },
                    (Ice.Exception exc) =>
                {
                    try
                    {
                        throw exc;
                    }
                    catch (Ice.UnknownUserException)
                    {
                    }
                    catch (Exception)
                    {
                        test(false);
                    }
                    cb.called();
                });
                cb.check();
            }

            {
                Callback cb = new Callback();
                thrower.begin_throwUndeclaredC(1, 2, 3).whenCompleted(
                    () =>
                {
                    test(false);
                },
                    (Ice.Exception exc) =>
                {
                    try
                    {
                        throw exc;
                    }
                    catch (Ice.UnknownUserException)
                    {
                    }
                    catch (Exception)
                    {
                        test(false);
                    }
                    cb.called();
                });
                cb.check();
            }

            WriteLine("ok");
        }

        Write("catching object not exist exception with new AMI mapping... ");
        Flush();

        {
            Ice.Identity id       = communicator.stringToIdentity("does not exist");
            ThrowerPrx   thrower2 = ThrowerPrxHelper.uncheckedCast(thrower.ice_identity(id));
            Callback     cb       = new Callback();
            thrower2.begin_throwAasA(1).whenCompleted(
                () =>
            {
                test(false);
            },
                (Ice.Exception exc) =>
            {
                try
                {
                    throw exc;
                }
                catch (Ice.ObjectNotExistException ex)
                {
                    test(ex.id.Equals(id));
                }
                catch (Exception)
                {
                    test(false);
                }
                cb.called();
            });
            cb.check();
        }

        WriteLine("ok");

        Write("catching facet not exist exception with new AMI mapping... ");
        Flush();

        {
            ThrowerPrx thrower2 = ThrowerPrxHelper.uncheckedCast(thrower, "no such facet");
            Callback   cb       = new Callback();
            thrower2.begin_throwAasA(1).whenCompleted(
                () =>
            {
                test(false);
            },
                (Ice.Exception exc) =>
            {
                try
                {
                    throw exc;
                }
                catch (Ice.FacetNotExistException ex)
                {
                    test(ex.facet.Equals("no such facet"));
                }
                catch (Exception)
                {
                    test(false);
                }
                cb.called();
            });
            cb.check();
        }

        WriteLine("ok");

        Write("catching operation not exist exception with new AMI mapping... ");
        Flush();

        {
            Callback          cb       = new Callback();
            WrongOperationPrx thrower4 = WrongOperationPrxHelper.uncheckedCast(thrower);
            thrower4.begin_noSuchOperation().whenCompleted(
                () =>
            {
                test(false);
            },
                (Ice.Exception exc) =>
            {
                try
                {
                    throw exc;
                }
                catch (Ice.OperationNotExistException ex)
                {
                    test(ex.operation.Equals("noSuchOperation"));
                }
                catch (Exception)
                {
                    test(false);
                }
                cb.called();
            });
            cb.check();
        }

        WriteLine("ok");

        Write("catching unknown local exception with new AMI mapping... ");
        Flush();

        {
            Callback cb = new Callback();
            thrower.begin_throwLocalException().whenCompleted(
                () =>
            {
                test(false);
            },
                (Ice.Exception exc) =>
            {
                try
                {
                    throw exc;
                }
                catch (Ice.UnknownLocalException)
                {
                }
                catch (Ice.OperationNotExistException)
                {
                }
                catch (Exception)
                {
                    test(false);
                }
                cb.called();
            });
            cb.check();
        }

        {
            Callback cb = new Callback();
            thrower.begin_throwLocalExceptionIdempotent().whenCompleted(
                () =>
            {
                test(false);
            },
                (Ice.Exception exc) =>
            {
                try
                {
                    throw exc;
                }
                catch (Ice.UnknownLocalException)
                {
                }
                catch (Ice.OperationNotExistException)
                {
                }
                catch (Exception)
                {
                    test(false);
                }
                cb.called();
            });
            cb.check();
        }

        WriteLine("ok");

        Write("catching unknown non-Ice exception with new AMI mapping... ");
        Flush();

        {
            Callback cb = new Callback();
            thrower.begin_throwNonIceException().whenCompleted(
                () =>
            {
                test(false);
            },
                (Ice.Exception exc) =>
            {
                try
                {
                    throw exc;
                }
                catch (Ice.UnknownException)
                {
                }
                catch (Exception)
                {
                    test(false);
                }
                cb.called();
            });
            cb.check();
        }

        WriteLine("ok");
#if SILVERLIGHT
        thrower.shutdown();
#else
        return(thrower);
#endif
    }
Example #3
0
            public static Test.ThrowerPrx allTests(global::Test.TestHelper helper)
            {
                Communicator communicator = helper.communicator();
                var          output       = helper.getWriter();

                {
                    output.Write("testing object adapter registration exceptions... ");
                    ObjectAdapter first;
                    try
                    {
                        first = communicator.createObjectAdapter("TestAdapter0");
                    }
                    catch (InitializationException)
                    {
                        // Expected
                    }

                    communicator.getProperties().setProperty("TestAdapter0.Endpoints", "tcp -h *");
                    first = communicator.createObjectAdapter("TestAdapter0");
                    try
                    {
                        communicator.createObjectAdapter("TestAdapter0");
                        test(false);
                    }
                    catch (AlreadyRegisteredException)
                    {
                        // Expected.
                    }

                    try
                    {
                        ObjectAdapter second =
                            communicator.createObjectAdapterWithEndpoints("TestAdapter0", "ssl -h foo -p 12011");
                        test(false);

                        //
                        // Quell mono error that variable second isn't used.
                        //
                        second.deactivate();
                    }
                    catch (AlreadyRegisteredException)
                    {
                        // Expected
                    }
                    first.deactivate();
                    output.WriteLine("ok");
                }

                {
                    output.Write("testing servant registration exceptions... ");
                    communicator.getProperties().setProperty("TestAdapter1.Endpoints", "tcp -h *");
                    ObjectAdapter adapter = communicator.createObjectAdapter("TestAdapter1");
                    Object        obj     = new EmptyI();
                    adapter.add(obj, Util.stringToIdentity("x"));
                    try
                    {
                        adapter.add(obj, Util.stringToIdentity("x"));
                        test(false);
                    }
                    catch (AlreadyRegisteredException)
                    {
                    }

                    try
                    {
                        adapter.add(obj, Util.stringToIdentity(""));
                        test(false);
                    }
                    catch (IllegalIdentityException e)
                    {
                        test(e.id.name.Equals(""));
                    }

                    try
                    {
                        adapter.add(null, Util.stringToIdentity("x"));
                        test(false);
                    }
                    catch (IllegalServantException)
                    {
                    }

                    adapter.remove(Util.stringToIdentity("x"));
                    try
                    {
                        adapter.remove(Util.stringToIdentity("x"));
                        test(false);
                    }
                    catch (NotRegisteredException)
                    {
                    }
                    adapter.deactivate();
                    output.WriteLine("ok");
                }

                {
                    output.Write("testing servant locator registration exceptions... ");
                    communicator.getProperties().setProperty("TestAdapter2.Endpoints", "tcp -h *");
                    ObjectAdapter  adapter = communicator.createObjectAdapter("TestAdapter2");
                    ServantLocator loc     = new ServantLocatorI();
                    adapter.addServantLocator(loc, "x");
                    try
                    {
                        adapter.addServantLocator(loc, "x");
                        test(false);
                    }
                    catch (AlreadyRegisteredException)
                    {
                    }

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

                output.Write("testing stringToProxy... ");
                output.Flush();
                String    @ref  = "thrower:" + helper.getTestEndpoint(0);
                ObjectPrx @base = communicator.stringToProxy(@ref);

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

                output.Write("testing checked cast... ");
                output.Flush();
                var thrower = Test.ThrowerPrxHelper.checkedCast(@base);

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

                output.Write("catching exact types... ");
                output.Flush();

                try
                {
                    thrower.throwAasA(1);
                    test(false);
                }
                catch (Test.A ex)
                {
                    test(ex.aMem == 1);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                    test(false);
                }

                try
                {
                    thrower.throwAorDasAorD(1);
                    test(false);
                }
                catch (Test.A ex)
                {
                    test(ex.aMem == 1);
                }
                catch (Exception)
                {
                    test(false);
                }

                try
                {
                    thrower.throwAorDasAorD(-1);
                    test(false);
                }
                catch (Test.D ex)
                {
                    test(ex.dMem == -1);
                }
                catch (Exception)
                {
                    test(false);
                }

                try
                {
                    thrower.throwBasB(1, 2);
                    test(false);
                }
                catch (Test.B ex)
                {
                    test(ex.aMem == 1);
                    test(ex.bMem == 2);
                }
                catch (Exception)
                {
                    test(false);
                }

                try
                {
                    thrower.throwCasC(1, 2, 3);
                    test(false);
                }
                catch (Test.C ex)
                {
                    test(ex.aMem == 1);
                    test(ex.bMem == 2);
                    test(ex.cMem == 3);
                }
                catch (Exception)
                {
                    test(false);
                }

                output.WriteLine("ok");

                output.Write("catching base types... ");
                output.Flush();

                try
                {
                    thrower.throwBasB(1, 2);
                    test(false);
                }
                catch (Test.A ex)
                {
                    test(ex.aMem == 1);
                }
                catch (Exception)
                {
                    test(false);
                }

                try
                {
                    thrower.throwCasC(1, 2, 3);
                    test(false);
                }
                catch (Test.B ex)
                {
                    test(ex.aMem == 1);
                    test(ex.bMem == 2);
                }
                catch (Exception)
                {
                    test(false);
                }

                output.WriteLine("ok");

                output.Write("catching derived types... ");
                output.Flush();

                try
                {
                    thrower.throwBasA(1, 2);
                    test(false);
                }
                catch (Test.B ex)
                {
                    test(ex.aMem == 1);
                    test(ex.bMem == 2);
                }
                catch (Exception)
                {
                    test(false);
                }

                try
                {
                    thrower.throwCasA(1, 2, 3);
                    test(false);
                }
                catch (Test.C ex)
                {
                    test(ex.aMem == 1);
                    test(ex.bMem == 2);
                    test(ex.cMem == 3);
                }
                catch (Exception)
                {
                    test(false);
                }

                try
                {
                    thrower.throwCasB(1, 2, 3);
                    test(false);
                }
                catch (Test.C ex)
                {
                    test(ex.aMem == 1);
                    test(ex.bMem == 2);
                    test(ex.cMem == 3);
                }
                catch (Exception)
                {
                    test(false);
                }

                output.WriteLine("ok");

                if (thrower.supportsUndeclaredExceptions())
                {
                    output.Write("catching unknown user exception... ");
                    output.Flush();

                    try
                    {
                        thrower.throwUndeclaredA(1);
                        test(false);
                    }
                    catch (UnknownUserException)
                    {
                    }
                    catch (Exception)
                    {
                        test(false);
                    }

                    try
                    {
                        thrower.throwUndeclaredB(1, 2);
                        test(false);
                    }
                    catch (UnknownUserException)
                    {
                    }
                    catch (Exception)
                    {
                        test(false);
                    }

                    try
                    {
                        thrower.throwUndeclaredC(1, 2, 3);
                        test(false);
                    }
                    catch (UnknownUserException)
                    {
                    }
                    catch (Exception)
                    {
                        test(false);
                    }

                    output.WriteLine("ok");
                }

                if (thrower.ice_getConnection() != null)
                {
                    output.Write("testing memory limit marshal exception...");
                    output.Flush();
                    try
                    {
                        thrower.throwMemoryLimitException(null);
                        test(false);
                    }
                    catch (MemoryLimitException)
                    {
                    }
                    catch (Exception)
                    {
                        test(false);
                    }

                    try
                    {
                        thrower.throwMemoryLimitException(new byte[20 * 1024]); // 20KB
                        test(false);
                    }
                    catch (ConnectionLostException)
                    {
                    }
                    catch (UnknownLocalException)
                    {
                        // Expected with JS bidir server
                    }
                    catch (Exception)
                    {
                        test(false);
                    }

                    try
                    {
                        var thrower2 = Test.ThrowerPrxHelper.uncheckedCast(
                            communicator.stringToProxy("thrower:" + helper.getTestEndpoint(1)));
                        try
                        {
                            thrower2.throwMemoryLimitException(new byte[2 * 1024 * 1024]); // 2MB(no limits)
                        }
                        catch (MemoryLimitException)
                        {
                        }
                        var thrower3 = Test.ThrowerPrxHelper.uncheckedCast(
                            communicator.stringToProxy("thrower:" + helper.getTestEndpoint(2)));
                        try
                        {
                            thrower3.throwMemoryLimitException(new byte[1024]); // 1KB limit
                            test(false);
                        }
                        catch (ConnectionLostException)
                        {
                        }
                    }
                    catch (ConnectionRefusedException)
                    {
                        // Expected with JS bidir server
                    }

                    output.WriteLine("ok");
                }

                output.Write("catching object not exist exception... ");
                output.Flush();

                {
                    Identity id = Util.stringToIdentity("does not exist");
                    try
                    {
                        var thrower2 = Test.ThrowerPrxHelper.uncheckedCast(thrower.ice_identity(id));
                        thrower2.ice_ping();
                        test(false);
                    }
                    catch (ObjectNotExistException ex)
                    {
                        test(ex.id.Equals(id));
                    }
                    catch (Exception)
                    {
                        test(false);
                    }
                }

                output.WriteLine("ok");

                output.Write("catching facet not exist exception... ");
                output.Flush();

                try
                {
                    var thrower2 = Test.ThrowerPrxHelper.uncheckedCast(thrower, "no such facet");
                    try
                    {
                        thrower2.ice_ping();
                        test(false);
                    }
                    catch (FacetNotExistException ex)
                    {
                        test(ex.facet.Equals("no such facet"));
                    }
                }
                catch (Exception)
                {
                    test(false);
                }

                output.WriteLine("ok");

                output.Write("catching operation not exist exception... ");
                output.Flush();

                try
                {
                    var thrower2 = Test.WrongOperationPrxHelper.uncheckedCast(thrower);
                    thrower2.noSuchOperation();
                    test(false);
                }
                catch (OperationNotExistException ex)
                {
                    test(ex.operation.Equals("noSuchOperation"));
                }
                catch (Exception)
                {
                    test(false);
                }

                output.WriteLine("ok");

                output.Write("catching unknown local exception... ");
                output.Flush();

                try
                {
                    thrower.throwLocalException();
                    test(false);
                }
                catch (UnknownLocalException)
                {
                }
                catch (Exception)
                {
                    test(false);
                }
                try
                {
                    thrower.throwLocalExceptionIdempotent();
                    test(false);
                }
                catch (UnknownLocalException)
                {
                }
                catch (OperationNotExistException)
                {
                }
                catch (Exception)
                {
                    test(false);
                }

                output.WriteLine("ok");

                output.Write("catching unknown non-Ice exception... ");
                output.Flush();

                try
                {
                    thrower.throwNonIceException();
                    test(false);
                }
                catch (UnknownException)
                {
                }
                catch (Exception)
                {
                    test(false);
                }

                output.WriteLine("ok");

                output.Write("testing asynchronous exceptions... ");
                output.Flush();

                try
                {
                    thrower.throwAfterResponse();
                }
                catch (Exception)
                {
                    test(false);
                }

                try
                {
                    thrower.throwAfterException();
                    test(false);
                }
                catch (Test.A)
                {
                }
                catch (Exception)
                {
                    test(false);
                }

                output.WriteLine("ok");

                output.Write("catching exact types with AMI mapping... ");
                output.Flush();

                {
                    try
                    {
                        thrower.throwAasAAsync(1).Wait();
                    }
                    catch (AggregateException exc)
                    {
                        test(exc.InnerException is Test.A);
                        var ex = exc.InnerException as Test.A;
                        test(ex.aMem == 1);
                    }
                }

                {
                    try
                    {
                        thrower.throwAorDasAorDAsync(1).Wait();
                        test(false);
                    }
                    catch (AggregateException exc)
                    {
                        try
                        {
                            throw exc.InnerException;
                        }
                        catch (Test.A ex)
                        {
                            test(ex.aMem == 1);
                        }
                        catch (Test.D ex)
                        {
                            test(ex.dMem == -1);
                        }
                        catch (Exception)
                        {
                            test(false);
                        }
                    }
                }

                {
                    try
                    {
                        thrower.throwAorDasAorDAsync(-1).Wait();
                        test(false);
                    }
                    catch (AggregateException exc)
                    {
                        try
                        {
                            throw exc.InnerException;
                        }
                        catch (Test.A ex)
                        {
                            test(ex.aMem == 1);
                        }
                        catch (Test.D ex)
                        {
                            test(ex.dMem == -1);
                        }
                        catch (Exception)
                        {
                            test(false);
                        }
                    }
                }

                {
                    try
                    {
                        thrower.throwBasBAsync(1, 2).Wait();
                        test(false);
                    }
                    catch (AggregateException exc)
                    {
                        try
                        {
                            throw exc.InnerException;
                        }
                        catch (Test.B ex)
                        {
                            test(ex.aMem == 1);
                            test(ex.bMem == 2);
                        }
                        catch (Exception)
                        {
                            test(false);
                        }
                    }
                }

                {
                    try
                    {
                        thrower.throwCasCAsync(1, 2, 3).Wait();
                        test(false);
                    }
                    catch (AggregateException exc)
                    {
                        try
                        {
                            throw exc.InnerException;
                        }
                        catch (Test.C ex)
                        {
                            test(ex.aMem == 1);
                            test(ex.bMem == 2);
                            test(ex.cMem == 3);
                        }
                        catch (Exception)
                        {
                            test(false);
                        }
                    }
                }

                output.WriteLine("ok");

                output.Write("catching derived types with new AMI mapping... ");
                output.Flush();

                {
                    try
                    {
                        thrower.throwBasAAsync(1, 2).Wait();
                        test(false);
                    }
                    catch (AggregateException exc)
                    {
                        try
                        {
                            throw exc.InnerException;
                        }
                        catch (Test.B ex)
                        {
                            test(ex.aMem == 1);
                            test(ex.bMem == 2);
                        }
                        catch (Exception)
                        {
                            test(false);
                        }
                    }
                }

                {
                    try
                    {
                        thrower.throwCasAAsync(1, 2, 3).Wait();
                    }
                    catch (AggregateException exc)
                    {
                        try
                        {
                            throw exc.InnerException;
                        }
                        catch (Test.C ex)
                        {
                            test(ex.aMem == 1);
                            test(ex.bMem == 2);
                            test(ex.cMem == 3);
                        }
                        catch (Exception)
                        {
                            test(false);
                        }
                    }
                }

                {
                    try
                    {
                        thrower.throwCasBAsync(1, 2, 3).Wait();
                        test(false);
                    }
                    catch (AggregateException exc)
                    {
                        try
                        {
                            throw exc.InnerException;
                        }
                        catch (Test.C ex)
                        {
                            test(ex.aMem == 1);
                            test(ex.bMem == 2);
                            test(ex.cMem == 3);
                        }
                        catch (Exception)
                        {
                            test(false);
                        }
                    }
                }

                output.WriteLine("ok");

                if (thrower.supportsUndeclaredExceptions())
                {
                    output.Write("catching unknown user exception with new AMI mapping... ");
                    output.Flush();

                    {
                        try
                        {
                            thrower.throwUndeclaredAAsync(1).Wait();
                            test(false);
                        }
                        catch (AggregateException exc)
                        {
                            try
                            {
                                throw exc.InnerException;
                            }
                            catch (UnknownUserException)
                            {
                            }
                            catch (Exception)
                            {
                                test(false);
                            }
                        }
                    }

                    {
                        try
                        {
                            thrower.throwUndeclaredBAsync(1, 2).Wait();
                            test(false);
                        }
                        catch (AggregateException exc)
                        {
                            try
                            {
                                throw exc.InnerException;
                            }
                            catch (UnknownUserException)
                            {
                            }
                            catch (Exception)
                            {
                                test(false);
                            }
                        }
                    }

                    {
                        try
                        {
                            thrower.throwUndeclaredCAsync(1, 2, 3).Wait();
                            test(false);
                        }
                        catch (AggregateException exc)
                        {
                            try
                            {
                                throw exc.InnerException;
                            }
                            catch (UnknownUserException)
                            {
                            }
                            catch (Exception)
                            {
                                test(false);
                            }
                        }
                    }

                    output.WriteLine("ok");
                }

                output.Write("catching object not exist exception with new AMI mapping... ");
                output.Flush();

                {
                    Identity id       = Util.stringToIdentity("does not exist");
                    var      thrower2 = Test.ThrowerPrxHelper.uncheckedCast(thrower.ice_identity(id));
                    try
                    {
                        thrower2.throwAasAAsync(1).Wait();
                        test(false);
                    }
                    catch (AggregateException exc)
                    {
                        try
                        {
                            throw exc.InnerException;
                        }
                        catch (ObjectNotExistException ex)
                        {
                            test(ex.id.Equals(id));
                        }
                        catch (Exception)
                        {
                            test(false);
                        }
                    }
                }

                output.WriteLine("ok");

                output.Write("catching facet not exist exception with new AMI mapping... ");
                output.Flush();

                {
                    var thrower2 = Test.ThrowerPrxHelper.uncheckedCast(thrower, "no such facet");
                    try
                    {
                        thrower2.throwAasAAsync(1).Wait();
                        test(false);
                    }
                    catch (AggregateException exc)
                    {
                        try
                        {
                            throw exc.InnerException;
                        }
                        catch (FacetNotExistException ex)
                        {
                            test(ex.facet.Equals("no such facet"));
                        }
                        catch (Exception)
                        {
                            test(false);
                        }
                    }
                }

                output.WriteLine("ok");

                output.Write("catching operation not exist exception with new AMI mapping... ");
                output.Flush();

                {
                    try
                    {
                        var thrower4 = Test.WrongOperationPrxHelper.uncheckedCast(thrower);
                        thrower4.noSuchOperationAsync().Wait();
                        test(false);
                    }
                    catch (AggregateException exc)
                    {
                        try
                        {
                            throw exc.InnerException;
                        }
                        catch (OperationNotExistException ex)
                        {
                            test(ex.operation.Equals("noSuchOperation"));
                        }
                        catch (Exception)
                        {
                            test(false);
                        }
                    }
                }

                output.WriteLine("ok");

                output.Write("catching unknown local exception with new AMI mapping... ");
                output.Flush();

                {
                    try
                    {
                        thrower.throwLocalExceptionAsync().Wait();
                        test(false);
                    }
                    catch (AggregateException exc)
                    {
                        try
                        {
                            throw exc.InnerException;
                        }
                        catch (UnknownLocalException)
                        {
                        }
                        catch (OperationNotExistException)
                        {
                        }
                        catch (Exception)
                        {
                            test(false);
                        }
                    }
                }

                {
                    try
                    {
                        thrower.throwLocalExceptionIdempotentAsync().Wait();
                        test(false);
                    }
                    catch (AggregateException exc)
                    {
                        try
                        {
                            throw exc.InnerException;
                        }
                        catch (UnknownLocalException)
                        {
                        }
                        catch (OperationNotExistException)
                        {
                        }
                        catch (Exception)
                        {
                            test(false);
                        }
                    }
                }

                output.WriteLine("ok");

                output.Write("catching unknown non-Ice exception with new AMI mapping... ");
                output.Flush();

                {
                    try
                    {
                        thrower.throwNonIceExceptionAsync().Wait();
                        test(false);
                    }
                    catch (AggregateException exc)
                    {
                        try
                        {
                            throw exc.InnerException;
                        }
                        catch (UnknownException)
                        {
                        }
                        catch (Exception)
                        {
                            test(false);
                        }
                    }
                }

                output.WriteLine("ok");

                if (thrower.supportsUndeclaredExceptions())
                {
                    output.Write("catching unknown user exception with new AMI mapping... ");
                    output.Flush();

                    {
                        try
                        {
                            thrower.throwUndeclaredAAsync(1).Wait();
                            test(false);
                        }
                        catch (AggregateException exc)
                        {
                            try
                            {
                                throw exc.InnerException;
                            }
                            catch (UnknownUserException)
                            {
                            }
                            catch (Exception)
                            {
                                test(false);
                            }
                        }
                    }

                    {
                        try
                        {
                            thrower.throwUndeclaredBAsync(1, 2).Wait();
                            test(false);
                        }
                        catch (AggregateException exc)
                        {
                            try
                            {
                                throw exc.InnerException;
                            }
                            catch (UnknownUserException)
                            {
                            }
                            catch (Exception)
                            {
                                test(false);
                            }
                        }
                    }

                    {
                        try
                        {
                            thrower.throwUndeclaredCAsync(1, 2, 3).Wait();
                            test(false);
                        }
                        catch (AggregateException exc)
                        {
                            try
                            {
                                throw exc.InnerException;
                            }
                            catch (UnknownUserException)
                            {
                            }
                            catch (Exception)
                            {
                                test(false);
                            }
                        }
                    }

                    output.WriteLine("ok");
                }

                output.Write("catching object not exist exception with new AMI mapping... ");
                output.Flush();

                {
                    Identity id       = Util.stringToIdentity("does not exist");
                    var      thrower2 = Test.ThrowerPrxHelper.uncheckedCast(thrower.ice_identity(id));
                    try
                    {
                        thrower2.throwAasAAsync(1).Wait();
                        test(false);
                    }
                    catch (AggregateException exc)
                    {
                        try
                        {
                            throw exc.InnerException;
                        }
                        catch (ObjectNotExistException ex)
                        {
                            test(ex.id.Equals(id));
                        }
                        catch (Exception)
                        {
                            test(false);
                        }
                    }
                }

                output.WriteLine("ok");

                output.Write("catching facet not exist exception with new AMI mapping... ");
                output.Flush();

                {
                    var thrower2 = Test.ThrowerPrxHelper.uncheckedCast(thrower, "no such facet");
                    try
                    {
                        thrower2.throwAasAAsync(1).Wait();
                        test(false);
                    }
                    catch (AggregateException exc)
                    {
                        try
                        {
                            throw exc.InnerException;
                        }
                        catch (FacetNotExistException ex)
                        {
                            test(ex.facet.Equals("no such facet"));
                        }
                        catch (Exception)
                        {
                            test(false);
                        }
                    }
                }

                output.WriteLine("ok");

                output.Write("catching operation not exist exception with new AMI mapping... ");
                output.Flush();

                {
                    var thrower4 = Test.WrongOperationPrxHelper.uncheckedCast(thrower);
                    try
                    {
                        thrower4.noSuchOperationAsync().Wait();
                        test(false);
                    }
                    catch (AggregateException exc)
                    {
                        try
                        {
                            throw exc.InnerException;
                        }
                        catch (OperationNotExistException ex)
                        {
                            test(ex.operation.Equals("noSuchOperation"));
                        }
                        catch (Exception)
                        {
                            test(false);
                        }
                    }
                }

                output.WriteLine("ok");

                output.Write("catching unknown local exception with new AMI mapping... ");
                output.Flush();

                {
                    try
                    {
                        thrower.throwLocalExceptionAsync().Wait();
                        test(false);
                    }
                    catch (AggregateException exc)
                    {
                        try
                        {
                            throw exc.InnerException;
                        }
                        catch (UnknownLocalException)
                        {
                        }
                        catch (OperationNotExistException)
                        {
                        }
                        catch (Exception)
                        {
                            test(false);
                        }
                    }
                }

                {
                    try
                    {
                        thrower.throwLocalExceptionIdempotentAsync().Wait();
                        test(false);
                    }
                    catch (AggregateException exc)
                    {
                        try
                        {
                            throw exc.InnerException;
                        }
                        catch (UnknownLocalException)
                        {
                        }
                        catch (OperationNotExistException)
                        {
                        }
                        catch (Exception)
                        {
                            test(false);
                        }
                    }
                }

                output.WriteLine("ok");

                output.Write("catching unknown non-Ice exception with new AMI mapping... ");
                output.Flush();

                {
                    try
                    {
                        thrower.throwNonIceExceptionAsync().Wait();
                        test(false);
                    }
                    catch (AggregateException exc)
                    {
                        try
                        {
                            throw exc.InnerException;
                        }
                        catch (UnknownException)
                        {
                        }
                        catch (Exception)
                        {
                            test(false);
                        }
                    }
                }

                output.WriteLine("ok");
                return(thrower);
            }
Example #4
0
    public static GPrx allTests(TestCommon.Application app)
    {
        Ice.Communicator communicator = app.communicator();

        Write("testing Ice.Admin.Facets property... ");
        test(communicator.getProperties().getPropertyAsList("Ice.Admin.Facets").Length == 0);
        communicator.getProperties().setProperty("Ice.Admin.Facets", "foobar");
        String[] facetFilter = communicator.getProperties().getPropertyAsList("Ice.Admin.Facets");
        test(facetFilter.Length == 1 && facetFilter[0].Equals("foobar"));
        communicator.getProperties().setProperty("Ice.Admin.Facets", "foo\\'bar");
        facetFilter = communicator.getProperties().getPropertyAsList("Ice.Admin.Facets");
        test(facetFilter.Length == 1 && facetFilter[0].Equals("foo'bar"));
        communicator.getProperties().setProperty("Ice.Admin.Facets", "'foo bar' toto 'titi'");
        facetFilter = communicator.getProperties().getPropertyAsList("Ice.Admin.Facets");
        test(facetFilter.Length == 3 && facetFilter[0].Equals("foo bar") && facetFilter[1].Equals("toto") &&
             facetFilter[2].Equals("titi"));
        communicator.getProperties().setProperty("Ice.Admin.Facets", "'foo bar\\' toto' 'titi'");
        facetFilter = communicator.getProperties().getPropertyAsList("Ice.Admin.Facets");
        test(facetFilter.Length == 2 && facetFilter[0].Equals("foo bar' toto") && facetFilter[1].Equals("titi"));
        //  communicator.getProperties().setProperty("Ice.Admin.Facets", "'foo bar' 'toto titi");
        // facetFilter = communicator.getProperties().getPropertyAsList("Ice.Admin.Facets");
        // test(facetFilter.Length == 0);
        communicator.getProperties().setProperty("Ice.Admin.Facets", "");
        WriteLine("ok");

        Write("testing facet registration exceptions... ");
        communicator.getProperties().setProperty("FacetExceptionTestAdapter.Endpoints", "default");
        Ice.ObjectAdapter adapter = communicator.createObjectAdapter("FacetExceptionTestAdapter");
        Ice.Object        obj     = new EmptyI();
        adapter.add(obj, Ice.Util.stringToIdentity("d"));
        adapter.addFacet(obj, Ice.Util.stringToIdentity("d"), "facetABCD");
        try
        {
            adapter.addFacet(obj, Ice.Util.stringToIdentity("d"), "facetABCD");
            test(false);
        }
        catch (Ice.AlreadyRegisteredException)
        {
        }
        adapter.removeFacet(Ice.Util.stringToIdentity("d"), "facetABCD");
        try
        {
            adapter.removeFacet(Ice.Util.stringToIdentity("d"), "facetABCD");
            test(false);
        }
        catch (Ice.NotRegisteredException)
        {
        }
        WriteLine("ok");

        Write("testing removeAllFacets... ");
        Ice.Object obj1 = new EmptyI();
        Ice.Object obj2 = new EmptyI();
        adapter.addFacet(obj1, Ice.Util.stringToIdentity("id1"), "f1");
        adapter.addFacet(obj2, Ice.Util.stringToIdentity("id1"), "f2");
        Ice.Object obj3 = new EmptyI();
        adapter.addFacet(obj1, Ice.Util.stringToIdentity("id2"), "f1");
        adapter.addFacet(obj2, Ice.Util.stringToIdentity("id2"), "f2");
        adapter.addFacet(obj3, Ice.Util.stringToIdentity("id2"), "");
        Dictionary <string, Ice.Object> fm
            = adapter.removeAllFacets(Ice.Util.stringToIdentity("id1"));

        test(fm.Count == 2);
        test(fm["f1"] == obj1);
        test(fm["f2"] == obj2);
        try
        {
            adapter.removeAllFacets(Ice.Util.stringToIdentity("id1"));
            test(false);
        }
        catch (Ice.NotRegisteredException)
        {
        }
        fm = adapter.removeAllFacets(Ice.Util.stringToIdentity("id2"));
        test(fm.Count == 3);
        test(fm["f1"] == obj1);
        test(fm["f2"] == obj2);
        test(fm[""] == obj3);
        WriteLine("ok");

        adapter.deactivate();

        Write("testing stringToProxy... ");
        Flush();
        string @ref = "d:" + app.getTestEndpoint(0);

        Ice.ObjectPrx db = communicator.stringToProxy(@ref);
        test(db != null);
        WriteLine("ok");

        Write("testing unchecked cast... ");
        Flush();
        Ice.ObjectPrx prx = Ice.ObjectPrxHelper.uncheckedCast(db);
        test(prx.ice_getFacet().Length == 0);
        prx = Ice.ObjectPrxHelper.uncheckedCast(db, "facetABCD");
        test(prx.ice_getFacet() == "facetABCD");
        Ice.ObjectPrx prx2 = Ice.ObjectPrxHelper.uncheckedCast(prx);
        test(prx2.ice_getFacet() == "facetABCD");
        Ice.ObjectPrx prx3 = Ice.ObjectPrxHelper.uncheckedCast(prx, "");
        test(prx3.ice_getFacet().Length == 0);
        DPrx d = Test.DPrxHelper.uncheckedCast(db);

        test(d.ice_getFacet().Length == 0);
        DPrx df = Test.DPrxHelper.uncheckedCast(db, "facetABCD");

        test(df.ice_getFacet() == "facetABCD");
        DPrx df2 = Test.DPrxHelper.uncheckedCast(df);

        test(df2.ice_getFacet() == "facetABCD");
        DPrx df3 = Test.DPrxHelper.uncheckedCast(df, "");

        test(df3.ice_getFacet().Length == 0);
        WriteLine("ok");

        Write("testing checked cast... ");
        Flush();
        prx = Ice.ObjectPrxHelper.checkedCast(db);
        test(prx.ice_getFacet().Length == 0);
        prx = Ice.ObjectPrxHelper.checkedCast(db, "facetABCD");
        test(prx.ice_getFacet() == "facetABCD");
        prx2 = Ice.ObjectPrxHelper.checkedCast(prx);
        test(prx2.ice_getFacet() == "facetABCD");
        prx3 = Ice.ObjectPrxHelper.checkedCast(prx, "");
        test(prx3.ice_getFacet().Length == 0);
        d = Test.DPrxHelper.checkedCast(db);
        test(d.ice_getFacet().Length == 0);
        df = Test.DPrxHelper.checkedCast(db, "facetABCD");
        test(df.ice_getFacet() == "facetABCD");
        df2 = Test.DPrxHelper.checkedCast(df);
        test(df2.ice_getFacet() == "facetABCD");
        df3 = Test.DPrxHelper.checkedCast(df, "");
        test(df3.ice_getFacet().Length == 0);
        WriteLine("ok");

        Write("testing non-facets A, B, C, and D... ");
        Flush();
        d = DPrxHelper.checkedCast(db);
        test(d != null);
        test(d.Equals(db));
        test(d.callA().Equals("A"));
        test(d.callB().Equals("B"));
        test(d.callC().Equals("C"));
        test(d.callD().Equals("D"));
        WriteLine("ok");

        Write("testing facets A, B, C, and D... ");
        Flush();
        df = DPrxHelper.checkedCast(d, "facetABCD");
        test(df != null);
        test(df.callA().Equals("A"));
        test(df.callB().Equals("B"));
        test(df.callC().Equals("C"));
        test(df.callD().Equals("D"));
        WriteLine("ok");

        Write("testing facets E and F... ");
        Flush();
        FPrx ff = FPrxHelper.checkedCast(d, "facetEF");

        test(ff != null);
        test(ff.callE().Equals("E"));
        test(ff.callF().Equals("F"));
        WriteLine("ok");

        Write("testing facet G... ");
        Flush();
        GPrx gf = GPrxHelper.checkedCast(ff, "facetGH");

        test(gf != null);
        test(gf.callG().Equals("G"));
        WriteLine("ok");

        Write("testing whether casting preserves the facet... ");
        Flush();
        HPrx hf = HPrxHelper.checkedCast(gf);

        test(hf != null);
        test(hf.callG().Equals("G"));
        test(hf.callH().Equals("H"));
        WriteLine("ok");
        return(gf);
    }
Example #5
0
    public static ThrowerPrx allTests(Ice.Communicator communicator, bool collocated)
    {
        {
            Console.Write("testing object adapter registration exceptions... ");
            Ice.ObjectAdapter first;
            try
            {
                first = communicator.createObjectAdapter("TestAdapter0");
            }
            catch(Ice.InitializationException)
            {
                // Expected
            }

            communicator.getProperties().setProperty("TestAdapter0.Endpoints", "default");
            first = communicator.createObjectAdapter("TestAdapter0");
            try
            {
                communicator.createObjectAdapter("TestAdapter0");
                test(false);
            }
            catch(Ice.AlreadyRegisteredException)
            {
                // Expected.
            }

            try
            {
                Ice.ObjectAdapter second =
                    communicator.createObjectAdapterWithEndpoints("TestAdapter0", "ssl -h foo -p 12011");
                test(false);

                //
                // Quell mono error that variable second isn't used.
                //
                second.deactivate();
            }
            catch(Ice.AlreadyRegisteredException)
            {
                // Expected
            }
            first.deactivate();
            Console.WriteLine("ok");
        }

        {
            Console.Write("testing servant registration exceptions... ");
            communicator.getProperties().setProperty("TestAdapter1.Endpoints", "default");
            Ice.ObjectAdapter adapter = communicator.createObjectAdapter("TestAdapter1");
            Ice.Object obj = new EmptyI();
            adapter.add(obj, communicator.stringToIdentity("x"));
            try
            {
                adapter.add(obj, communicator.stringToIdentity("x"));
                test(false);
            }
            catch(Ice.AlreadyRegisteredException)
            {
            }

            adapter.remove(communicator.stringToIdentity("x"));
            try
            {
                adapter.remove(communicator.stringToIdentity("x"));
                test(false);
            }
            catch(Ice.NotRegisteredException)
            {
            }
            adapter.deactivate();
            Console.WriteLine("ok");
        }

        {
            Console.Write("testing servant locator registration exceptions... ");
            communicator.getProperties().setProperty("TestAdapter2.Endpoints", "default");
            Ice.ObjectAdapter adapter = communicator.createObjectAdapter("TestAdapter2");
            Ice.ServantLocator loc = new ServantLocatorI();
            adapter.addServantLocator(loc, "x");
            try
            {
                adapter.addServantLocator(loc, "x");
                test(false);
            }
            catch(Ice.AlreadyRegisteredException)
            {
            }

            adapter.deactivate();
            Console.WriteLine("ok");
        }

        {
            Console.Write("testing object factory registration exception... ");
            Ice.ObjectFactory of = new ObjectFactoryI();
            communicator.addObjectFactory(of, "::x");
            try
            {
                communicator.addObjectFactory(of, "::x");
                test(false);
            }
            catch(Ice.AlreadyRegisteredException)
            {
            }
            Console.WriteLine("ok");
        }

        Console.Write("testing stringToProxy... ");
        Console.Out.Flush();
        String @ref = "thrower:default -p 12010";
        Ice.ObjectPrx @base = communicator.stringToProxy(@ref);
        test(@base != null);
        Console.WriteLine("ok");

        Console.Write("testing checked cast... ");
        Console.Out.Flush();
        ThrowerPrx thrower = ThrowerPrxHelper.checkedCast(@base);
        test(thrower != null);
        test(thrower.Equals(@base));
        Console.WriteLine("ok");

        Console.Write("catching exact types... ");
        Console.Out.Flush();

        try
        {
            thrower.throwAasA(1);
            test(false);
        }
        catch(A ex)
        {
            test(ex.aMem == 1);
        }
        catch(Exception)
        {
            test(false);
        }

        try
        {
            thrower.throwAorDasAorD(1);
            test(false);
        }
        catch(A ex)
        {
            test(ex.aMem == 1);
        }
        catch(Exception)
        {
            test(false);
        }

        try
        {
            thrower.throwAorDasAorD(- 1);
            test(false);
        }
        catch(D ex)
        {
            test(ex.dMem == - 1);
        }
        catch(Exception)
        {
            test(false);
        }

        try
        {
            thrower.throwBasB(1, 2);
            test(false);
        }
        catch(B ex)
        {
            test(ex.aMem == 1);
            test(ex.bMem == 2);
        }
        catch(Exception)
        {
            test(false);
        }

        try
        {
            thrower.throwCasC(1, 2, 3);
            test(false);
        }
        catch(C ex)
        {
            test(ex.aMem == 1);
            test(ex.bMem == 2);
            test(ex.cMem == 3);
        }
        catch(Exception)
        {
            test(false);
        }

        Console.WriteLine("ok");

        Console.Write("catching base types... ");
        Console.Out.Flush();

        try
        {
            thrower.throwBasB(1, 2);
            test(false);
        }
        catch(A ex)
        {
            test(ex.aMem == 1);
        }
        catch(Exception)
        {
            test(false);
        }

        try
        {
            thrower.throwCasC(1, 2, 3);
            test(false);
        }
        catch(B ex)
        {
            test(ex.aMem == 1);
            test(ex.bMem == 2);
        }
        catch(Exception)
        {
            test(false);
        }

        Console.WriteLine("ok");

        Console.Write("catching derived types... ");
        Console.Out.Flush();

        try
        {
            thrower.throwBasA(1, 2);
            test(false);
        }
        catch(B ex)
        {
            test(ex.aMem == 1);
            test(ex.bMem == 2);
        }
        catch(Exception)
        {
            test(false);
        }

        try
        {
            thrower.throwCasA(1, 2, 3);
            test(false);
        }
        catch(C ex)
        {
            test(ex.aMem == 1);
            test(ex.bMem == 2);
            test(ex.cMem == 3);
        }
        catch(Exception)
        {
            test(false);
        }

        try
        {
            thrower.throwCasB(1, 2, 3);
            test(false);
        }
        catch(C ex)
        {
            test(ex.aMem == 1);
            test(ex.bMem == 2);
            test(ex.cMem == 3);
        }
        catch(Exception)
        {
            test(false);
        }

        Console.WriteLine("ok");

        if(thrower.supportsUndeclaredExceptions())
        {
            Console.Write("catching unknown user exception... ");
            Console.Out.Flush();

            try
            {
                thrower.throwUndeclaredA(1);
                test(false);
            }
            catch(Ice.UnknownUserException)
            {
            }
            catch(Exception)
            {
                test(false);
            }

            try
            {
                thrower.throwUndeclaredB(1, 2);
                test(false);
            }
            catch(Ice.UnknownUserException)
            {
            }
            catch(Exception)
            {
                test(false);
            }

            try
            {
                thrower.throwUndeclaredC(1, 2, 3);
                test(false);
            }
            catch(Ice.UnknownUserException)
            {
            }
            catch(Exception)
            {
                test(false);
            }

            Console.WriteLine("ok");
        }

        Console.Write("catching object not exist exception... ");
        Console.Out.Flush();

        {
            Ice.Identity id = communicator.stringToIdentity("does not exist");
            try
            {
                ThrowerPrx thrower2 = ThrowerPrxHelper.uncheckedCast(thrower.ice_identity(id));
                thrower2.ice_ping();
                test(false);
            }
            catch(Ice.ObjectNotExistException ex)
            {
                test(ex.id.Equals(id));
            }
            catch(Exception)
            {
                test(false);
            }
        }

        Console.WriteLine("ok");

        Console.Write("catching facet not exist exception... ");
        Console.Out.Flush();

        try
        {
            ThrowerPrx thrower2 = ThrowerPrxHelper.uncheckedCast(thrower, "no such facet");
            try
            {
                thrower2.ice_ping();
                test(false);
            }
            catch(Ice.FacetNotExistException ex)
            {
                test(ex.facet.Equals("no such facet"));
            }
        }
        catch(Exception)
        {
            test(false);
        }

        Console.WriteLine("ok");

        Console.Write("catching operation not exist exception... ");
        Console.Out.Flush();

        try
        {
            WrongOperationPrx thrower2 = WrongOperationPrxHelper.uncheckedCast(thrower);
            thrower2.noSuchOperation();
            test(false);
        }
        catch(Ice.OperationNotExistException ex)
        {
            test(ex.operation.Equals("noSuchOperation"));
        }
        catch(Exception)
        {
            test(false);
        }

        Console.WriteLine("ok");

        Console.Write("catching unknown local exception... ");
        Console.Out.Flush();

        try
        {
            thrower.throwLocalException();
            test(false);
        }
        catch(Ice.UnknownLocalException)
        {
        }
        catch(Exception)
        {
            test(false);
        }

        Console.WriteLine("ok");

        Console.Write("catching unknown non-Ice exception... ");
        Console.Out.Flush();

        try
        {
            thrower.throwNonIceException();
            test(false);
        }
        catch(Ice.UnknownException)
        {
        }
        catch(System.Exception)
        {
            test(false);
        }

        Console.WriteLine("ok");

        Console.Write("testing asynchronous exceptions... ");
        Console.Out.Flush();

        try
        {
            thrower.throwAfterResponse();
        }
        catch(Exception)
        {
            test(false);
        }

        try
        {
            thrower.throwAfterException();
            test(false);
        }
        catch(A)
        {
        }
        catch(Exception)
        {
            test(false);
        }

        Console.WriteLine("ok");

        if(!collocated)
        {
            Console.Write("catching exact types with AMI... ");
            Console.Out.Flush();

            {
                AMI_Thrower_throwAasAI cb = new AMI_Thrower_throwAasAI();
                thrower.throwAasA_async(cb, 1);
                cb.check();
            }

            {
                AMI_Thrower_throwAorDasAorDI cb = new AMI_Thrower_throwAorDasAorDI();
                thrower.throwAorDasAorD_async(cb, 1);
                cb.check();
            }

            {
                AMI_Thrower_throwAorDasAorDI cb = new AMI_Thrower_throwAorDasAorDI();
                thrower.throwAorDasAorD_async(cb, - 1);
                cb.check();
            }

            {
                AMI_Thrower_throwBasBI cb = new AMI_Thrower_throwBasBI();
                thrower.throwBasB_async(cb, 1, 2);
                cb.check();
            }

            {
                AMI_Thrower_throwCasCI cb = new AMI_Thrower_throwCasCI();
                thrower.throwCasC_async(cb, 1, 2, 3);
                cb.check();
            }

            Console.WriteLine("ok");

            Console.Write("catching derived types... ");
            Console.Out.Flush();

            {
                AMI_Thrower_throwBasAI cb = new AMI_Thrower_throwBasAI();
                thrower.throwBasA_async(cb, 1, 2);
                cb.check();
            }

            {
                AMI_Thrower_throwCasAI cb = new AMI_Thrower_throwCasAI();
                thrower.throwCasA_async(cb, 1, 2, 3);
                cb.check();
            }

            {
                AMI_Thrower_throwCasBI cb = new AMI_Thrower_throwCasBI();
                thrower.throwCasB_async(cb, 1, 2, 3);
                cb.check();
            }

            Console.WriteLine("ok");

            if(thrower.supportsUndeclaredExceptions())
            {
                Console.Write("catching unknown user exception with AMI... ");
                Console.Out.Flush();

                {
                    AMI_Thrower_throwUndeclaredAI cb = new AMI_Thrower_throwUndeclaredAI();
                    thrower.throwUndeclaredA_async(cb, 1);
                    cb.check();
                }

                {
                    AMI_Thrower_throwUndeclaredBI cb = new AMI_Thrower_throwUndeclaredBI();
                    thrower.throwUndeclaredB_async(cb, 1, 2);
                    cb.check();
                }

                {
                    AMI_Thrower_throwUndeclaredCI cb = new AMI_Thrower_throwUndeclaredCI();
                    thrower.throwUndeclaredC_async(cb, 1, 2, 3);
                    cb.check();
                }

                Console.WriteLine("ok");
            }

            Console.Write("catching object not exist exception with AMI... ");
            Console.Out.Flush();

            {
                Ice.Identity id = communicator.stringToIdentity("does not exist");
                ThrowerPrx thrower2 = ThrowerPrxHelper.uncheckedCast(thrower.ice_identity(id));
                AMI_Thrower_throwAasAObjectNotExistI cb = new AMI_Thrower_throwAasAObjectNotExistI(communicator);
                thrower2.throwAasA_async(cb, 1);
                cb.check();
            }

            Console.WriteLine("ok");

            Console.Write("catching facet not exist exception with AMI... ");
            Console.Out.Flush();

            try
            {
                ThrowerPrx thrower2 = ThrowerPrxHelper.uncheckedCast(thrower, "no such facet");
                {
                    AMI_Thrower_throwAasAFacetNotExistI cb = new AMI_Thrower_throwAasAFacetNotExistI();
                    thrower2.throwAasA_async(cb, 1);
                    cb.check();
                }
            }
            catch(Exception)
            {
                test(false);
            }

            Console.WriteLine("ok");

            Console.Write("catching operation not exist exception with AMI... ");
            Console.Out.Flush();

            {
                AMI_WrongOperation_noSuchOperationI cb = new AMI_WrongOperation_noSuchOperationI();
                WrongOperationPrx thrower2 = WrongOperationPrxHelper.uncheckedCast(thrower);
                thrower2.noSuchOperation_async(cb);
                cb.check();
            }

            Console.WriteLine("ok");

            Console.Write("catching unknown local exception with AMI... ");
            Console.Out.Flush();

            {
                AMI_Thrower_throwLocalExceptionI cb = new AMI_Thrower_throwLocalExceptionI();
                thrower.throwLocalException_async(cb);
                cb.check();
            }

            Console.WriteLine("ok");

            Console.Write("catching unknown non-Ice exception with AMI... ");
            Console.Out.Flush();

            AMI_Thrower_throwNonIceExceptionI cb2 = new AMI_Thrower_throwNonIceExceptionI();
            thrower.throwNonIceException_async(cb2);
            cb2.check();

            Console.WriteLine("ok");

            Console.Write("catching exact types with new AMI mapping... ");
            Console.Out.Flush();

            {
                AsyncCallback cb3 = new AsyncCallback();
                thrower.begin_throwAasA(1).whenCompleted(cb3.response, cb3.exception_AasA);
                cb3.check();
            }

            {
                AsyncCallback cb3 = new AsyncCallback();
                thrower.begin_throwAorDasAorD(1).whenCompleted(cb3.response, cb3.exception_AorDasAorD);
                cb3.check();
            }

            {
                AsyncCallback cb3 = new AsyncCallback();
                thrower.begin_throwAorDasAorD(-1).whenCompleted(cb3.response, cb3.exception_AorDasAorD);
                cb3.check();
            }

            {
                AsyncCallback cb3 = new AsyncCallback();
                thrower.begin_throwBasB(1, 2).whenCompleted(cb3.response, cb3.exception_BasB);
                cb3.check();
            }

            {
                AsyncCallback cb3 = new AsyncCallback();
                thrower.begin_throwCasC(1, 2, 3).whenCompleted(cb3.response, cb3.exception_CasC);
                cb3.check();
            }

            Console.WriteLine("ok");

            Console.Write("catching derived types with new AMI mapping... ");
            Console.Out.Flush();

            {
                AsyncCallback cb3 = new AsyncCallback();
                thrower.begin_throwBasA(1, 2).whenCompleted(cb3.response, cb3.exception_BasA);
                cb3.check();
            }

            {
                AsyncCallback cb3 = new AsyncCallback();
                thrower.begin_throwCasA(1, 2, 3).whenCompleted(cb3.response, cb3.exception_CasA);
                cb3.check();
            }

            {
                AsyncCallback cb3 = new AsyncCallback();
                thrower.begin_throwCasB(1, 2, 3).whenCompleted(cb3.response, cb3.exception_CasB);
                cb3.check();
            }

            Console.WriteLine("ok");

            if(thrower.supportsUndeclaredExceptions())
            {
                Console.Write("catching unknown user exception with new AMI mapping... ");
                Console.Out.Flush();

                {
                    AsyncCallback cb3 = new AsyncCallback();
                    thrower.begin_throwUndeclaredA(1).whenCompleted(cb3.response, cb3.exception_UndeclaredA);
                    cb3.check();
                }

                {
                    AsyncCallback cb3 = new AsyncCallback();
                    thrower.begin_throwUndeclaredB(1, 2).whenCompleted(cb3.response, cb3.exception_UndeclaredB);
                    cb3.check();
                }

                {
                    AsyncCallback cb3 = new AsyncCallback();
                    thrower.begin_throwUndeclaredC(1, 2, 3).whenCompleted(cb3.response, cb3.exception_UndeclaredC);
                    cb3.check();
                }

                Console.WriteLine("ok");
            }

            Console.Write("catching object not exist exception with new AMI mapping... ");
            Console.Out.Flush();

            {
                Ice.Identity id = communicator.stringToIdentity("does not exist");
                ThrowerPrx thrower2 = ThrowerPrxHelper.uncheckedCast(thrower.ice_identity(id));
                AsyncCallback cb3 = new AsyncCallback(communicator);
                thrower2.begin_throwAasA(1).whenCompleted(cb3.response, cb3.exception_AasAObjectNotExist);
                cb3.check();
            }

            Console.WriteLine("ok");

            Console.Write("catching facet not exist exception with new AMI mapping... ");
            Console.Out.Flush();

            {
                ThrowerPrx thrower2 = ThrowerPrxHelper.uncheckedCast(thrower, "no such facet");
                AsyncCallback cb3 = new AsyncCallback();
                thrower2.begin_throwAasA(1).whenCompleted(cb3.response, cb3.exception_AasAFacetNotExist);
                cb3.check();
            }

            Console.WriteLine("ok");

            Console.Write("catching operation not exist exception with new AMI mapping... ");
            Console.Out.Flush();

            {
                AsyncCallback cb3 = new AsyncCallback();
                WrongOperationPrx thrower4 = WrongOperationPrxHelper.uncheckedCast(thrower);
                thrower4.begin_noSuchOperation().whenCompleted(cb3.response, cb3.exception_noSuchOperation);
                cb3.check();
            }

            Console.WriteLine("ok");

            Console.Write("catching unknown local exception with new AMI mapping... ");
            Console.Out.Flush();

            {
                AsyncCallback cb3 = new AsyncCallback();
                thrower.begin_throwLocalException().whenCompleted(cb3.response, cb3.exception_LocalException);
                cb3.check();
            }

            Console.WriteLine("ok");

            Console.Write("catching unknown non-Ice exception with new AMI mapping... ");
            Console.Out.Flush();

            {
                AsyncCallback cb3 = new AsyncCallback();
                thrower.begin_throwNonIceException().whenCompleted(cb3.response, cb3.exception_NonIceException);
                cb3.check();
            }

            Console.WriteLine("ok");
        }

        return thrower;
    }
Example #6
0
            public static Test.GPrx allTests(global::Test.TestHelper helper)
            {
                Communicator communicator = helper.communicator();
                var          output       = helper.getWriter();

                output.Write("testing Ice.Admin.Facets property... ");
                test(communicator.GetPropertyAsList("Ice.Admin.Facets") == null);
                communicator.SetProperty("Ice.Admin.Facets", "foobar");
                string[]? facetFilter = communicator.GetPropertyAsList("Ice.Admin.Facets");
                test(facetFilter != null && facetFilter.Length == 1 && facetFilter[0].Equals("foobar"));
                communicator.SetProperty("Ice.Admin.Facets", "foo\\'bar");
                facetFilter = communicator.GetPropertyAsList("Ice.Admin.Facets");
                test(facetFilter != null && facetFilter.Length == 1 && facetFilter[0].Equals("foo'bar"));
                communicator.SetProperty("Ice.Admin.Facets", "'foo bar' toto 'titi'");
                facetFilter = communicator.GetPropertyAsList("Ice.Admin.Facets");
                test(facetFilter != null && facetFilter.Length == 3 && facetFilter[0].Equals("foo bar") &&
                     facetFilter[1].Equals("toto") && facetFilter[2].Equals("titi"));
                communicator.SetProperty("Ice.Admin.Facets", "'foo bar\\' toto' 'titi'");
                facetFilter = communicator.GetPropertyAsList("Ice.Admin.Facets");
                test(facetFilter != null && facetFilter.Length == 2 && facetFilter[0].Equals("foo bar' toto") &&
                     facetFilter[1].Equals("titi"));
                // communicator.SetProperty("Ice.Admin.Facets", "'foo bar' 'toto titi");
                // facetFilter = communicator.Properties.getPropertyAsList("Ice.Admin.Facets");
                // test(facetFilter.Length == 0);
                communicator.SetProperty("Ice.Admin.Facets", "");
                output.WriteLine("ok");

                output.Write("testing facet registration exceptions... ");
                communicator.SetProperty("FacetExceptionTestAdapter.Endpoints", "tcp -h *");
                ObjectAdapter adapter = communicator.createObjectAdapter("FacetExceptionTestAdapter");

                var obj = new EmptyI();

                adapter.Add(obj, "d");
                adapter.Add(obj, "d", "facetABCD");
                try
                {
                    adapter.Add(obj, "d", "facetABCD");
                    test(false);
                }
                catch (System.ArgumentException)
                {
                }
                adapter.Remove("d", "facetABCD");
                try
                {
                    adapter.Remove("d", "facetABCD");
                    test(false);
                }
                catch (NotRegisteredException)
                {
                }
                output.WriteLine("ok");

                output.Write("testing removeAllFacets... ");
                var obj1 = new EmptyI();
                var obj2 = new EmptyI();
                var obj3 = new EmptyI();

                adapter.Add(obj1, "id1", "f1");
                adapter.Add(obj2, "id1", "f2");
                adapter.Add(obj1, "id2", "f1");
                adapter.Add(obj2, "id2", "f2");
                adapter.Add(obj3, "id2", "");
                Dictionary <string, Disp> fm = adapter.RemoveAllFacets("id1");

                test(fm.Count == 2);
                test(fm.ContainsKey("f1"));
                test(fm.ContainsKey("f2"));
                try
                {
                    adapter.RemoveAllFacets("id1");
                    test(false);
                }
                catch (NotRegisteredException)
                {
                }
                fm = adapter.RemoveAllFacets("id2");
                test(fm.Count == 3);
                test(fm.ContainsKey("f1"));
                test(fm.ContainsKey("f2"));
                test(fm.ContainsKey(""));
                output.WriteLine("ok");

                adapter.Deactivate();

                var prx = IObjectPrx.Parse($"d:{helper.getTestEndpoint(0)}", communicator);

                output.Write("testing unchecked cast... ");
                output.Flush();
                var d = DPrx.UncheckedCast(prx);

                test(d.Facet.Length == 0);
                var df = DPrx.UncheckedCast(prx.Clone(facet: "facetABCD"));

                test(df.Facet == "facetABCD");
                var df2 = DPrx.UncheckedCast(df);

                test(df2.Facet == "facetABCD");
                var df3 = DPrx.UncheckedCast(df.Clone(facet: ""));

                test(df3.Facet.Length == 0);
                output.WriteLine("ok");

                output.Write("testing checked cast... ");
                output.Flush();
                d = DPrx.CheckedCast(prx);
                test(d.Facet.Length == 0);
                df = DPrx.CheckedCast(prx.Clone(facet: "facetABCD"));
                test(df.Facet == "facetABCD");
                df2 = DPrx.CheckedCast(df);
                test(df2.Facet == "facetABCD");
                df3 = DPrx.CheckedCast(df.Clone(facet: ""));
                test(df3.Facet.Length == 0);
                output.WriteLine("ok");

                output.Write("testing non-facets A, B, C, and D... ");
                output.Flush();
                d = DPrx.CheckedCast(prx);
                test(d != null);
                test(d.Equals(prx));
                test(d.callA().Equals("A"));
                test(d.callB().Equals("B"));
                test(d.callC().Equals("C"));
                test(d.callD().Equals("D"));
                output.WriteLine("ok");

                output.Write("testing facets A, B, C, and D... ");
                output.Flush();
                df = DPrx.CheckedCast(d.Clone(facet: "facetABCD"));
                test(df != null);
                test(df.callA().Equals("A"));
                test(df.callB().Equals("B"));
                test(df.callC().Equals("C"));
                test(df.callD().Equals("D"));
                output.WriteLine("ok");

                output.Write("testing facets E and F... ");
                output.Flush();
                var ff = FPrx.CheckedCast(d.Clone(facet: "facetEF"));

                test(ff.callE().Equals("E"));
                test(ff.callF().Equals("F"));
                output.WriteLine("ok");

                output.Write("testing facet G... ");
                output.Flush();
                var gf = GPrx.CheckedCast(ff.Clone(facet: "facetGH"));

                test(gf.callG().Equals("G"));
                output.WriteLine("ok");

                output.Write("testing whether casting preserves the facet... ");
                output.Flush();
                var hf = HPrx.CheckedCast(gf);

                test(hf.callG().Equals("G"));
                test(hf.callH().Equals("H"));
                output.WriteLine("ok");
                return(gf);
            }
Example #7
0
    public static ThrowerPrx allTests(Ice.Communicator communicator)
#endif
    {
#if SILVERLIGHT
        WriteLine("Ice.FactoryAssemblies: " + communicator.getProperties().getProperty("Ice.FactoryAssemblies"));
#endif

#if !SILVERLIGHT
        {
            Write("testing object adapter registration exceptions... ");
            Ice.ObjectAdapter first;
            try
            {
                first = communicator.createObjectAdapter("TestAdapter0");
            }
            catch(Ice.InitializationException)
            {
                // Expected
            }

            communicator.getProperties().setProperty("TestAdapter0.Endpoints", "default");
            first = communicator.createObjectAdapter("TestAdapter0");
            try
            {
                communicator.createObjectAdapter("TestAdapter0");
                test(false);
            }
            catch(Ice.AlreadyRegisteredException)
            {
                // Expected.
            }

            try
            {
                Ice.ObjectAdapter second =
                    communicator.createObjectAdapterWithEndpoints("TestAdapter0", "ssl -h foo -p 12011");
                test(false);

                //
                // Quell mono error that variable second isn't used.
                //
                second.deactivate();
            }
            catch(Ice.AlreadyRegisteredException)
            {
                // Expected
            }
            first.deactivate();
            WriteLine("ok");
        }

        {
            Write("testing servant registration exceptions... ");
            communicator.getProperties().setProperty("TestAdapter1.Endpoints", "default");
            Ice.ObjectAdapter adapter = communicator.createObjectAdapter("TestAdapter1");
            Ice.Object obj = new EmptyI();
            adapter.add(obj, communicator.stringToIdentity("x"));
            try
            {
                adapter.add(obj, communicator.stringToIdentity("x"));
                test(false);
            }
            catch(Ice.AlreadyRegisteredException)
            {
            }

            try
            {
                adapter.add(obj, communicator.stringToIdentity(""));
                test(false);
            }
            catch(Ice.IllegalIdentityException e)
            {
                test(e.id.name.Equals(""));
            }

            try
            {
                adapter.add(null, communicator.stringToIdentity("x"));
                test(false);
            }
            catch(Ice.IllegalServantException)
            {
            }

            adapter.remove(communicator.stringToIdentity("x"));
            try
            {
                adapter.remove(communicator.stringToIdentity("x"));
                test(false);
            }
            catch(Ice.NotRegisteredException)
            {
            }
            adapter.deactivate();
            WriteLine("ok");
        }

        {
            Write("testing servant locator registration exceptions... ");
            communicator.getProperties().setProperty("TestAdapter2.Endpoints", "default");
            Ice.ObjectAdapter adapter = communicator.createObjectAdapter("TestAdapter2");
            Ice.ServantLocator loc = new ServantLocatorI();
            adapter.addServantLocator(loc, "x");
            try
            {
                adapter.addServantLocator(loc, "x");
                test(false);
            }
            catch(Ice.AlreadyRegisteredException)
            {
            }

            adapter.deactivate();
            WriteLine("ok");
        }
#endif
        {
            Write("testing object factory registration exception... ");
            Ice.ObjectFactory of = new ObjectFactoryI();
            communicator.addObjectFactory(of, "::x");
            try
            {
                communicator.addObjectFactory(of, "::x");
                test(false);
            }
            catch(Ice.AlreadyRegisteredException)
            {
            }
            WriteLine("ok");
        }

        Write("testing stringToProxy... ");
        Flush();
        String @ref = "thrower:default -p 12010";
        Ice.ObjectPrx @base = communicator.stringToProxy(@ref);
        test(@base != null);
        WriteLine("ok");

        Write("testing checked cast... ");
        Flush();
        ThrowerPrx thrower = ThrowerPrxHelper.checkedCast(@base);

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

        Write("catching exact types... ");
        Flush();

        try
        {
            thrower.throwAasA(1);
            test(false);
        }
        catch(A ex)
        {
            test(ex.aMem == 1);
        }
        catch(Exception)
        {
            test(false);
        }

        try
        {
            thrower.throwAorDasAorD(1);
            test(false);
        }
        catch(A ex)
        {
            test(ex.aMem == 1);
        }
        catch(Exception)
        {
            test(false);
        }

        try
        {
            thrower.throwAorDasAorD(- 1);
            test(false);
        }
        catch(D ex)
        {
            test(ex.dMem == - 1);
        }
        catch(Exception)
        {
            test(false);
        }

        try
        {
            thrower.throwBasB(1, 2);
            test(false);
        }
        catch(B ex)
        {
            test(ex.aMem == 1);
            test(ex.bMem == 2);
        }
        catch(Exception)
        {
            test(false);
        }

        try
        {
            thrower.throwCasC(1, 2, 3);
            test(false);
        }
        catch(C ex)
        {
            test(ex.aMem == 1);
            test(ex.bMem == 2);
            test(ex.cMem == 3);
        }
        catch(Exception)
        {
            test(false);
        }

        WriteLine("ok");

        Write("catching base types... ");
        Flush();

        try
        {
            thrower.throwBasB(1, 2);
            test(false);
        }
        catch(A ex)
        {
            test(ex.aMem == 1);
        }
        catch(Exception)
        {
            test(false);
        }

        try
        {
            thrower.throwCasC(1, 2, 3);
            test(false);
        }
        catch(B ex)
        {
            test(ex.aMem == 1);
            test(ex.bMem == 2);
        }
        catch(Exception)
        {
            test(false);
        }

        WriteLine("ok");

        Write("catching derived types... ");
        Flush();

        try
        {
            thrower.throwBasA(1, 2);
            test(false);
        }
        catch(B ex)
        {
            test(ex.aMem == 1);
            test(ex.bMem == 2);
        }
        catch(Exception)
        {
            test(false);
        }

        try
        {
            thrower.throwCasA(1, 2, 3);
            test(false);
        }
        catch(C ex)
        {
            test(ex.aMem == 1);
            test(ex.bMem == 2);
            test(ex.cMem == 3);
        }
        catch(Exception)
        {
            test(false);
        }

        try
        {
            thrower.throwCasB(1, 2, 3);
            test(false);
        }
        catch(C ex)
        {
            test(ex.aMem == 1);
            test(ex.bMem == 2);
            test(ex.cMem == 3);
        }
        catch(Exception)
        {
            test(false);
        }

        WriteLine("ok");

        if(thrower.supportsUndeclaredExceptions())
        {
            Write("catching unknown user exception... ");
            Flush();

            try
            {
                thrower.throwUndeclaredA(1);
                test(false);
            }
            catch(Ice.UnknownUserException)
            {
            }
            catch(Exception)
            {
                test(false);
            }

            try
            {
                thrower.throwUndeclaredB(1, 2);
                test(false);
            }
            catch(Ice.UnknownUserException)
            {
            }
            catch(Exception)
            {
                test(false);
            }

            try
            {
                thrower.throwUndeclaredC(1, 2, 3);
                test(false);
            }
            catch(Ice.UnknownUserException)
            {
            }
            catch(Exception)
            {
                test(false);
            }

            WriteLine("ok");
        }

        if(thrower.ice_getConnection() != null)
        {
            Write("testing memory limit marshal exception...");
            Flush();
            try
            {
                thrower.throwMemoryLimitException(null);
                test(false);
            }
            catch(Ice.MemoryLimitException)
            {
            }
            catch(Exception)
            {
                test(false);
            }

            try
            {
                thrower.throwMemoryLimitException(new byte[20 * 1024]); // 20KB
                test(false);
            }
            catch(Ice.ConnectionLostException)
            {
            }
            catch(Exception)
            {
                test(false);
            }

            ThrowerPrx thrower2 = ThrowerPrxHelper.uncheckedCast(
                communicator.stringToProxy("thrower:default -p 12011"));
            try
            {
                thrower2.throwMemoryLimitException(new byte[2 * 1024 * 1024]); // 2MB (no limits)
            }
            catch(Ice.MemoryLimitException)
            {
            }
            ThrowerPrx thrower3 = ThrowerPrxHelper.uncheckedCast(
                communicator.stringToProxy("thrower:default -p 12012"));
            try
            {
                thrower3.throwMemoryLimitException(new byte[1024]); // 1KB limit
                test(false);
            }
            catch(Ice.ConnectionLostException)
            {
            }

            WriteLine("ok");
        }

        Write("catching object not exist exception... ");
        Flush();

        {
            Ice.Identity id = communicator.stringToIdentity("does not exist");
            try
            {
                ThrowerPrx thrower2 = ThrowerPrxHelper.uncheckedCast(thrower.ice_identity(id));
                thrower2.ice_ping();
                test(false);
            }
            catch(Ice.ObjectNotExistException ex)
            {
                test(ex.id.Equals(id));
            }
            catch(Exception)
            {
                test(false);
            }
        }

        WriteLine("ok");

        Write("catching facet not exist exception... ");
        Flush();

        try
        {
            ThrowerPrx thrower2 = ThrowerPrxHelper.uncheckedCast(thrower, "no such facet");
            try
            {
                thrower2.ice_ping();
                test(false);
            }
            catch(Ice.FacetNotExistException ex)
            {
                test(ex.facet.Equals("no such facet"));
            }
        }
        catch(Exception)
        {
            test(false);
        }

        WriteLine("ok");

        Write("catching operation not exist exception... ");
        Flush();

        try
        {
            WrongOperationPrx thrower2 = WrongOperationPrxHelper.uncheckedCast(thrower);
            thrower2.noSuchOperation();
            test(false);
        }
        catch(Ice.OperationNotExistException ex)
        {
            test(ex.operation.Equals("noSuchOperation"));
        }
        catch(Exception)
        {
            test(false);
        }

        WriteLine("ok");

        Write("catching unknown local exception... ");
        Flush();

        try
        {
            thrower.throwLocalException();
            test(false);
        }
        catch(Ice.UnknownLocalException)
        {
        }
        catch(Exception)
        {
            test(false);
        }
        try
        {
            thrower.throwLocalExceptionIdempotent();
            test(false);
        }
        catch(Ice.UnknownLocalException)
        {
        }
        catch(Ice.OperationNotExistException)
        {
        }
        catch(Exception)
        {
            test(false);
        }

        WriteLine("ok");

        Write("catching unknown non-Ice exception... ");
        Flush();

        try
        {
            thrower.throwNonIceException();
            test(false);
        }
        catch(Ice.UnknownException)
        {
        }
        catch(System.Exception)
        {
            test(false);
        }

        WriteLine("ok");

        Write("testing asynchronous exceptions... ");
        Flush();

        try
        {
            thrower.throwAfterResponse();
        }
        catch(Exception)
        {
            test(false);
        }

        try
        {
            thrower.throwAfterException();
            test(false);
        }
        catch(A)
        {
        }
        catch(Exception)
        {
            test(false);
        }

        WriteLine("ok");

        Write("catching exact types with AMI mapping... ");
        Flush();

        {
            Callback cb = new Callback();
            thrower.begin_throwAasA(1).whenCompleted(
                () =>
                {
                    test(false);
                },
                (Ice.Exception exc) =>
                {
                    test(exc is A);
                    A ex = exc as A;
                    test(ex.aMem == 1);
                    cb.called();
                });
            cb.check();
        }

        {
            Callback cb = new Callback();
            thrower.begin_throwAorDasAorD(1).whenCompleted(
                () =>
                {
                    test(false);
                },
                (Ice.Exception exc) =>
                {
                    try
                    {
                        throw exc;
                    }
                    catch(A ex)
                    {
                        test(ex.aMem == 1);
                    }
                    catch(D ex)
                    {
                        test(ex.dMem == -1);
                    }
                    catch(Exception)
                    {
                        test(false);
                    }
                    cb.called();                
                });
            cb.check();
        }

        {
            Callback cb = new Callback();
            thrower.begin_throwAorDasAorD(-1).whenCompleted(
                () =>
                {
                    test(false);
                },
                (Ice.Exception exc) =>
                {
                     try
                    {
                        throw exc;
                    }
                    catch(A ex)
                    {
                        test(ex.aMem == 1);
                    }
                    catch(D ex)
                    {
                        test(ex.dMem == -1);
                    }
                    catch(Exception)
                    {
                        test(false);
                    }
                    cb.called();
                });
            cb.check();
        }

        {
            Callback cb = new Callback();
            thrower.begin_throwBasB(1, 2).whenCompleted(
                () =>
                {
                    test(false);
                },
                (Ice.Exception exc) =>
                {
                    try
                    {
                        throw exc;
                    }
                    catch(B ex)
                    {
                        test(ex.aMem == 1);
                        test(ex.bMem == 2);
                    }
                    catch(Exception)
                    {
                        test(false);
                    }
                    cb.called();
                });
            cb.check();
        }

        {
            Callback cb = new Callback();
            thrower.begin_throwCasC(1, 2, 3).whenCompleted(
                () =>
                {
                    test(false);
                },
                (Ice.Exception exc) =>
                {
                    try
                    {
                        throw exc;
                    }
                    catch(C ex)
                    {
                        test(ex.aMem == 1);
                        test(ex.bMem == 2);
                        test(ex.cMem == 3);
                    }
                    catch(Exception)
                    {
                        test(false);
                    }
                    cb.called();
                });
            cb.check();
        }

        WriteLine("ok");

        Write("catching derived types with new AMI mapping... ");
        Flush();

        {
            Callback cb = new Callback();
            thrower.begin_throwBasA(1, 2).whenCompleted(
                () =>
                {
                    test(false);
                },
                (Ice.Exception exc) =>
                {
                    try
                    {
                        throw exc;
                    }
                    catch(B ex)
                    {
                        test(ex.aMem == 1);
                        test(ex.bMem == 2);
                    }
                    catch(Exception)
                    {
                        test(false);
                    }
                    cb.called();
                });
            cb.check();
        }

        {
            Callback cb = new Callback();
            thrower.begin_throwCasA(1, 2, 3).whenCompleted(
                () =>
                {
                    test(false);
                },
                (Ice.Exception exc) =>
                {
                     try
                    {
                        throw exc;
                    }
                    catch(C ex)
                    {
                        test(ex.aMem == 1);
                        test(ex.bMem == 2);
                        test(ex.cMem == 3);
                    }
                    catch(Exception)
                    {
                        test(false);
                    }
                    cb.called();
                });
            cb.check();
        }

        {
            Callback cb = new Callback();
            thrower.begin_throwCasB(1, 2, 3).whenCompleted(
                () =>
                {
                    test(false);
                },
                (Ice.Exception exc) =>
                {
                     try
                    {
                        throw exc;
                    }
                    catch(C ex)
                    {
                        test(ex.aMem == 1);
                        test(ex.bMem == 2);
                        test(ex.cMem == 3);
                    }
                    catch(Exception)
                    {
                        test(false);
                    }
                    cb.called();
                });
            cb.check();
        }

        WriteLine("ok");

        if(thrower.supportsUndeclaredExceptions())
        {
            Write("catching unknown user exception with new AMI mapping... ");
            Flush();

            {
                Callback cb = new Callback();
                thrower.begin_throwUndeclaredA(1).whenCompleted(
                    () =>
                    {
                        test(false);
                    },
                    (Ice.Exception exc) =>
                    {
                        try
                        {
                            throw exc;
                        }
                        catch(Ice.UnknownUserException)
                        {
                        }
                        catch(Exception)
                        {
                            test(false);
                        }
                        cb.called();
                    });
                cb.check();
            }

            {
                Callback cb = new Callback();
                thrower.begin_throwUndeclaredB(1, 2).whenCompleted(
                    () =>
                    {
                        test(false);
                    },
                    (Ice.Exception exc) =>
                    {
                        try
                        {
                            throw exc;
                        }
                        catch(Ice.UnknownUserException)
                        {
                        }
                        catch(Exception)
                        {
                            test(false);
                        }
                        cb.called();
                    });
                cb.check();
            }

            {
                Callback cb = new Callback();
                thrower.begin_throwUndeclaredC(1, 2, 3).whenCompleted(
                    () =>
                    {
                        test(false);
                    },
                    (Ice.Exception exc) =>
                    {
                        try
                        {
                            throw exc;
                        }
                        catch(Ice.UnknownUserException)
                        {
                        }
                        catch(Exception)
                        {
                            test(false);
                        }
                        cb.called();
                    });
                cb.check();
            }

            WriteLine("ok");
        }

        Write("catching object not exist exception with new AMI mapping... ");
        Flush();

        {
            Ice.Identity id = communicator.stringToIdentity("does not exist");
            ThrowerPrx thrower2 = ThrowerPrxHelper.uncheckedCast(thrower.ice_identity(id));
            Callback cb = new Callback();
            thrower2.begin_throwAasA(1).whenCompleted(
                () =>
                {
                    test(false);
                },
                (Ice.Exception exc) =>
                {
                    try
                    {
                        throw exc;
                    }
                    catch(Ice.ObjectNotExistException ex)
                    {
                        test(ex.id.Equals(id));
                    }
                    catch(Exception)
                    {
                        test(false);
                    }
                    cb.called();
                });
            cb.check();
        }

        WriteLine("ok");

        Write("catching facet not exist exception with new AMI mapping... ");
        Flush();

        {
            ThrowerPrx thrower2 = ThrowerPrxHelper.uncheckedCast(thrower, "no such facet");
            Callback cb = new Callback();
            thrower2.begin_throwAasA(1).whenCompleted(
                () =>
                {
                    test(false);
                },
                (Ice.Exception exc) =>
                {
                    try
                    {
                        throw exc;
                    }
                    catch(Ice.FacetNotExistException ex)
                    {
                        test(ex.facet.Equals("no such facet"));
                    }
                    catch(Exception)
                    {
                        test(false);
                    }
                    cb.called();
                });
            cb.check();
        }

        WriteLine("ok");

        Write("catching operation not exist exception with new AMI mapping... ");
        Flush();

        {
            Callback cb = new Callback();
            WrongOperationPrx thrower4 = WrongOperationPrxHelper.uncheckedCast(thrower);
            thrower4.begin_noSuchOperation().whenCompleted(
                () =>
                {
                    test(false);
                },
                (Ice.Exception exc) =>
                {
                    try
                    {
                        throw exc;
                    }
                    catch(Ice.OperationNotExistException ex)
                    {
                        test(ex.operation.Equals("noSuchOperation"));
                    }
                    catch(Exception)
                    {
                        test(false);
                    }
                    cb.called();
                });
            cb.check();
        }

        WriteLine("ok");

        Write("catching unknown local exception with new AMI mapping... ");
        Flush();

        {
            Callback cb = new Callback();
            thrower.begin_throwLocalException().whenCompleted(
                () =>
                {
                    test(false);
                },
                (Ice.Exception exc) =>
                {
                    try
                    {
                        throw exc;
                    }
                    catch(Ice.UnknownLocalException)
                    {
                    }
                    catch(Ice.OperationNotExistException)
                    {
                    }
                    catch(Exception)
                    {
                        test(false);
                    }
                    cb.called();
                });
            cb.check();
        }

        {
            Callback cb = new Callback();
            thrower.begin_throwLocalExceptionIdempotent().whenCompleted(
                () =>
                {
                    test(false);
                },
                (Ice.Exception exc) =>
                {
                    try
                    {
                        throw exc;
                    }
                    catch(Ice.UnknownLocalException)
                    {
                    }
                    catch(Ice.OperationNotExistException)
                    {
                    }
                    catch(Exception)
                    {
                        test(false);
                    }
                    cb.called();
                });
            cb.check();
        }

        WriteLine("ok");

        Write("catching unknown non-Ice exception with new AMI mapping... ");
        Flush();

        {
            Callback cb = new Callback();
            thrower.begin_throwNonIceException().whenCompleted(
                () =>
                {
                    test(false);
                },
                (Ice.Exception exc) =>
                {
                    try
                    {
                        throw exc;
                    }
                    catch(Ice.UnknownException)
                    {
                    }
                    catch(Exception)
                    {
                        test(false);
                    }
                    cb.called();
                });
            cb.check();
        }

        WriteLine("ok");

        // ----------------------------------------
        if(thrower.supportsUndeclaredExceptions())
        {
            Write("catching unknown user exception with new AMI mapping... ");
            Flush();

            {
                Callback cb = new Callback();
                thrower.begin_throwUndeclaredA(1).whenCompleted(
                    () =>
                    {
                        test(false);
                    },
                    (Ice.Exception exc) =>
                    {
                        try
                        {
                            throw exc;
                        }
                        catch(Ice.UnknownUserException)
                        {
                        }
                        catch(Exception)
                        {
                            test(false);
                        }
                        cb.called();
                    });
                cb.check();
            }

            {
                Callback cb = new Callback();
                thrower.begin_throwUndeclaredB(1, 2).whenCompleted(
                    () =>
                    {
                        test(false);
                    },
                    (Ice.Exception exc) =>
                    {
                        try
                        {
                            throw exc;
                        }
                        catch(Ice.UnknownUserException)
                        {
                        }
                        catch(Exception)
                        {
                            test(false);
                        }
                        cb.called();
                    });
                cb.check();
            }

            {
                Callback cb = new Callback();
                thrower.begin_throwUndeclaredC(1, 2, 3).whenCompleted(
                    () =>
                    {
                        test(false);
                    },
                    (Ice.Exception exc) =>
                    {
                        try
                        {
                            throw exc;
                        }
                        catch(Ice.UnknownUserException)
                        {
                        }
                        catch(Exception)
                        {
                            test(false);
                        }
                        cb.called();
                    });
                cb.check();
            }

            WriteLine("ok");
        }

        Write("catching object not exist exception with new AMI mapping... ");
        Flush();

        {
            Ice.Identity id = communicator.stringToIdentity("does not exist");
            ThrowerPrx thrower2 = ThrowerPrxHelper.uncheckedCast(thrower.ice_identity(id));
            Callback cb = new Callback();
            thrower2.begin_throwAasA(1).whenCompleted(
                () =>
                {
                    test(false);
                },
                (Ice.Exception exc) =>
                {
                    try
                    {
                        throw exc;
                    }
                    catch(Ice.ObjectNotExistException ex)
                    {
                        test(ex.id.Equals(id));
                    }
                    catch(Exception)
                    {
                        test(false);
                    }
                    cb.called();
                });
            cb.check();
        }

        WriteLine("ok");

        Write("catching facet not exist exception with new AMI mapping... ");
        Flush();

        {
            ThrowerPrx thrower2 = ThrowerPrxHelper.uncheckedCast(thrower, "no such facet");
            Callback cb = new Callback();
            thrower2.begin_throwAasA(1).whenCompleted(
                () =>
                {
                    test(false);
                },
                (Ice.Exception exc) =>
                {
                    try
                    {
                        throw exc;
                    }
                    catch(Ice.FacetNotExistException ex)
                    {
                        test(ex.facet.Equals("no such facet"));
                    }
                    catch(Exception)
                    {
                        test(false);
                    }
                    cb.called();
                });
            cb.check();
        }

        WriteLine("ok");

        Write("catching operation not exist exception with new AMI mapping... ");
        Flush();

        {
            Callback cb = new Callback();
            WrongOperationPrx thrower4 = WrongOperationPrxHelper.uncheckedCast(thrower);
            thrower4.begin_noSuchOperation().whenCompleted(
                () =>
                {
                    test(false);
                },
                (Ice.Exception exc) =>
                {
                    try
                    {
                        throw exc;
                    }
                    catch(Ice.OperationNotExistException ex)
                    {
                        test(ex.operation.Equals("noSuchOperation"));
                    }
                    catch(Exception)
                    {
                        test(false);
                    }
                    cb.called();
                });
            cb.check();
        }

        WriteLine("ok");

        Write("catching unknown local exception with new AMI mapping... ");
        Flush();

        {
            Callback cb = new Callback();
            thrower.begin_throwLocalException().whenCompleted(
                () =>
                {
                    test(false);
                },
                (Ice.Exception exc) =>
                {
                    try
                    {
                        throw exc;
                    }
                    catch(Ice.UnknownLocalException)
                    {
                    }
                    catch(Ice.OperationNotExistException)
                    {
                    }
                    catch(Exception)
                    {
                        test(false);
                    }
                    cb.called();
                });
            cb.check();
        }

        {
            Callback cb = new Callback();
            thrower.begin_throwLocalExceptionIdempotent().whenCompleted(
                () =>
                {
                    test(false);
                },
                (Ice.Exception exc) =>
                {
                    try
                    {
                        throw exc;
                    }
                    catch(Ice.UnknownLocalException)
                    {
                    }
                    catch(Ice.OperationNotExistException)
                    {
                    }
                    catch(Exception)
                    {
                        test(false);
                    }
                    cb.called();
                });
            cb.check();
        }

        WriteLine("ok");

        Write("catching unknown non-Ice exception with new AMI mapping... ");
        Flush();

        {
            Callback cb = new Callback();
            thrower.begin_throwNonIceException().whenCompleted(
                () =>
                {
                    test(false);
                },
                (Ice.Exception exc) =>
                {
                    try
                    {
                        throw exc;
                    }
                    catch(Ice.UnknownException)
                    {
                    }
                    catch(Exception)
                    {
                        test(false);
                    }
                    cb.called();
                });
            cb.check();
        }

        WriteLine("ok");
#if SILVERLIGHT
        thrower.shutdown();
#else
        return thrower;
#endif
    }
Example #8
0
    public static ThrowerPrx allTests(Ice.Communicator communicator, bool collocated)
#endif
    {
#if SILVERLIGHT
        bool collocated = false;
        WriteLine("Ice.FactoryAssemblies: " + communicator.getProperties().getProperty("Ice.FactoryAssemblies"));
#endif

#if !SILVERLIGHT
        {
            Write("testing object adapter registration exceptions... ");
            Ice.ObjectAdapter first;
            try
            {
                first = communicator.createObjectAdapter("TestAdapter0");
            }
            catch (Ice.InitializationException)
            {
                // Expected
            }

            communicator.getProperties().setProperty("TestAdapter0.Endpoints", "default");
            first = communicator.createObjectAdapter("TestAdapter0");
            try
            {
                communicator.createObjectAdapter("TestAdapter0");
                test(false);
            }
            catch (Ice.AlreadyRegisteredException)
            {
                // Expected.
            }

            try
            {
                Ice.ObjectAdapter second =
                    communicator.createObjectAdapterWithEndpoints("TestAdapter0", "ssl -h foo -p 12011");
                test(false);

                //
                // Quell mono error that variable second isn't used.
                //
                second.deactivate();
            }
            catch (Ice.AlreadyRegisteredException)
            {
                // Expected
            }
            first.deactivate();
            WriteLine("ok");
        }

        {
            Write("testing servant registration exceptions... ");
            communicator.getProperties().setProperty("TestAdapter1.Endpoints", "default");
            Ice.ObjectAdapter adapter = communicator.createObjectAdapter("TestAdapter1");
            Ice.Object        obj     = new EmptyI();
            adapter.add(obj, communicator.stringToIdentity("x"));
            try
            {
                adapter.add(obj, communicator.stringToIdentity("x"));
                test(false);
            }
            catch (Ice.AlreadyRegisteredException)
            {
            }

            adapter.remove(communicator.stringToIdentity("x"));
            try
            {
                adapter.remove(communicator.stringToIdentity("x"));
                test(false);
            }
            catch (Ice.NotRegisteredException)
            {
            }
            adapter.deactivate();
            WriteLine("ok");
        }

        {
            Write("testing servant locator registration exceptions... ");
            communicator.getProperties().setProperty("TestAdapter2.Endpoints", "default");
            Ice.ObjectAdapter  adapter = communicator.createObjectAdapter("TestAdapter2");
            Ice.ServantLocator loc     = new ServantLocatorI();
            adapter.addServantLocator(loc, "x");
            try
            {
                adapter.addServantLocator(loc, "x");
                test(false);
            }
            catch (Ice.AlreadyRegisteredException)
            {
            }

            adapter.deactivate();
            WriteLine("ok");
        }
#endif
        {
            Write("testing object factory registration exception... ");
            Ice.ObjectFactory of = new ObjectFactoryI();
            communicator.addObjectFactory(of, "::x");
            try
            {
                communicator.addObjectFactory(of, "::x");
                test(false);
            }
            catch (Ice.AlreadyRegisteredException)
            {
            }
            WriteLine("ok");
        }

        Write("testing stringToProxy... ");
        Flush();
        String        @ref  = "thrower:default -p 12010";
        Ice.ObjectPrx @base = communicator.stringToProxy(@ref);
        test(@base != null);
        WriteLine("ok");

        Write("testing checked cast... ");
        Flush();
        ThrowerPrx thrower = ThrowerPrxHelper.checkedCast(@base);
        test(thrower != null);
        test(thrower.Equals(@base));
        WriteLine("ok");

        Write("catching exact types... ");
        Flush();

        try
        {
            thrower.throwAasA(1);
            test(false);
        }
        catch (A ex)
        {
            test(ex.aMem == 1);
        }
        catch (Exception)
        {
            test(false);
        }

        try
        {
            thrower.throwAorDasAorD(1);
            test(false);
        }
        catch (A ex)
        {
            test(ex.aMem == 1);
        }
        catch (Exception)
        {
            test(false);
        }

        try
        {
            thrower.throwAorDasAorD(-1);
            test(false);
        }
        catch (D ex)
        {
            test(ex.dMem == -1);
        }
        catch (Exception)
        {
            test(false);
        }

        try
        {
            thrower.throwBasB(1, 2);
            test(false);
        }
        catch (B ex)
        {
            test(ex.aMem == 1);
            test(ex.bMem == 2);
        }
        catch (Exception)
        {
            test(false);
        }

        try
        {
            thrower.throwCasC(1, 2, 3);
            test(false);
        }
        catch (C ex)
        {
            test(ex.aMem == 1);
            test(ex.bMem == 2);
            test(ex.cMem == 3);
        }
        catch (Exception)
        {
            test(false);
        }

        WriteLine("ok");

        Write("catching base types... ");
        Flush();

        try
        {
            thrower.throwBasB(1, 2);
            test(false);
        }
        catch (A ex)
        {
            test(ex.aMem == 1);
        }
        catch (Exception)
        {
            test(false);
        }

        try
        {
            thrower.throwCasC(1, 2, 3);
            test(false);
        }
        catch (B ex)
        {
            test(ex.aMem == 1);
            test(ex.bMem == 2);
        }
        catch (Exception)
        {
            test(false);
        }

        WriteLine("ok");

        Write("catching derived types... ");
        Flush();

        try
        {
            thrower.throwBasA(1, 2);
            test(false);
        }
        catch (B ex)
        {
            test(ex.aMem == 1);
            test(ex.bMem == 2);
        }
        catch (Exception)
        {
            test(false);
        }

        try
        {
            thrower.throwCasA(1, 2, 3);
            test(false);
        }
        catch (C ex)
        {
            test(ex.aMem == 1);
            test(ex.bMem == 2);
            test(ex.cMem == 3);
        }
        catch (Exception)
        {
            test(false);
        }

        try
        {
            thrower.throwCasB(1, 2, 3);
            test(false);
        }
        catch (C ex)
        {
            test(ex.aMem == 1);
            test(ex.bMem == 2);
            test(ex.cMem == 3);
        }
        catch (Exception)
        {
            test(false);
        }

        WriteLine("ok");

        if (thrower.supportsUndeclaredExceptions())
        {
            Write("catching unknown user exception... ");
            Flush();

            try
            {
                thrower.throwUndeclaredA(1);
                test(false);
            }
            catch (Ice.UnknownUserException)
            {
            }
            catch (Exception)
            {
                test(false);
            }

            try
            {
                thrower.throwUndeclaredB(1, 2);
                test(false);
            }
            catch (Ice.UnknownUserException)
            {
            }
            catch (Exception)
            {
                test(false);
            }

            try
            {
                thrower.throwUndeclaredC(1, 2, 3);
                test(false);
            }
            catch (Ice.UnknownUserException)
            {
            }
            catch (Exception)
            {
                test(false);
            }

            WriteLine("ok");
        }

        Write("testing memory limit marshal exception...");
        Flush();
        {
            try
            {
                thrower.throwMemoryLimitException(null);
                test(collocated);
            }
            catch (Ice.UnknownLocalException)
            {
            }
            catch (Exception)
            {
                test(false);
            }

            try
            {
                thrower.throwMemoryLimitException(new byte[20 * 1024]); // 20KB
                test(collocated);
            }
            catch (Ice.MemoryLimitException)
            {
            }
            catch (Exception)
            {
                test(false);
            }

            if (!collocated)
            {
                try
                {
                    thrower.end_throwMemoryLimitException(
                        thrower.begin_throwMemoryLimitException(new byte[20 * 1024])); // 20KB
                    test(false);
                }
                catch (Ice.MemoryLimitException)
                {
                }
                catch (Exception)
                {
                    test(false);
                }
            }
        }
        WriteLine("ok");

        Write("catching object not exist exception... ");
        Flush();

        {
            Ice.Identity id = communicator.stringToIdentity("does not exist");
            try
            {
                ThrowerPrx thrower2 = ThrowerPrxHelper.uncheckedCast(thrower.ice_identity(id));
                thrower2.ice_ping();
                test(false);
            }
            catch (Ice.ObjectNotExistException ex)
            {
                test(ex.id.Equals(id));
            }
            catch (Exception)
            {
                test(false);
            }
        }

        WriteLine("ok");

        Write("catching facet not exist exception... ");
        Flush();

        try
        {
            ThrowerPrx thrower2 = ThrowerPrxHelper.uncheckedCast(thrower, "no such facet");
            try
            {
                thrower2.ice_ping();
                test(false);
            }
            catch (Ice.FacetNotExistException ex)
            {
                test(ex.facet.Equals("no such facet"));
            }
        }
        catch (Exception)
        {
            test(false);
        }

        WriteLine("ok");

        Write("catching operation not exist exception... ");
        Flush();

        try
        {
            WrongOperationPrx thrower2 = WrongOperationPrxHelper.uncheckedCast(thrower);
            thrower2.noSuchOperation();
            test(false);
        }
        catch (Ice.OperationNotExistException ex)
        {
            test(ex.operation.Equals("noSuchOperation"));
        }
        catch (Exception)
        {
            test(false);
        }

        WriteLine("ok");

        Write("catching unknown local exception... ");
        Flush();

        try
        {
            thrower.throwLocalException();
            test(false);
        }
        catch (Ice.UnknownLocalException)
        {
        }
        catch (Exception)
        {
            test(false);
        }
        try
        {
            thrower.throwLocalExceptionIdempotent();
            test(false);
        }
        catch (Ice.UnknownLocalException)
        {
        }
        catch (Ice.OperationNotExistException)
        {
        }
        catch (Exception)
        {
            test(false);
        }

        WriteLine("ok");

        Write("catching unknown non-Ice exception... ");
        Flush();

        try
        {
            thrower.throwNonIceException();
            test(false);
        }
        catch (Ice.UnknownException)
        {
        }
        catch (System.Exception)
        {
            test(false);
        }

        WriteLine("ok");

        Write("testing asynchronous exceptions... ");
        Flush();

        try
        {
            thrower.throwAfterResponse();
        }
        catch (Exception)
        {
            test(false);
        }

        try
        {
            thrower.throwAfterException();
            test(false);
        }
        catch (A)
        {
        }
        catch (Exception)
        {
            test(false);
        }

        WriteLine("ok");

        if (!collocated)
        {
            Write("catching exact types with AMI... ");
            Flush();

            {
                AMI_Thrower_throwAasAI cb = new AMI_Thrower_throwAasAI();
                thrower.throwAasA_async(cb, 1);
                cb.check();
            }

            {
                AMI_Thrower_throwAorDasAorDI cb = new AMI_Thrower_throwAorDasAorDI();
                thrower.throwAorDasAorD_async(cb, 1);
                cb.check();
            }

            {
                AMI_Thrower_throwAorDasAorDI cb = new AMI_Thrower_throwAorDasAorDI();
                thrower.throwAorDasAorD_async(cb, -1);
                cb.check();
            }

            {
                AMI_Thrower_throwBasBI cb = new AMI_Thrower_throwBasBI();
                thrower.throwBasB_async(cb, 1, 2);
                cb.check();
            }

            {
                AMI_Thrower_throwCasCI cb = new AMI_Thrower_throwCasCI();
                thrower.throwCasC_async(cb, 1, 2, 3);
                cb.check();
            }

            WriteLine("ok");

            Write("catching derived types... ");
            Flush();

            {
                AMI_Thrower_throwBasAI cb = new AMI_Thrower_throwBasAI();
                thrower.throwBasA_async(cb, 1, 2);
                cb.check();
            }

            {
                AMI_Thrower_throwCasAI cb = new AMI_Thrower_throwCasAI();
                thrower.throwCasA_async(cb, 1, 2, 3);
                cb.check();
            }

            {
                AMI_Thrower_throwCasBI cb = new AMI_Thrower_throwCasBI();
                thrower.throwCasB_async(cb, 1, 2, 3);
                cb.check();
            }

            WriteLine("ok");

            if (thrower.supportsUndeclaredExceptions())
            {
                Write("catching unknown user exception with AMI... ");
                Flush();

                {
                    AMI_Thrower_throwUndeclaredAI cb = new AMI_Thrower_throwUndeclaredAI();
                    thrower.throwUndeclaredA_async(cb, 1);
                    cb.check();
                }

                {
                    AMI_Thrower_throwUndeclaredBI cb = new AMI_Thrower_throwUndeclaredBI();
                    thrower.throwUndeclaredB_async(cb, 1, 2);
                    cb.check();
                }

                {
                    AMI_Thrower_throwUndeclaredCI cb = new AMI_Thrower_throwUndeclaredCI();
                    thrower.throwUndeclaredC_async(cb, 1, 2, 3);
                    cb.check();
                }

                WriteLine("ok");
            }

            Write("catching object not exist exception with AMI... ");
            Flush();

            {
                Ice.Identity id       = communicator.stringToIdentity("does not exist");
                ThrowerPrx   thrower2 = ThrowerPrxHelper.uncheckedCast(thrower.ice_identity(id));
                AMI_Thrower_throwAasAObjectNotExistI cb = new AMI_Thrower_throwAasAObjectNotExistI(communicator);
                thrower2.throwAasA_async(cb, 1);
                cb.check();
            }

            WriteLine("ok");

            Write("catching facet not exist exception with AMI... ");
            Flush();

            try
            {
                ThrowerPrx thrower2 = ThrowerPrxHelper.uncheckedCast(thrower, "no such facet");
                {
                    AMI_Thrower_throwAasAFacetNotExistI cb = new AMI_Thrower_throwAasAFacetNotExistI();
                    thrower2.throwAasA_async(cb, 1);
                    cb.check();
                }
            }
            catch (Exception)
            {
                test(false);
            }

            WriteLine("ok");

            Write("catching operation not exist exception with AMI... ");
            Flush();

            {
                AMI_WrongOperation_noSuchOperationI cb = new AMI_WrongOperation_noSuchOperationI();
                WrongOperationPrx thrower2             = WrongOperationPrxHelper.uncheckedCast(thrower);
                thrower2.noSuchOperation_async(cb);
                cb.check();
            }

            WriteLine("ok");

            Write("catching unknown local exception with AMI... ");
            Flush();

            {
                AMI_Thrower_throwLocalExceptionI cb = new AMI_Thrower_throwLocalExceptionI();
                thrower.throwLocalException_async(cb);
                cb.check();
            }

            WriteLine("ok");

            Write("catching unknown non-Ice exception with AMI... ");
            Flush();

            AMI_Thrower_throwNonIceExceptionI cb2 = new AMI_Thrower_throwNonIceExceptionI();
            thrower.throwNonIceException_async(cb2);
            cb2.check();

            WriteLine("ok");

            Write("catching exact types with new AMI mapping... ");
            Flush();

            {
                AsyncCallback cb3 = new AsyncCallback();
                thrower.begin_throwAasA(1).whenCompleted(cb3.response, cb3.exception_AasA);
                cb3.check();
            }

            {
                AsyncCallback cb3 = new AsyncCallback();
                thrower.begin_throwAorDasAorD(1).whenCompleted(cb3.response, cb3.exception_AorDasAorD);
                cb3.check();
            }

            {
                AsyncCallback cb3 = new AsyncCallback();
                thrower.begin_throwAorDasAorD(-1).whenCompleted(cb3.response, cb3.exception_AorDasAorD);
                cb3.check();
            }

            {
                AsyncCallback cb3 = new AsyncCallback();
                thrower.begin_throwBasB(1, 2).whenCompleted(cb3.response, cb3.exception_BasB);
                cb3.check();
            }

            {
                AsyncCallback cb3 = new AsyncCallback();
                thrower.begin_throwCasC(1, 2, 3).whenCompleted(cb3.response, cb3.exception_CasC);
                cb3.check();
            }

            WriteLine("ok");

            Write("catching derived types with new AMI mapping... ");
            Flush();

            {
                AsyncCallback cb3 = new AsyncCallback();
                thrower.begin_throwBasA(1, 2).whenCompleted(cb3.response, cb3.exception_BasA);
                cb3.check();
            }

            {
                AsyncCallback cb3 = new AsyncCallback();
                thrower.begin_throwCasA(1, 2, 3).whenCompleted(cb3.response, cb3.exception_CasA);
                cb3.check();
            }

            {
                AsyncCallback cb3 = new AsyncCallback();
                thrower.begin_throwCasB(1, 2, 3).whenCompleted(cb3.response, cb3.exception_CasB);
                cb3.check();
            }

            WriteLine("ok");

            if (thrower.supportsUndeclaredExceptions())
            {
                Write("catching unknown user exception with new AMI mapping... ");
                Flush();

                {
                    AsyncCallback cb3 = new AsyncCallback();
                    thrower.begin_throwUndeclaredA(1).whenCompleted(cb3.response, cb3.exception_UndeclaredA);
                    cb3.check();
                }

                {
                    AsyncCallback cb3 = new AsyncCallback();
                    thrower.begin_throwUndeclaredB(1, 2).whenCompleted(cb3.response, cb3.exception_UndeclaredB);
                    cb3.check();
                }

                {
                    AsyncCallback cb3 = new AsyncCallback();
                    thrower.begin_throwUndeclaredC(1, 2, 3).whenCompleted(cb3.response, cb3.exception_UndeclaredC);
                    cb3.check();
                }

                WriteLine("ok");
            }

            Write("catching object not exist exception with new AMI mapping... ");
            Flush();

            {
                Ice.Identity  id       = communicator.stringToIdentity("does not exist");
                ThrowerPrx    thrower2 = ThrowerPrxHelper.uncheckedCast(thrower.ice_identity(id));
                AsyncCallback cb3      = new AsyncCallback(communicator);
                thrower2.begin_throwAasA(1).whenCompleted(cb3.response, cb3.exception_AasAObjectNotExist);
                cb3.check();
            }

            WriteLine("ok");

            Write("catching facet not exist exception with new AMI mapping... ");
            Flush();

            {
                ThrowerPrx    thrower2 = ThrowerPrxHelper.uncheckedCast(thrower, "no such facet");
                AsyncCallback cb3      = new AsyncCallback();
                thrower2.begin_throwAasA(1).whenCompleted(cb3.response, cb3.exception_AasAFacetNotExist);
                cb3.check();
            }

            WriteLine("ok");

            Write("catching operation not exist exception with new AMI mapping... ");
            Flush();

            {
                AsyncCallback     cb3      = new AsyncCallback();
                WrongOperationPrx thrower4 = WrongOperationPrxHelper.uncheckedCast(thrower);
                thrower4.begin_noSuchOperation().whenCompleted(cb3.response, cb3.exception_noSuchOperation);
                cb3.check();
            }

            WriteLine("ok");

            Write("catching unknown local exception with new AMI mapping... ");
            Flush();

            {
                AsyncCallback cb3 = new AsyncCallback();
                thrower.begin_throwLocalException().whenCompleted(cb3.response, cb3.exception_LocalException);
                cb3.check();
            }

            {
                AsyncCallback cb3 = new AsyncCallback();
                thrower.begin_throwLocalExceptionIdempotent().whenCompleted(cb3.response, cb3.exception_LocalException);
                cb3.check();
            }

            WriteLine("ok");

            Write("catching unknown non-Ice exception with new AMI mapping... ");
            Flush();

            {
                AsyncCallback cb3 = new AsyncCallback();
                thrower.begin_throwNonIceException().whenCompleted(cb3.response, cb3.exception_NonIceException);
                cb3.check();
            }

            WriteLine("ok");
        }
#if SILVERLIGHT
        thrower.shutdown();
#else
        return(thrower);
#endif
    }
Example #9
0
    public static ThrowerPrx allTests(TestCommon.Application app)
    {
        Ice.Communicator communicator = app.communicator();
        {
            Write("testing object adapter registration exceptions... ");
            Ice.ObjectAdapter first;
            try
            {
                first = communicator.createObjectAdapter("TestAdapter0");
            }
            catch (Ice.InitializationException)
            {
                // Expected
            }

            communicator.getProperties().setProperty("TestAdapter0.Endpoints", "tcp -h *");
            first = communicator.createObjectAdapter("TestAdapter0");
            try
            {
                communicator.createObjectAdapter("TestAdapter0");
                test(false);
            }
            catch (Ice.AlreadyRegisteredException)
            {
                // Expected.
            }

            try
            {
                Ice.ObjectAdapter second =
                    communicator.createObjectAdapterWithEndpoints("TestAdapter0", "ssl -h foo -p 12011");
                test(false);

                //
                // Quell mono error that variable second isn't used.
                //
                second.deactivate();
            }
            catch (Ice.AlreadyRegisteredException)
            {
                // Expected
            }
            first.deactivate();
            WriteLine("ok");
        }

        {
            Write("testing servant registration exceptions... ");
            communicator.getProperties().setProperty("TestAdapter1.Endpoints", "tcp -h *");
            Ice.ObjectAdapter adapter = communicator.createObjectAdapter("TestAdapter1");
            Ice.Object        obj     = new EmptyI();
            adapter.add(obj, Ice.Util.stringToIdentity("x"));
            try
            {
                adapter.add(obj, Ice.Util.stringToIdentity("x"));
                test(false);
            }
            catch (Ice.AlreadyRegisteredException)
            {
            }

            try
            {
                adapter.add(obj, Ice.Util.stringToIdentity(""));
                test(false);
            }
            catch (Ice.IllegalIdentityException e)
            {
                test(e.id.name.Equals(""));
            }

            try
            {
                adapter.add(null, Ice.Util.stringToIdentity("x"));
                test(false);
            }
            catch (Ice.IllegalServantException)
            {
            }

            adapter.remove(Ice.Util.stringToIdentity("x"));
            try
            {
                adapter.remove(Ice.Util.stringToIdentity("x"));
                test(false);
            }
            catch (Ice.NotRegisteredException)
            {
            }
            adapter.deactivate();
            WriteLine("ok");
        }

        {
            Write("testing servant locator registration exceptions... ");
            communicator.getProperties().setProperty("TestAdapter2.Endpoints", "tcp -h *");
            Ice.ObjectAdapter  adapter = communicator.createObjectAdapter("TestAdapter2");
            Ice.ServantLocator loc     = new ServantLocatorI();
            adapter.addServantLocator(loc, "x");
            try
            {
                adapter.addServantLocator(loc, "x");
                test(false);
            }
            catch (Ice.AlreadyRegisteredException)
            {
            }

            adapter.deactivate();
            WriteLine("ok");
        }

        {
            Write("testing object factory registration exception... ");
            communicator.getValueFactoryManager().add(_ => { return(null); }, "::x");
            try
            {
                communicator.getValueFactoryManager().add(_ => { return(null); }, "::x");
                test(false);
            }
            catch (Ice.AlreadyRegisteredException)
            {
            }
            WriteLine("ok");
        }

        Write("testing stringToProxy... ");
        Flush();
        String @ref = "thrower:" + app.getTestEndpoint(0);

        Ice.ObjectPrx @base = communicator.stringToProxy(@ref);
        test(@base != null);
        WriteLine("ok");

        Write("testing checked cast... ");
        Flush();
        ThrowerPrx thrower = ThrowerPrxHelper.checkedCast(@base);

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

        Write("catching exact types... ");
        Flush();

        try
        {
            thrower.throwAasA(1);
            test(false);
        }
        catch (A ex)
        {
            test(ex.aMem == 1);
        }
        catch (Exception ex)
        {
            System.Console.WriteLine(ex);
            test(false);
        }

        try
        {
            thrower.throwAorDasAorD(1);
            test(false);
        }
        catch (A ex)
        {
            test(ex.aMem == 1);
        }
        catch (Exception)
        {
            test(false);
        }

        try
        {
            thrower.throwAorDasAorD(-1);
            test(false);
        }
        catch (D ex)
        {
            test(ex.dMem == -1);
        }
        catch (Exception)
        {
            test(false);
        }

        try
        {
            thrower.throwBasB(1, 2);
            test(false);
        }
        catch (B ex)
        {
            test(ex.aMem == 1);
            test(ex.bMem == 2);
        }
        catch (Exception)
        {
            test(false);
        }

        try
        {
            thrower.throwCasC(1, 2, 3);
            test(false);
        }
        catch (C ex)
        {
            test(ex.aMem == 1);
            test(ex.bMem == 2);
            test(ex.cMem == 3);
        }
        catch (Exception)
        {
            test(false);
        }

        WriteLine("ok");

        Write("catching base types... ");
        Flush();

        try
        {
            thrower.throwBasB(1, 2);
            test(false);
        }
        catch (A ex)
        {
            test(ex.aMem == 1);
        }
        catch (Exception)
        {
            test(false);
        }

        try
        {
            thrower.throwCasC(1, 2, 3);
            test(false);
        }
        catch (B ex)
        {
            test(ex.aMem == 1);
            test(ex.bMem == 2);
        }
        catch (Exception)
        {
            test(false);
        }

        WriteLine("ok");

        Write("catching derived types... ");
        Flush();

        try
        {
            thrower.throwBasA(1, 2);
            test(false);
        }
        catch (B ex)
        {
            test(ex.aMem == 1);
            test(ex.bMem == 2);
        }
        catch (Exception)
        {
            test(false);
        }

        try
        {
            thrower.throwCasA(1, 2, 3);
            test(false);
        }
        catch (C ex)
        {
            test(ex.aMem == 1);
            test(ex.bMem == 2);
            test(ex.cMem == 3);
        }
        catch (Exception)
        {
            test(false);
        }

        try
        {
            thrower.throwCasB(1, 2, 3);
            test(false);
        }
        catch (C ex)
        {
            test(ex.aMem == 1);
            test(ex.bMem == 2);
            test(ex.cMem == 3);
        }
        catch (Exception)
        {
            test(false);
        }

        WriteLine("ok");

        if (thrower.supportsUndeclaredExceptions())
        {
            Write("catching unknown user exception... ");
            Flush();

            try
            {
                thrower.throwUndeclaredA(1);
                test(false);
            }
            catch (Ice.UnknownUserException)
            {
            }
            catch (Exception)
            {
                test(false);
            }

            try
            {
                thrower.throwUndeclaredB(1, 2);
                test(false);
            }
            catch (Ice.UnknownUserException)
            {
            }
            catch (Exception)
            {
                test(false);
            }

            try
            {
                thrower.throwUndeclaredC(1, 2, 3);
                test(false);
            }
            catch (Ice.UnknownUserException)
            {
            }
            catch (Exception)
            {
                test(false);
            }

            WriteLine("ok");
        }

        if (thrower.ice_getConnection() != null)
        {
            Write("testing memory limit marshal exception...");
            Flush();
            try
            {
                thrower.throwMemoryLimitException(null);
                test(false);
            }
            catch (Ice.MemoryLimitException)
            {
            }
            catch (Exception)
            {
                test(false);
            }

            try
            {
                thrower.throwMemoryLimitException(new byte[20 * 1024]); // 20KB
                test(false);
            }
            catch (Ice.ConnectionLostException)
            {
            }
            catch (Ice.UnknownLocalException)
            {
                // Expected with JS bidir server
            }
            catch (Exception)
            {
                test(false);
            }

            try
            {
                ThrowerPrx thrower2 = ThrowerPrxHelper.uncheckedCast(
                    communicator.stringToProxy("thrower:" + app.getTestEndpoint(1)));
                try
                {
                    thrower2.throwMemoryLimitException(new byte[2 * 1024 * 1024]); // 2MB (no limits)
                }
                catch (Ice.MemoryLimitException)
                {
                }
                ThrowerPrx thrower3 = ThrowerPrxHelper.uncheckedCast(
                    communicator.stringToProxy("thrower:" + app.getTestEndpoint(2)));
                try
                {
                    thrower3.throwMemoryLimitException(new byte[1024]); // 1KB limit
                    test(false);
                }
                catch (Ice.ConnectionLostException)
                {
                }
                catch (Ice.ConnectionTimeoutException)
                {
                    // TODO: WORKAROUND for ICE-8118, it some takes 2 minutes to get the ReceivedAsync completed
                    // callback when the connection is forcefully closed by the server. It appears to be an issue
                    // with .NET.
                }
            }
            catch (Ice.ConnectionRefusedException)
            {
                // Expected with JS bidir server
            }

            WriteLine("ok");
        }

        Write("catching object not exist exception... ");
        Flush();

        {
            Ice.Identity id = Ice.Util.stringToIdentity("does not exist");
            try
            {
                ThrowerPrx thrower2 = ThrowerPrxHelper.uncheckedCast(thrower.ice_identity(id));
                thrower2.ice_ping();
                test(false);
            }
            catch (Ice.ObjectNotExistException ex)
            {
                test(ex.id.Equals(id));
            }
            catch (Exception)
            {
                test(false);
            }
        }

        WriteLine("ok");

        Write("catching facet not exist exception... ");
        Flush();

        try
        {
            ThrowerPrx thrower2 = ThrowerPrxHelper.uncheckedCast(thrower, "no such facet");
            try
            {
                thrower2.ice_ping();
                test(false);
            }
            catch (Ice.FacetNotExistException ex)
            {
                test(ex.facet.Equals("no such facet"));
            }
        }
        catch (Exception)
        {
            test(false);
        }

        WriteLine("ok");

        Write("catching operation not exist exception... ");
        Flush();

        try
        {
            WrongOperationPrx thrower2 = WrongOperationPrxHelper.uncheckedCast(thrower);
            thrower2.noSuchOperation();
            test(false);
        }
        catch (Ice.OperationNotExistException ex)
        {
            test(ex.operation.Equals("noSuchOperation"));
        }
        catch (Exception)
        {
            test(false);
        }

        WriteLine("ok");

        Write("catching unknown local exception... ");
        Flush();

        try
        {
            thrower.throwLocalException();
            test(false);
        }
        catch (Ice.UnknownLocalException)
        {
        }
        catch (Exception)
        {
            test(false);
        }
        try
        {
            thrower.throwLocalExceptionIdempotent();
            test(false);
        }
        catch (Ice.UnknownLocalException)
        {
        }
        catch (Ice.OperationNotExistException)
        {
        }
        catch (Exception)
        {
            test(false);
        }

        WriteLine("ok");

        Write("catching unknown non-Ice exception... ");
        Flush();

        try
        {
            thrower.throwNonIceException();
            test(false);
        }
        catch (Ice.UnknownException)
        {
        }
        catch (System.Exception)
        {
            test(false);
        }

        WriteLine("ok");

        Write("testing asynchronous exceptions... ");
        Flush();

        try
        {
            thrower.throwAfterResponse();
        }
        catch (Exception)
        {
            test(false);
        }

        try
        {
            thrower.throwAfterException();
            test(false);
        }
        catch (A)
        {
        }
        catch (Exception)
        {
            test(false);
        }

        WriteLine("ok");

        Write("catching exact types with AMI mapping... ");
        Flush();

        {
            Callback cb = new Callback();
            thrower.begin_throwAasA(1).whenCompleted(
                () =>
            {
                test(false);
            },
                (Ice.Exception exc) =>
            {
                test(exc is A);
                A ex = exc as A;
                test(ex.aMem == 1);
                cb.called();
            });
            cb.check();
        }

        {
            Callback cb = new Callback();
            thrower.begin_throwAorDasAorD(1).whenCompleted(
                () =>
            {
                test(false);
            },
                (Ice.Exception exc) =>
            {
                try
                {
                    throw exc;
                }
                catch (A ex)
                {
                    test(ex.aMem == 1);
                }
                catch (D ex)
                {
                    test(ex.dMem == -1);
                }
                catch (Exception)
                {
                    test(false);
                }
                cb.called();
            });
            cb.check();
        }

        {
            Callback cb = new Callback();
            thrower.begin_throwAorDasAorD(-1).whenCompleted(
                () =>
            {
                test(false);
            },
                (Ice.Exception exc) =>
            {
                try
                {
                    throw exc;
                }
                catch (A ex)
                {
                    test(ex.aMem == 1);
                }
                catch (D ex)
                {
                    test(ex.dMem == -1);
                }
                catch (Exception)
                {
                    test(false);
                }
                cb.called();
            });
            cb.check();
        }

        {
            Callback cb = new Callback();
            thrower.begin_throwBasB(1, 2).whenCompleted(
                () =>
            {
                test(false);
            },
                (Ice.Exception exc) =>
            {
                try
                {
                    throw exc;
                }
                catch (B ex)
                {
                    test(ex.aMem == 1);
                    test(ex.bMem == 2);
                }
                catch (Exception)
                {
                    test(false);
                }
                cb.called();
            });
            cb.check();
        }

        {
            Callback cb = new Callback();
            thrower.begin_throwCasC(1, 2, 3).whenCompleted(
                () =>
            {
                test(false);
            },
                (Ice.Exception exc) =>
            {
                try
                {
                    throw exc;
                }
                catch (C ex)
                {
                    test(ex.aMem == 1);
                    test(ex.bMem == 2);
                    test(ex.cMem == 3);
                }
                catch (Exception)
                {
                    test(false);
                }
                cb.called();
            });
            cb.check();
        }

        WriteLine("ok");

        Write("catching derived types with new AMI mapping... ");
        Flush();

        {
            Callback cb = new Callback();
            thrower.begin_throwBasA(1, 2).whenCompleted(
                () =>
            {
                test(false);
            },
                (Ice.Exception exc) =>
            {
                try
                {
                    throw exc;
                }
                catch (B ex)
                {
                    test(ex.aMem == 1);
                    test(ex.bMem == 2);
                }
                catch (Exception)
                {
                    test(false);
                }
                cb.called();
            });
            cb.check();
        }

        {
            Callback cb = new Callback();
            thrower.begin_throwCasA(1, 2, 3).whenCompleted(
                () =>
            {
                test(false);
            },
                (Ice.Exception exc) =>
            {
                try
                {
                    throw exc;
                }
                catch (C ex)
                {
                    test(ex.aMem == 1);
                    test(ex.bMem == 2);
                    test(ex.cMem == 3);
                }
                catch (Exception)
                {
                    test(false);
                }
                cb.called();
            });
            cb.check();
        }

        {
            Callback cb = new Callback();
            thrower.begin_throwCasB(1, 2, 3).whenCompleted(
                () =>
            {
                test(false);
            },
                (Ice.Exception exc) =>
            {
                try
                {
                    throw exc;
                }
                catch (C ex)
                {
                    test(ex.aMem == 1);
                    test(ex.bMem == 2);
                    test(ex.cMem == 3);
                }
                catch (Exception)
                {
                    test(false);
                }
                cb.called();
            });
            cb.check();
        }

        WriteLine("ok");

        if (thrower.supportsUndeclaredExceptions())
        {
            Write("catching unknown user exception with new AMI mapping... ");
            Flush();

            {
                Callback cb = new Callback();
                thrower.begin_throwUndeclaredA(1).whenCompleted(
                    () =>
                {
                    test(false);
                },
                    (Ice.Exception exc) =>
                {
                    try
                    {
                        throw exc;
                    }
                    catch (Ice.UnknownUserException)
                    {
                    }
                    catch (Exception)
                    {
                        test(false);
                    }
                    cb.called();
                });
                cb.check();
            }

            {
                Callback cb = new Callback();
                thrower.begin_throwUndeclaredB(1, 2).whenCompleted(
                    () =>
                {
                    test(false);
                },
                    (Ice.Exception exc) =>
                {
                    try
                    {
                        throw exc;
                    }
                    catch (Ice.UnknownUserException)
                    {
                    }
                    catch (Exception)
                    {
                        test(false);
                    }
                    cb.called();
                });
                cb.check();
            }

            {
                Callback cb = new Callback();
                thrower.begin_throwUndeclaredC(1, 2, 3).whenCompleted(
                    () =>
                {
                    test(false);
                },
                    (Ice.Exception exc) =>
                {
                    try
                    {
                        throw exc;
                    }
                    catch (Ice.UnknownUserException)
                    {
                    }
                    catch (Exception)
                    {
                        test(false);
                    }
                    cb.called();
                });
                cb.check();
            }

            WriteLine("ok");
        }

        Write("catching object not exist exception with new AMI mapping... ");
        Flush();

        {
            Ice.Identity id       = Ice.Util.stringToIdentity("does not exist");
            ThrowerPrx   thrower2 = ThrowerPrxHelper.uncheckedCast(thrower.ice_identity(id));
            Callback     cb       = new Callback();
            thrower2.begin_throwAasA(1).whenCompleted(
                () =>
            {
                test(false);
            },
                (Ice.Exception exc) =>
            {
                try
                {
                    throw exc;
                }
                catch (Ice.ObjectNotExistException ex)
                {
                    test(ex.id.Equals(id));
                }
                catch (Exception)
                {
                    test(false);
                }
                cb.called();
            });
            cb.check();
        }

        WriteLine("ok");

        Write("catching facet not exist exception with new AMI mapping... ");
        Flush();

        {
            ThrowerPrx thrower2 = ThrowerPrxHelper.uncheckedCast(thrower, "no such facet");
            Callback   cb       = new Callback();
            thrower2.begin_throwAasA(1).whenCompleted(
                () =>
            {
                test(false);
            },
                (Ice.Exception exc) =>
            {
                try
                {
                    throw exc;
                }
                catch (Ice.FacetNotExistException ex)
                {
                    test(ex.facet.Equals("no such facet"));
                }
                catch (Exception)
                {
                    test(false);
                }
                cb.called();
            });
            cb.check();
        }

        WriteLine("ok");

        Write("catching operation not exist exception with new AMI mapping... ");
        Flush();

        {
            Callback          cb       = new Callback();
            WrongOperationPrx thrower4 = WrongOperationPrxHelper.uncheckedCast(thrower);
            thrower4.begin_noSuchOperation().whenCompleted(
                () =>
            {
                test(false);
            },
                (Ice.Exception exc) =>
            {
                try
                {
                    throw exc;
                }
                catch (Ice.OperationNotExistException ex)
                {
                    test(ex.operation.Equals("noSuchOperation"));
                }
                catch (Exception)
                {
                    test(false);
                }
                cb.called();
            });
            cb.check();
        }

        WriteLine("ok");

        Write("catching unknown local exception with new AMI mapping... ");
        Flush();

        {
            Callback cb = new Callback();
            thrower.begin_throwLocalException().whenCompleted(
                () =>
            {
                test(false);
            },
                (Ice.Exception exc) =>
            {
                try
                {
                    throw exc;
                }
                catch (Ice.UnknownLocalException)
                {
                }
                catch (Ice.OperationNotExistException)
                {
                }
                catch (Exception)
                {
                    test(false);
                }
                cb.called();
            });
            cb.check();
        }

        {
            Callback cb = new Callback();
            thrower.begin_throwLocalExceptionIdempotent().whenCompleted(
                () =>
            {
                test(false);
            },
                (Ice.Exception exc) =>
            {
                try
                {
                    throw exc;
                }
                catch (Ice.UnknownLocalException)
                {
                }
                catch (Ice.OperationNotExistException)
                {
                }
                catch (Exception)
                {
                    test(false);
                }
                cb.called();
            });
            cb.check();
        }

        WriteLine("ok");

        Write("catching unknown non-Ice exception with new AMI mapping... ");
        Flush();

        {
            Callback cb = new Callback();
            thrower.begin_throwNonIceException().whenCompleted(
                () =>
            {
                test(false);
            },
                (Ice.Exception exc) =>
            {
                try
                {
                    throw exc;
                }
                catch (Ice.UnknownException)
                {
                }
                catch (Exception)
                {
                    test(false);
                }
                cb.called();
            });
            cb.check();
        }

        WriteLine("ok");

        if (thrower.supportsUndeclaredExceptions())
        {
            Write("catching unknown user exception with new AMI mapping... ");
            Flush();

            {
                Callback cb = new Callback();
                thrower.begin_throwUndeclaredA(1).whenCompleted(
                    () =>
                {
                    test(false);
                },
                    (Ice.Exception exc) =>
                {
                    try
                    {
                        throw exc;
                    }
                    catch (Ice.UnknownUserException)
                    {
                    }
                    catch (Exception)
                    {
                        test(false);
                    }
                    cb.called();
                });
                cb.check();
            }

            {
                Callback cb = new Callback();
                thrower.begin_throwUndeclaredB(1, 2).whenCompleted(
                    () =>
                {
                    test(false);
                },
                    (Ice.Exception exc) =>
                {
                    try
                    {
                        throw exc;
                    }
                    catch (Ice.UnknownUserException)
                    {
                    }
                    catch (Exception)
                    {
                        test(false);
                    }
                    cb.called();
                });
                cb.check();
            }

            {
                Callback cb = new Callback();
                thrower.begin_throwUndeclaredC(1, 2, 3).whenCompleted(
                    () =>
                {
                    test(false);
                },
                    (Ice.Exception exc) =>
                {
                    try
                    {
                        throw exc;
                    }
                    catch (Ice.UnknownUserException)
                    {
                    }
                    catch (Exception)
                    {
                        test(false);
                    }
                    cb.called();
                });
                cb.check();
            }

            WriteLine("ok");
        }

        Write("catching object not exist exception with new AMI mapping... ");
        Flush();

        {
            Ice.Identity id       = Ice.Util.stringToIdentity("does not exist");
            ThrowerPrx   thrower2 = ThrowerPrxHelper.uncheckedCast(thrower.ice_identity(id));
            Callback     cb       = new Callback();
            thrower2.begin_throwAasA(1).whenCompleted(
                () =>
            {
                test(false);
            },
                (Ice.Exception exc) =>
            {
                try
                {
                    throw exc;
                }
                catch (Ice.ObjectNotExistException ex)
                {
                    test(ex.id.Equals(id));
                }
                catch (Exception)
                {
                    test(false);
                }
                cb.called();
            });
            cb.check();
        }

        WriteLine("ok");

        Write("catching facet not exist exception with new AMI mapping... ");
        Flush();

        {
            ThrowerPrx thrower2 = ThrowerPrxHelper.uncheckedCast(thrower, "no such facet");
            Callback   cb       = new Callback();
            thrower2.begin_throwAasA(1).whenCompleted(
                () =>
            {
                test(false);
            },
                (Ice.Exception exc) =>
            {
                try
                {
                    throw exc;
                }
                catch (Ice.FacetNotExistException ex)
                {
                    test(ex.facet.Equals("no such facet"));
                }
                catch (Exception)
                {
                    test(false);
                }
                cb.called();
            });
            cb.check();
        }

        WriteLine("ok");

        Write("catching operation not exist exception with new AMI mapping... ");
        Flush();

        {
            Callback          cb       = new Callback();
            WrongOperationPrx thrower4 = WrongOperationPrxHelper.uncheckedCast(thrower);
            thrower4.begin_noSuchOperation().whenCompleted(
                () =>
            {
                test(false);
            },
                (Ice.Exception exc) =>
            {
                try
                {
                    throw exc;
                }
                catch (Ice.OperationNotExistException ex)
                {
                    test(ex.operation.Equals("noSuchOperation"));
                }
                catch (Exception)
                {
                    test(false);
                }
                cb.called();
            });
            cb.check();
        }

        WriteLine("ok");

        Write("catching unknown local exception with new AMI mapping... ");
        Flush();

        {
            Callback cb = new Callback();
            thrower.begin_throwLocalException().whenCompleted(
                () =>
            {
                test(false);
            },
                (Ice.Exception exc) =>
            {
                try
                {
                    throw exc;
                }
                catch (Ice.UnknownLocalException)
                {
                }
                catch (Ice.OperationNotExistException)
                {
                }
                catch (Exception)
                {
                    test(false);
                }
                cb.called();
            });
            cb.check();
        }

        {
            Callback cb = new Callback();
            thrower.begin_throwLocalExceptionIdempotent().whenCompleted(
                () =>
            {
                test(false);
            },
                (Ice.Exception exc) =>
            {
                try
                {
                    throw exc;
                }
                catch (Ice.UnknownLocalException)
                {
                }
                catch (Ice.OperationNotExistException)
                {
                }
                catch (Exception)
                {
                    test(false);
                }
                cb.called();
            });
            cb.check();
        }

        WriteLine("ok");

        Write("catching unknown non-Ice exception with new AMI mapping... ");
        Flush();

        {
            Callback cb = new Callback();
            thrower.begin_throwNonIceException().whenCompleted(
                () =>
            {
                test(false);
            },
                (Ice.Exception exc) =>
            {
                try
                {
                    throw exc;
                }
                catch (Ice.UnknownException)
                {
                }
                catch (Exception)
                {
                    test(false);
                }
                cb.called();
            });
            cb.check();
        }

        WriteLine("ok");
        return(thrower);
    }