Пример #1
0
    private static int run(string[] args, Ice.Communicator communicator)
    {
        communicator.addValueFactory(MyValueFactory, "::Test::I");
        communicator.addValueFactory(MyValueFactory, "::Test::J");
        communicator.addValueFactory(MyValueFactory, "::Test::H");

        communicator.getProperties().setProperty("TestAdapter.Endpoints", "default -p 12010");
        Ice.ObjectAdapter adapter = communicator.createObjectAdapter("TestAdapter");
        Ice.Object        @object = new InitialI(adapter);
        adapter.add(@object, communicator.stringToIdentity("initial"));
        @object = new UnexpectedObjectExceptionTestI();
        adapter.add(@object, communicator.stringToIdentity("uoet"));
        adapter.activate();
        communicator.waitForShutdown();
        return(0);
    }
Пример #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
    }
Пример #3
0
    public static InitialPrx allTests(Ice.Communicator communicator)
#endif
    {
        communicator.addValueFactory(MyValueFactory, "::Test::B");
        communicator.addValueFactory(MyValueFactory, "::Test::C");
        communicator.addValueFactory(MyValueFactory, "::Test::D");
        communicator.addValueFactory(MyValueFactory, "::Test::E");
        communicator.addValueFactory(MyValueFactory, "::Test::F");
        communicator.addValueFactory(MyValueFactory, "::Test::I");
        communicator.addValueFactory(MyValueFactory, "::Test::J");
        communicator.addValueFactory(MyValueFactory, "::Test::H");

// Disable Obsolete warning/error
#pragma warning disable 612, 618
        communicator.addObjectFactory(new MyObjectFactory(), "TestOF");
#pragma warning restore 612, 618


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

        Write("testing checked cast... ");
        Flush();
        InitialPrx initial = InitialPrxHelper.checkedCast(@base);
        test(initial != null);
        test(initial.Equals(@base));
        WriteLine("ok");

        Write("getting B1... ");
        Flush();
        B b1 = initial.getB1();
        test(b1 != null);
        WriteLine("ok");

        Write("getting B2... ");
        Flush();
        B b2 = initial.getB2();
        test(b2 != null);
        WriteLine("ok");

        Write("getting C... ");
        Flush();
        C c = initial.getC();
        test(c != null);
        WriteLine("ok");

        Write("getting D... ");
        Flush();
        D d = initial.getD();
        test(d != null);
        WriteLine("ok");

        Write("checking consistency... ");
        Flush();
        test(b1 != b2);
        //test(b1 != c);
        //test(b1 != d);
        //test(b2 != c);
        //test(b2 != d);
        //test(c != d);
        test(b1.theB == b1);
        test(b1.theC == null);
        test(b1.theA is B);
        test(((B)b1.theA).theA == b1.theA);
        test(((B)b1.theA).theB == b1);
        //test(((B)b1.theA).theC is C); // Redundant -- theC is always of type C
        test(((C)(((B)b1.theA).theC)).theB == b1.theA);
        test(b1.preMarshalInvoked);
        test(b1.postUnmarshalInvoked());
        test(b1.theA.preMarshalInvoked);
        test(b1.theA.postUnmarshalInvoked());
        test(((B)b1.theA).theC.preMarshalInvoked);
        test(((B)b1.theA).theC.postUnmarshalInvoked());

        // More tests possible for b2 and d, but I think this is already
        // sufficient.
        test(b2.theA == b2);
        test(d.theC == null);
        WriteLine("ok");

        Write("getting B1, B2, C, and D all at once... ");
        Flush();
        B b1out;
        B b2out;
        C cout;
        D dout;
        initial.getAll(out b1out, out b2out, out cout, out dout);
        test(b1out != null);
        test(b2out != null);
        test(cout != null);
        test(dout != null);
        WriteLine("ok");

        Write("checking consistency... ");
        Flush();
        test(b1out != b2out);
        test(b1out.theA == b2out);
        test(b1out.theB == b1out);
        test(b1out.theC == null);
        test(b2out.theA == b2out);
        test(b2out.theB == b1out);
        test(b2out.theC == cout);
        test(cout.theB == b2out);
        test(dout.theA == b1out);
        test(dout.theB == b2out);
        test(dout.theC == null);
        test(dout.preMarshalInvoked);
        test(dout.postUnmarshalInvoked());
        test(dout.theA.preMarshalInvoked);
        test(dout.theA.postUnmarshalInvoked());
        test(dout.theB.preMarshalInvoked);
        test(dout.theB.postUnmarshalInvoked());
        test(dout.theB.theC.preMarshalInvoked);
        test(dout.theB.theC.postUnmarshalInvoked());

        WriteLine("ok");

        Write("testing protected members... ");
        Flush();
        E e = initial.getE();
        test(e.checkValues());
        System.Reflection.BindingFlags flags = System.Reflection.BindingFlags.NonPublic |
                                               System.Reflection.BindingFlags.Public |
                                               System.Reflection.BindingFlags.Instance;
        test(!typeof(E).GetField("i", flags).IsPublic&& !typeof(E).GetField("i", flags).IsPrivate);
        test(!typeof(E).GetField("s", flags).IsPublic&& !typeof(E).GetField("s", flags).IsPrivate);
        F f = initial.getF();
        test(f.checkValues());
        test(f.e2.checkValues());
        test(!typeof(F).GetField("e1", flags).IsPublic&& !typeof(F).GetField("e1", flags).IsPrivate);
        test(typeof(F).GetField("e2", flags).IsPublic&& !typeof(F).GetField("e2", flags).IsPrivate);
        WriteLine("ok");

        Write("getting I, J and H... ");
        Flush();
        I i = initial.getI();
        test(i != null);
        I j = initial.getJ();
        test(j != null && ((J)j) != null);
        I h = initial.getH();
        test(h != null && ((H)h) != null);
        WriteLine("ok");

        Write("getting D1... ");
        Flush();
        D1 d1 = new D1(new A1("a1"), new A1("a2"), new A1("a3"), new A1("a4"));
        d1 = initial.getD1(d1);
        test(d1.a1.name.Equals("a1"));
        test(d1.a2.name.Equals("a2"));
        test(d1.a3.name.Equals("a3"));
        test(d1.a4.name.Equals("a4"));
        WriteLine("ok");

        Write("throw EDerived... ");
        Flush();
        try
        {
            initial.throwEDerived();
            test(false);
        }
        catch (EDerived ederived)
        {
            test(ederived.a1.name.Equals("a1"));
            test(ederived.a2.name.Equals("a2"));
            test(ederived.a3.name.Equals("a3"));
            test(ederived.a4.name.Equals("a4"));
        }
        WriteLine("ok");

        Write("setting I... ");
        Flush();
        initial.setI(i);
        initial.setI(j);
        initial.setI(h);
        WriteLine("ok");

        Write("testing sequences...");
        Flush();
        try
        {
            Base[] inS = new Base[0];
            Base[] outS;
            Base[] retS;
            retS = initial.opBaseSeq(inS, out outS);

            inS    = new Base[1];
            inS[0] = new Base(new S(), "");
            retS   = initial.opBaseSeq(inS, out outS);
            test(retS.Length == 1 && outS.Length == 1);
        }
        catch (Ice.OperationNotExistException)
        {
        }
        WriteLine("ok");

        Write("testing compact ID...");
        Flush();
        try
        {
            test(initial.getCompact() != null);
        }
        catch (Ice.OperationNotExistException)
        {
        }
        WriteLine("ok");

        Write("testing UnexpectedObjectException...");
        Flush();
        @ref  = "uoet:default -p 12010";
        @base = communicator.stringToProxy(@ref);
        test(@base != null);
        UnexpectedObjectExceptionTestPrx uoet = UnexpectedObjectExceptionTestPrxHelper.uncheckedCast(@base);
        test(uoet != null);
        try
        {
            uoet.op();
            test(false);
        }
        catch (Ice.UnexpectedObjectException ex)
        {
            test(ex.type.Equals("::Test::AlsoEmpty"));
            test(ex.expectedType.Equals("::Test::Empty"));
        }
        catch (System.Exception ex)
        {
            WriteLine(ex.ToString());
            test(false);
        }
        WriteLine("ok");

// Disable Obsolete warning/error
#pragma warning disable 612, 618
        Write("testing getting ObjectFactory...");
        Flush();
        test(communicator.findObjectFactory("TestOF") != null);
        WriteLine("ok");
        Write("testing getting ObjectFactory as ValueFactory...");
        Flush();
        test(communicator.findValueFactory("TestOF") != null);
        WriteLine("ok");
#pragma warning restore 612, 618

#if SILVERLIGHT
        initial.shutdown();
#else
        return(initial);
#endif
    }