Пример #1
0
        /// <summary>
        /// Connect to ICE interface on running Murmur server
        /// </summary>
        /// <param name="address">murmur server address</param>
        /// <param name="port">ice port</param>
        /// <param name="secret">ice password</param>
        /// <param name="timeout"></param>
        /// <returns>object of murmur server</returns>
        public MetaPrx Connect(string address, int port, string secret, string callbackAddress = "127.0.0.1", int callbackPort = 0, int timeout = 1000)
        {
            this.timeout = timeout;

            // initialize
            run(new string[] { });

            ic = Ice.Util.initialize(_data);

            // set ice secret
            if (!string.IsNullOrEmpty(secret))
            {
                ic.getImplicitContext().put("secret", secret);
            }

            try
            {
                var connectionString = string.Format("Meta:tcp -h {0} -p {1} -t {2}", address, port, timeout);

                // Create a proxy
                var obj = ic.stringToProxy(connectionString);

                // Tests whether the target object of this proxy can be reached.
                obj.ice_ping();

                // initialize metadata of murmur server
                _meta = MetaPrxHelper.uncheckedCast(obj);


                var portString         = (callbackPort > 0) ? string.Format("-p {0}", callbackPort) : "";
                var connectionStringCB = string.Format("tcp -h {0} {1} -t {2}", callbackAddress, portString, timeout);

                // Create the callback adapter
                ic.getProperties().setProperty("Ice.PrintAdapterReady", "0");
                _adapter = ic.createObjectAdapterWithEndpoints("Callback.Client", connectionStringCB);
                _adapter.activate();

                _meta.ice_ping();
            }
            catch (System.Exception e)
            {
                Console.WriteLine(e.ToString());
                throw new MurmurPlugin.ConnectionRefusedException();
            }

            // FIXME: check for valid ice secret, because getLogLen() is working only if "icesecretwrite" is valid
            //  (there a secure hole - get methods allowed if "icesecretread" is not set)
            //  if secret is invalid it throws UnmarshalOutOfBoundsException();
            try
            {
                // set allowhtml property to the server to check ice writesecret
                _meta.getAllServers()[0].setConf("allowhtml", "true");
            }
            catch
            {
                throw new MurmurPlugin.InvalidSecretException();
            }

            return(_meta);
        }
Пример #2
0
        private void btndynamicDetect_Click(object sender, RoutedEventArgs e)
        {
            //回调EndPoint的写法
            //1."default -h 192.168.1.116 -p 9991"
            //2."default"
            string endpoints = "default -h 192.168.1.116 -p 9991";

            callbackAdapter = ic.createObjectAdapterWithEndpoints("callback-client", endpoints);

            Ice.Object servant = new ClientCallbackI(Item);
            callbackAdapter.add(servant, ic.stringToIdentity("callbackReceiver"));
            callbackAdapter.activate();

            ClientCallbackReceiverPrx receiverPrx = null;

            Ice.Identity identity = ic.stringToIdentity("callbackReceiver");
            //代理一定要通过adapter对象创建
            Ice.ObjectPrx pxy = callbackAdapter.createProxy(identity);
            receiverPrx = ClientCallbackReceiverPrxHelper.uncheckedCast(pxy);


            var result = facePxy.dynamicDetect("rtspPath", receiverPrx, 0.4f, 100, 4);

            lbResult.Items.Clear();
            Item("code:" + result.code);
            Item("message:" + result.message);
        }
Пример #3
0
 /// <summary>
 /// 启动服务
 /// </summary>
 /// <param name="iceObj"></param>
 /// <param name="port"></param>
 /// <returns></returns>
 public static bool Start(Ice.Object iceObj, int port = 10000)
 {
     if (iceObj == null)
     {
         throw new ApplicationException("Invalid obj");
     }
     if (run == false)
     {
         Ice.Communicator ic = null;
         //初始化Ice runtime ,将args传递给这个调用,是因为服务器可能
         //有run time感兴趣的命令行参数,返回的是一个Ice.Communicator
         //它是Ice run time的主句柄
         ic = Ice.Util.initialize();
         //调用createObjectAdapterWithEndpoints创建一个对象适配器,传入的参数为SimplePrinter(适配器名称)
         //和default -p 10000或者是适配器使用缺省协议TCP/IP在端口10000侦听到来的请求
         Ice.ObjectAdapter adapter = ic.createObjectAdapterWithEndpoints("SimplePrinter", "default -p " + port);
         //这时,服务器端run time 已经初始化,我们实例化一个PrinterI 对
         //象,为我们的Printer 接口创建一个servant。
         //Ice.Object obj = new PrinterI();
         //我们调用适配器的add,告诉它有了一个新的servant ;传给add 的参
         //数是我们刚才实例化的servant,再加上一个标识符。在这里,
         //"SimplePrinter" 串是servant 的名字(如果我们有多个打印机,每个
         //打印机都会有不同的名字,更正确的说法是,都会有不同的对象标识)。
         adapter.add(iceObj, Ice.Util.stringToIdentity("SimplePrinter"));
         //我们调用适配器的activate 方法激活适配器(适配器一开
         //始是在扣留(holding)状态创建的;这种做法在下面这样的情况下很
         //有用:如果我们有多个servant,它们共享同一个适配器,而在所有
         //servant 实例化之前我们不想处理请求)。一旦适配器被激活,服务器就
         //会开始处理来自客户的请求。
         adapter.activate();
         run = true;
     }
     return(run);
 }
Пример #4
0
        public async Task Connect(string[] args)
        {
            await Task.Yield();

            communicator = Ice.Util.initialize(ref args);
            Ice.Identity id    = new Ice.Identity();
            var          proxy = communicator.stringToProxy("Server:default -h localhost -p 10000");

            _server = ServerPrxHelper.checkedCast(proxy);
            adapter = communicator.createObjectAdapterWithEndpoints("TreeDiagramClient", "default -p 10008");
            adapter.activate();
            serverEvent = ServerEventPrxHelper.uncheckedCast(
                adapter.addWithUUID(
                    lib.Provider.serviceProvider.GetRequiredService <lib.IceBridge.ServerEvent>()));
            _server.initEvent(uuid, serverEvent);
        }
Пример #5
0
 public static int Main(string[] args)
 {
     try
     {
         using (Ice.Communicator communicator = Ice.Util.initialize(ref args))
         {
             var adapter =
                 communicator.createObjectAdapterWithEndpoints("SimplePrinterAdapter",
                                                               "default -h localhost -p 10000");
             adapter.add(new PrinterI(), Ice.Util.stringToIdentity("SimplePrinter"));
             adapter.activate();
             communicator.waitForShutdown();
         }
     }
     catch (System.Exception ex)
     {
         Console.Error.WriteLine(ex);
         return(1);
     }
     return(0);
 }
Пример #6
0
    public static ThrowerPrx allTests(Ice.Communicator communicator)
    {
        {
            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");
        }

        {
            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: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");
        return(thrower);
    }
Пример #7
0
    public static void allTests(TestCommon.Application app)
    {
        Ice.Communicator communicator = app.communicator();
        ServerManagerPrx manager      = ServerManagerPrxHelper.checkedCast(
            communicator.stringToProxy("ServerManager :" + app.getTestEndpoint(0)));

        test(manager != null);
        TestLocatorPrx locator = TestLocatorPrxHelper.uncheckedCast(communicator.getDefaultLocator());

        test(locator != null);
        TestLocatorRegistryPrx registry = TestLocatorRegistryPrxHelper.checkedCast(locator.getRegistry());

        test(registry != null);

        Write("testing stringToProxy... ");
        Flush();
        Ice.ObjectPrx @base = communicator.stringToProxy("test @ TestAdapter");
        Ice.ObjectPrx base2 = communicator.stringToProxy("test @ TestAdapter");
        Ice.ObjectPrx base3 = communicator.stringToProxy("test");
        Ice.ObjectPrx base4 = communicator.stringToProxy("ServerManager");
        Ice.ObjectPrx base5 = communicator.stringToProxy("test2");
        Ice.ObjectPrx base6 = communicator.stringToProxy("test @ ReplicatedAdapter");
        WriteLine("ok");

        Write("testing ice_locator and ice_getLocator... ");
        test(Ice.Util.proxyIdentityCompare(@base.ice_getLocator(), communicator.getDefaultLocator()) == 0);
        Ice.LocatorPrx anotherLocator =
            Ice.LocatorPrxHelper.uncheckedCast(communicator.stringToProxy("anotherLocator"));
        @base = @base.ice_locator(anotherLocator);
        test(Ice.Util.proxyIdentityCompare(@base.ice_getLocator(), anotherLocator) == 0);
        communicator.setDefaultLocator(null);
        @base = communicator.stringToProxy("test @ TestAdapter");
        test(@base.ice_getLocator() == null);
        @base = @base.ice_locator(anotherLocator);
        test(Ice.Util.proxyIdentityCompare(@base.ice_getLocator(), anotherLocator) == 0);
        communicator.setDefaultLocator(locator);
        @base = communicator.stringToProxy("test @ TestAdapter");
        test(Ice.Util.proxyIdentityCompare(@base.ice_getLocator(), communicator.getDefaultLocator()) == 0);

        //
        // We also test ice_router/ice_getRouter (perhaps we should add a
        // test/Ice/router test?)
        //
        test(@base.ice_getRouter() == null);
        Ice.RouterPrx anotherRouter = Ice.RouterPrxHelper.uncheckedCast(communicator.stringToProxy("anotherRouter"));
        @base = @base.ice_router(anotherRouter);
        test(Ice.Util.proxyIdentityCompare(@base.ice_getRouter(), anotherRouter) == 0);
        Ice.RouterPrx router = Ice.RouterPrxHelper.uncheckedCast(communicator.stringToProxy("dummyrouter"));
        communicator.setDefaultRouter(router);
        @base = communicator.stringToProxy("test @ TestAdapter");
        test(Ice.Util.proxyIdentityCompare(@base.ice_getRouter(), communicator.getDefaultRouter()) == 0);
        communicator.setDefaultRouter(null);
        @base = communicator.stringToProxy("test @ TestAdapter");
        test(@base.ice_getRouter() == null);
        WriteLine("ok");

        Write("starting server... ");
        Flush();
        manager.startServer();
        WriteLine("ok");

        Write("testing checked cast... ");
        Flush();
        TestIntfPrx obj = TestIntfPrxHelper.checkedCast(@base);

        test(obj != null);
        TestIntfPrx obj2 = TestIntfPrxHelper.checkedCast(base2);

        test(obj2 != null);
        TestIntfPrx obj3 = TestIntfPrxHelper.checkedCast(base3);

        test(obj3 != null);
        ServerManagerPrx obj4 = ServerManagerPrxHelper.checkedCast(base4);

        test(obj4 != null);
        TestIntfPrx obj5 = TestIntfPrxHelper.checkedCast(base5);

        test(obj5 != null);
        TestIntfPrx obj6 = TestIntfPrxHelper.checkedCast(base6);

        test(obj6 != null);
        WriteLine("ok");

        Write("testing id@AdapterId indirect proxy... ");
        Flush();
        obj.shutdown();
        manager.startServer();
        try
        {
            obj2.ice_ping();
        }
        catch (Ice.LocalException)
        {
            test(false);
        }
        WriteLine("ok");

        Write("testing id@ReplicaGroupId indirect proxy... ");
        Flush();
        obj.shutdown();
        manager.startServer();
        try
        {
            obj6.ice_ping();
        }
        catch (Ice.LocalException)
        {
            test(false);
        }
        WriteLine("ok");

        Write("testing identity indirect proxy... ");
        Flush();
        obj.shutdown();
        manager.startServer();
        try
        {
            obj3.ice_ping();
        }
        catch (Ice.LocalException)
        {
            test(false);
        }
        try
        {
            obj2.ice_ping();
        }
        catch (Ice.LocalException)
        {
            test(false);
        }
        obj.shutdown();
        manager.startServer();
        try
        {
            obj2.ice_ping();
        }
        catch (Ice.LocalException)
        {
            test(false);
        }
        try
        {
            obj3.ice_ping();
        }
        catch (Ice.LocalException)
        {
            test(false);
        }
        obj.shutdown();
        manager.startServer();
        try
        {
            obj2.ice_ping();
        }
        catch (Ice.LocalException)
        {
            test(false);
        }
        obj.shutdown();
        manager.startServer();
        try
        {
            obj3.ice_ping();
        }
        catch (Ice.LocalException)
        {
            test(false);
        }
        obj.shutdown();
        manager.startServer();
        try
        {
            obj5 = TestIntfPrxHelper.checkedCast(base5);
            obj5.ice_ping();
        }
        catch (Ice.LocalException)
        {
            test(false);
        }
        WriteLine("ok");

        Write("testing proxy with unknown identity... ");
        Flush();
        try
        {
            @base = communicator.stringToProxy("unknown/unknown");
            @base.ice_ping();
            test(false);
        }
        catch (Ice.NotRegisteredException ex)
        {
            test(ex.kindOfObject.Equals("object"));
            test(ex.id.Equals("unknown/unknown"));
        }
        WriteLine("ok");

        Write("testing proxy with unknown adapter... ");
        Flush();
        try
        {
            @base = communicator.stringToProxy("test @ TestAdapterUnknown");
            @base.ice_ping();
            test(false);
        }
        catch (Ice.NotRegisteredException ex)
        {
            test(ex.kindOfObject.Equals("object adapter"));
            test(ex.id.Equals("TestAdapterUnknown"));
        }
        WriteLine("ok");

        Write("testing locator cache timeout... ");
        Flush();

        int count = locator.getRequestCount();

        communicator.stringToProxy("test@TestAdapter").ice_locatorCacheTimeout(0).ice_ping(); // No locator cache.
        test(++count == locator.getRequestCount());
        communicator.stringToProxy("test@TestAdapter").ice_locatorCacheTimeout(0).ice_ping(); // No locator cache.
        test(++count == locator.getRequestCount());
        communicator.stringToProxy("test@TestAdapter").ice_locatorCacheTimeout(1).ice_ping(); // 1s timeout.
        test(count == locator.getRequestCount());
        System.Threading.Thread.Sleep(1200);                                                  // 1200ms
        communicator.stringToProxy("test@TestAdapter").ice_locatorCacheTimeout(1).ice_ping(); // 1s timeout.
        test(++count == locator.getRequestCount());

        communicator.stringToProxy("test").ice_locatorCacheTimeout(0).ice_ping(); // No locator cache.
        count += 2;
        test(count == locator.getRequestCount());
        communicator.stringToProxy("test").ice_locatorCacheTimeout(1).ice_ping(); // 1s timeout
        test(count == locator.getRequestCount());
        System.Threading.Thread.Sleep(1200);                                      // 1200ms
        communicator.stringToProxy("test").ice_locatorCacheTimeout(1).ice_ping(); // 1s timeout
        count += 2;
        test(count == locator.getRequestCount());

        communicator.stringToProxy("test@TestAdapter").ice_locatorCacheTimeout(-1).ice_ping();
        test(count == locator.getRequestCount());
        communicator.stringToProxy("test").ice_locatorCacheTimeout(-1).ice_ping();
        test(count == locator.getRequestCount());
        communicator.stringToProxy("test@TestAdapter").ice_ping();
        test(count == locator.getRequestCount());
        communicator.stringToProxy("test").ice_ping();
        test(count == locator.getRequestCount());

        test(communicator.stringToProxy("test").ice_locatorCacheTimeout(99).ice_getLocatorCacheTimeout() == 99);

        WriteLine("ok");

        Write("testing proxy from server... ");
        Flush();
        obj = TestIntfPrxHelper.checkedCast(communicator.stringToProxy("test@TestAdapter"));
        HelloPrx hello = obj.getHello();

        test(hello.ice_getAdapterId().Equals("TestAdapter"));
        hello.sayHello();
        hello = obj.getReplicatedHello();
        test(hello.ice_getAdapterId().Equals("ReplicatedAdapter"));
        hello.sayHello();
        WriteLine("ok");

        Write("testing locator request queuing... ");
        Flush();
        hello = (HelloPrx)obj.getReplicatedHello().ice_locatorCacheTimeout(0).ice_connectionCached(false);
        count = locator.getRequestCount();
        hello.ice_ping();
        test(++count == locator.getRequestCount());
        List <Ice.AsyncResult <Test.Callback_Hello_sayHello> > results =
            new List <Ice.AsyncResult <Test.Callback_Hello_sayHello> >();

        for (int i = 0; i < 1000; i++)
        {
            Ice.AsyncResult <Test.Callback_Hello_sayHello> result = hello.begin_sayHello().
                                                                    whenCompleted(
                () =>
            {
            },
                (Ice.Exception ex) =>
            {
                test(false);
            });
            results.Add(result);
        }
        foreach (Ice.AsyncResult <Test.Callback_Hello_sayHello> result in results)
        {
            result.waitForCompleted();
        }
        results.Clear();
        test(locator.getRequestCount() > count && locator.getRequestCount() < count + 999);
        if (locator.getRequestCount() > count + 800)
        {
            Write("queuing = " + (locator.getRequestCount() - count));
        }
        count = locator.getRequestCount();
        hello = (HelloPrx)hello.ice_adapterId("unknown");
        for (int i = 0; i < 1000; i++)
        {
            Ice.AsyncResult <Test.Callback_Hello_sayHello> result = hello.begin_sayHello().
                                                                    whenCompleted(
                () =>
            {
                test(false);
            },
                (Ice.Exception ex) =>
            {
                test(ex is Ice.NotRegisteredException);
            });
            results.Add(result);
        }
        foreach (Ice.AsyncResult <Test.Callback_Hello_sayHello> result in results)
        {
            result.waitForCompleted();
        }
        results.Clear();
        // XXX:
        // Take into account the retries.
        test(locator.getRequestCount() > count && locator.getRequestCount() < count + 1999);
        if (locator.getRequestCount() > count + 800)
        {
            Write("queuing = " + (locator.getRequestCount() - count));
        }
        WriteLine("ok");

        Write("testing adapter locator cache... ");
        Flush();
        try
        {
            communicator.stringToProxy("test@TestAdapter3").ice_ping();
            test(false);
        }
        catch (Ice.NotRegisteredException ex)
        {
            test(ex.kindOfObject == "object adapter");
            test(ex.id.Equals("TestAdapter3"));
        }
        registry.setAdapterDirectProxy("TestAdapter3", locator.findAdapterById("TestAdapter"));
        try
        {
            communicator.stringToProxy("test@TestAdapter3").ice_ping();
            registry.setAdapterDirectProxy("TestAdapter3", communicator.stringToProxy("dummy:tcp"));
            communicator.stringToProxy("test@TestAdapter3").ice_ping();
        }
        catch (Ice.LocalException)
        {
            test(false);
        }

        try
        {
            communicator.stringToProxy("test@TestAdapter3").ice_locatorCacheTimeout(0).ice_ping();
            test(false);
        }
        catch (Ice.LocalException)
        {
        }
        try
        {
            communicator.stringToProxy("test@TestAdapter3").ice_ping();
            test(false);
        }
        catch (Ice.LocalException)
        {
        }
        registry.setAdapterDirectProxy("TestAdapter3", locator.findAdapterById("TestAdapter"));
        try
        {
            communicator.stringToProxy("test@TestAdapter3").ice_ping();
        }
        catch (Ice.LocalException)
        {
            test(false);
        }
        WriteLine("ok");

        Write("testing well-known object locator cache... ");
        Flush();
        registry.addObject(communicator.stringToProxy("test3@TestUnknown"));
        try
        {
            communicator.stringToProxy("test3").ice_ping();
            test(false);
        }
        catch (Ice.NotRegisteredException ex)
        {
            test(ex.kindOfObject == "object adapter");
            test(ex.id.Equals("TestUnknown"));
        }
        registry.addObject(communicator.stringToProxy("test3@TestAdapter4")); // Update
        registry.setAdapterDirectProxy("TestAdapter4", communicator.stringToProxy("dummy:tcp"));
        try
        {
            communicator.stringToProxy("test3").ice_ping();
            test(false);
        }
        catch (Ice.LocalException)
        {
        }
        registry.setAdapterDirectProxy("TestAdapter4", locator.findAdapterById("TestAdapter"));
        try
        {
            communicator.stringToProxy("test3").ice_ping();
        }
        catch (Ice.LocalException)
        {
            test(false);
        }

        registry.setAdapterDirectProxy("TestAdapter4", communicator.stringToProxy("dummy:tcp"));
        try
        {
            communicator.stringToProxy("test3").ice_ping();
        }
        catch (Ice.LocalException)
        {
            test(false);
        }

        try
        {
            communicator.stringToProxy("test@TestAdapter4").ice_locatorCacheTimeout(0).ice_ping();
            test(false);
        }
        catch (Ice.LocalException)
        {
        }
        try
        {
            communicator.stringToProxy("test@TestAdapter4").ice_ping();
            test(false);
        }
        catch (Ice.LocalException)
        {
        }
        try
        {
            communicator.stringToProxy("test3").ice_ping();
            test(false);
        }
        catch (Ice.LocalException)
        {
        }
        registry.addObject(communicator.stringToProxy("test3@TestAdapter"));
        try
        {
            communicator.stringToProxy("test3").ice_ping();
        }
        catch (Ice.LocalException)
        {
            test(false);
        }

        registry.addObject(communicator.stringToProxy("test4"));
        try
        {
            communicator.stringToProxy("test4").ice_ping();
            test(false);
        }
        catch (Ice.NoEndpointException)
        {
        }
        WriteLine("ok");

        Write("testing locator cache background updates... ");
        Flush();
        {
            Ice.InitializationData initData = new Ice.InitializationData();
            initData.properties = communicator.getProperties().ice_clone_();
            initData.properties.setProperty("Ice.BackgroundLocatorCacheUpdates", "1");
            Ice.Communicator ic = Ice.Util.initialize(initData);

            registry.setAdapterDirectProxy("TestAdapter5", locator.findAdapterById("TestAdapter"));
            registry.addObject(communicator.stringToProxy("test3@TestAdapter"));

            count = locator.getRequestCount();
            ic.stringToProxy("test@TestAdapter5").ice_locatorCacheTimeout(0).ice_ping(); // No locator cache.
            ic.stringToProxy("test3").ice_locatorCacheTimeout(0).ice_ping();             // No locator cache.
            count += 3;
            test(count == locator.getRequestCount());
            registry.setAdapterDirectProxy("TestAdapter5", null);
            registry.addObject(communicator.stringToProxy("test3:tcp"));
            ic.stringToProxy("test@TestAdapter5").ice_locatorCacheTimeout(10).ice_ping(); // 10s timeout.
            ic.stringToProxy("test3").ice_locatorCacheTimeout(10).ice_ping();             // 10s timeout.
            test(count == locator.getRequestCount());
            System.Threading.Thread.Sleep(1200);

            // The following request should trigger the background
            // updates but still use the cached endpoints and
            // therefore succeed.
            ic.stringToProxy("test@TestAdapter5").ice_locatorCacheTimeout(1).ice_ping(); // 1s timeout.
            ic.stringToProxy("test3").ice_locatorCacheTimeout(1).ice_ping();             // 1s timeout.

            try
            {
                while (true)
                {
                    ic.stringToProxy("test@TestAdapter5").ice_locatorCacheTimeout(1).ice_ping(); // 1s timeout.
                    System.Threading.Thread.Sleep(10);
                }
            }
            catch (Ice.LocalException)
            {
                // Expected to fail once they endpoints have been updated in the background.
            }
            try
            {
                while (true)
                {
                    ic.stringToProxy("test3").ice_locatorCacheTimeout(1).ice_ping(); // 1s timeout.
                    System.Threading.Thread.Sleep(10);
                }
            }
            catch (Ice.LocalException)
            {
                // Expected to fail once they endpoints have been updated in the background.
            }
            ic.destroy();
        }
        WriteLine("ok");

        Write("testing proxy from server after shutdown... ");
        Flush();
        hello = obj.getReplicatedHello();
        obj.shutdown();
        manager.startServer();
        hello.sayHello();
        WriteLine("ok");

        Write("testing object migration... ");
        Flush();
        hello = HelloPrxHelper.checkedCast(communicator.stringToProxy("hello"));
        obj.migrateHello();
        hello.ice_getConnection().close(Ice.ConnectionClose.GracefullyWithWait);
        hello.sayHello();
        obj.migrateHello();
        hello.sayHello();
        obj.migrateHello();
        hello.sayHello();
        WriteLine("ok");

        Write("testing locator encoding resolution... ");
        Flush();
        hello = HelloPrxHelper.checkedCast(communicator.stringToProxy("hello"));
        count = locator.getRequestCount();
        communicator.stringToProxy("test@TestAdapter").ice_encodingVersion(Ice.Util.Encoding_1_1).ice_ping();
        test(count == locator.getRequestCount());
        communicator.stringToProxy("test@TestAdapter10").ice_encodingVersion(Ice.Util.Encoding_1_0).ice_ping();
        test(++count == locator.getRequestCount());
        communicator.stringToProxy("test -e 1.0@TestAdapter10-2").ice_ping();
        test(++count == locator.getRequestCount());
        WriteLine("ok");

        Write("shutdown server... ");
        Flush();
        obj.shutdown();
        WriteLine("ok");

        Write("testing whether server is gone... ");
        Flush();
        try
        {
            obj2.ice_ping();
            test(false);
        }
        catch (Ice.LocalException)
        {
        }
        try
        {
            obj3.ice_ping();
            test(false);
        }
        catch (Ice.LocalException)
        {
        }
        try
        {
            obj5.ice_ping();
            test(false);
        }
        catch (Ice.LocalException)
        {
        }
        WriteLine("ok");

        Write("testing indirect proxies to collocated objects... ");
        Flush();

        //
        // Set up test for calling a collocated object through an
        // indirect, adapterless reference.
        //
        Ice.Properties properties = communicator.getProperties();
        properties.setProperty("Ice.PrintAdapterReady", "0");
        Ice.ObjectAdapter adapter = communicator.createObjectAdapterWithEndpoints("Hello", "tcp -h *");
        adapter.setLocator(locator);

        Ice.Identity id = new Ice.Identity();
        id.name = Guid.NewGuid().ToString();
        registry.addObject(adapter.add(new HelloI(), id));
        adapter.activate();

        HelloPrx helloPrx = HelloPrxHelper.checkedCast(
            communicator.stringToProxy("\"" + communicator.identityToString(id) + "\""));

        test(helloPrx.ice_getConnection() == null);

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

        Write("shutdown server manager... ");
        Flush();
        manager.shutdown();
        WriteLine("ok");
    }
Пример #8
0
    public static TestIntfPrx allTests(TestCommon.Application app)
    {
        Ice.Communicator communicator = app.communicator();
        Write("testing stringToProxy... ");
        Flush();
        string @ref = "test:" + app.getTestEndpoint(0);

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

        Write("testing checked cast... ");
        Flush();
        TestIntfPrx obj = TestIntfPrxHelper.checkedCast(@base);

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

        {
            Write("creating/destroying/recreating object adapter... ");
            Flush();
            Ice.ObjectAdapter adapter =
                communicator.createObjectAdapterWithEndpoints("TransientTestAdapter", "default");
            try
            {
                communicator.createObjectAdapterWithEndpoints("TransientTestAdapter", "default");
                test(false);
            }
            catch (Ice.AlreadyRegisteredException)
            {
            }
            adapter.destroy();

            //
            // Use a different port than the first adapter to avoid an "address already in use" error.
            //
            adapter = communicator.createObjectAdapterWithEndpoints("TransientTestAdapter", "default");
            adapter.destroy();
            Console.Out.WriteLine("ok");
        }

        Write("creating/activating/deactivating object adapter in one operation... ");
        Flush();
        obj.transient();
        obj.end_transient(obj.begin_transient());
        WriteLine("ok");

        {
            Write("testing connection closure... ");
            Flush();
            for (int i = 0; i < 10; ++i)
            {
                Ice.InitializationData initData = new Ice.InitializationData();
                initData.properties = communicator.getProperties().ice_clone_();
                Ice.Communicator comm = Ice.Util.initialize(initData);
                comm.stringToProxy("test:" + app.getTestEndpoint(0)).begin_ice_ping();
                comm.destroy();
            }
            WriteLine("ok");
        }

        Write("deactivating object adapter in the server... ");
        Flush();
        obj.deactivate();
        WriteLine("ok");

        Write("testing whether server is gone... ");
        Flush();
        try
        {
            obj.ice_timeout(100).ice_ping(); // Use timeout to speed up testing on Windows
            test(false);
        }
        catch (Ice.LocalException)
        {
            WriteLine("ok");
        }

        return(obj);
    }
Пример #9
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
    }
Пример #10
0
    public static Test.MyClassPrx allTests(TestCommon.Application app)
    {
        Ice.Communicator communicator = app.communicator();
        Write("testing stringToProxy... ");
        Flush();
        string rf = "test:" + app.getTestEndpoint(0);

        Ice.ObjectPrx baseProxy = communicator.stringToProxy(rf);
        test(baseProxy != null);

        Ice.ObjectPrx b1 = communicator.stringToProxy("test");
        test(b1.ice_getIdentity().name.Equals("test") && b1.ice_getIdentity().category.Length == 0 &&
             b1.ice_getAdapterId().Length == 0 && b1.ice_getFacet().Length == 0);
        b1 = communicator.stringToProxy("test ");
        test(b1.ice_getIdentity().name.Equals("test") && b1.ice_getIdentity().category.Length == 0 &&
             b1.ice_getFacet().Length == 0);
        b1 = communicator.stringToProxy(" test ");
        test(b1.ice_getIdentity().name.Equals("test") && b1.ice_getIdentity().category.Length == 0 &&
             b1.ice_getFacet().Length == 0);
        b1 = communicator.stringToProxy(" test");
        test(b1.ice_getIdentity().name.Equals("test") && b1.ice_getIdentity().category.Length == 0 &&
             b1.ice_getFacet().Length == 0);
        b1 = communicator.stringToProxy("'test -f facet'");
        test(b1.ice_getIdentity().name.Equals("test -f facet") && b1.ice_getIdentity().category.Length == 0 &&
             b1.ice_getFacet().Length == 0);
        try
        {
            b1 = communicator.stringToProxy("\"test -f facet'");
            test(false);
        }
        catch (Ice.ProxyParseException)
        {
        }
        b1 = communicator.stringToProxy("\"test -f facet\"");
        test(b1.ice_getIdentity().name.Equals("test -f facet") && b1.ice_getIdentity().category.Length == 0 &&
             b1.ice_getFacet().Length == 0);
        b1 = communicator.stringToProxy("\"test -f facet@test\"");
        test(b1.ice_getIdentity().name.Equals("test -f facet@test") && b1.ice_getIdentity().category.Length == 0 &&
             b1.ice_getFacet().Length == 0);
        b1 = communicator.stringToProxy("\"test -f facet@test @test\"");
        test(b1.ice_getIdentity().name.Equals("test -f facet@test @test") && b1.ice_getIdentity().category.Length == 0 &&
             b1.ice_getFacet().Length == 0);
        try
        {
            b1 = communicator.stringToProxy("test test");
            test(false);
        }
        catch (Ice.ProxyParseException)
        {
        }
        b1 = communicator.stringToProxy("test\\040test");
        test(b1.ice_getIdentity().name.Equals("test test") && b1.ice_getIdentity().category.Length == 0);
        try
        {
            b1 = communicator.stringToProxy("test\\777");
            test(false);
        }
        catch (Ice.IdentityParseException)
        {
        }
        b1 = communicator.stringToProxy("test\\40test");
        test(b1.ice_getIdentity().name.Equals("test test"));

        // Test some octal and hex corner cases.
        b1 = communicator.stringToProxy("test\\4test");
        test(b1.ice_getIdentity().name.Equals("test\u0004test"));
        b1 = communicator.stringToProxy("test\\04test");
        test(b1.ice_getIdentity().name.Equals("test\u0004test"));
        b1 = communicator.stringToProxy("test\\004test");
        test(b1.ice_getIdentity().name.Equals("test\u0004test"));
        b1 = communicator.stringToProxy("test\\1114test");
        test(b1.ice_getIdentity().name.Equals("test\u00494test"));

        b1 = communicator.stringToProxy("test\\b\\f\\n\\r\\t\\'\\\"\\\\test");
        test(b1.ice_getIdentity().name.Equals("test\b\f\n\r\t\'\"\\test") && b1.ice_getIdentity().category.Length == 0);

        b1 = communicator.stringToProxy("category/test");
        test(b1.ice_getIdentity().name.Equals("test") && b1.ice_getIdentity().category.Equals("category") &&
             b1.ice_getAdapterId().Length == 0);

        b1 = communicator.stringToProxy("");
        test(b1 == null);
        b1 = communicator.stringToProxy("\"\"");
        test(b1 == null);
        try
        {
            b1 = communicator.stringToProxy("\"\" test"); // Invalid trailing characters.
            test(false);
        }
        catch (Ice.ProxyParseException)
        {
        }
        try
        {
            b1 = communicator.stringToProxy("test:"); // Missing endpoint.
            test(false);
        }
        catch (Ice.EndpointParseException)
        {
        }

        b1 = communicator.stringToProxy("test@adapter");
        test(b1.ice_getIdentity().name.Equals("test") && b1.ice_getIdentity().category.Length == 0 &&
             b1.ice_getAdapterId().Equals("adapter"));
        try
        {
            b1 = communicator.stringToProxy("id@adapter test");
            test(false);
        }
        catch (Ice.ProxyParseException)
        {
        }
        b1 = communicator.stringToProxy("category/test@adapter");
        test(b1.ice_getIdentity().name.Equals("test") && b1.ice_getIdentity().category.Equals("category") &&
             b1.ice_getAdapterId().Equals("adapter"));
        b1 = communicator.stringToProxy("category/test@adapter:tcp");
        test(b1.ice_getIdentity().name.Equals("test") && b1.ice_getIdentity().category.Equals("category") &&
             b1.ice_getAdapterId().Equals("adapter:tcp"));
        b1 = communicator.stringToProxy("'category 1/test'@adapter");
        test(b1.ice_getIdentity().name.Equals("test") && b1.ice_getIdentity().category.Equals("category 1") &&
             b1.ice_getAdapterId().Equals("adapter"));
        b1 = communicator.stringToProxy("'category/test 1'@adapter");
        test(b1.ice_getIdentity().name.Equals("test 1") && b1.ice_getIdentity().category.Equals("category") &&
             b1.ice_getAdapterId().Equals("adapter"));
        b1 = communicator.stringToProxy("'category/test'@'adapter 1'");
        test(b1.ice_getIdentity().name.Equals("test") && b1.ice_getIdentity().category.Equals("category") &&
             b1.ice_getAdapterId().Equals("adapter 1"));
        b1 = communicator.stringToProxy("\"category \\/test@foo/test\"@adapter");
        test(b1.ice_getIdentity().name.Equals("test") && b1.ice_getIdentity().category.Equals("category /test@foo") &&
             b1.ice_getAdapterId().Equals("adapter"));
        b1 = communicator.stringToProxy("\"category \\/test@foo/test\"@\"adapter:tcp\"");
        test(b1.ice_getIdentity().name.Equals("test") && b1.ice_getIdentity().category.Equals("category /test@foo") &&
             b1.ice_getAdapterId().Equals("adapter:tcp"));

        b1 = communicator.stringToProxy("id -f facet");
        test(b1.ice_getIdentity().name.Equals("id") && b1.ice_getIdentity().category.Length == 0 &&
             b1.ice_getFacet().Equals("facet"));
        b1 = communicator.stringToProxy("id -f 'facet x'");
        test(b1.ice_getIdentity().name.Equals("id") && b1.ice_getIdentity().category.Length == 0 &&
             b1.ice_getFacet().Equals("facet x"));
        b1 = communicator.stringToProxy("id -f \"facet x\"");
        test(b1.ice_getIdentity().name.Equals("id") && b1.ice_getIdentity().category.Length == 0 &&
             b1.ice_getFacet().Equals("facet x"));
        try
        {
            b1 = communicator.stringToProxy("id -f \"facet x");
            test(false);
        }
        catch (Ice.ProxyParseException)
        {
        }
        try
        {
            b1 = communicator.stringToProxy("id -f \'facet x");
            test(false);
        }
        catch (Ice.ProxyParseException)
        {
        }
        b1 = communicator.stringToProxy("test -f facet:tcp");
        test(b1.ice_getIdentity().name.Equals("test") && b1.ice_getIdentity().category.Length == 0 &&
             b1.ice_getFacet().Equals("facet") && b1.ice_getAdapterId().Length == 0);
        b1 = communicator.stringToProxy("test -f \"facet:tcp\"");
        test(b1.ice_getIdentity().name.Equals("test") && b1.ice_getIdentity().category.Length == 0 &&
             b1.ice_getFacet().Equals("facet:tcp") && b1.ice_getAdapterId().Length == 0);
        b1 = communicator.stringToProxy("test -f facet@test");
        test(b1.ice_getIdentity().name.Equals("test") && b1.ice_getIdentity().category.Length == 0 &&
             b1.ice_getFacet().Equals("facet") && b1.ice_getAdapterId().Equals("test"));
        b1 = communicator.stringToProxy("test -f 'facet@test'");
        test(b1.ice_getIdentity().name.Equals("test") && b1.ice_getIdentity().category.Length == 0 &&
             b1.ice_getFacet().Equals("facet@test") && b1.ice_getAdapterId().Length == 0);
        b1 = communicator.stringToProxy("test -f 'facet@test'@test");
        test(b1.ice_getIdentity().name.Equals("test") && b1.ice_getIdentity().category.Length == 0 &&
             b1.ice_getFacet().Equals("facet@test") && b1.ice_getAdapterId().Equals("test"));
        try
        {
            b1 = communicator.stringToProxy("test -f facet@test @test");
            test(false);
        }
        catch (Ice.ProxyParseException)
        {
        }
        b1 = communicator.stringToProxy("test");
        test(b1.ice_isTwoway());
        b1 = communicator.stringToProxy("test -t");
        test(b1.ice_isTwoway());
        b1 = communicator.stringToProxy("test -o");
        test(b1.ice_isOneway());
        b1 = communicator.stringToProxy("test -O");
        test(b1.ice_isBatchOneway());
        b1 = communicator.stringToProxy("test -d");
        test(b1.ice_isDatagram());
        b1 = communicator.stringToProxy("test -D");
        test(b1.ice_isBatchDatagram());
        b1 = communicator.stringToProxy("test");
        test(!b1.ice_isSecure());
        b1 = communicator.stringToProxy("test -s");
        test(b1.ice_isSecure());

        test(b1.ice_getEncodingVersion().Equals(Ice.Util.currentEncoding));

        b1 = communicator.stringToProxy("test -e 1.0");
        test(b1.ice_getEncodingVersion().major == 1 && b1.ice_getEncodingVersion().minor == 0);

        b1 = communicator.stringToProxy("test -e 6.5");
        test(b1.ice_getEncodingVersion().major == 6 && b1.ice_getEncodingVersion().minor == 5);

        b1 = communicator.stringToProxy("test -p 1.0 -e 1.0");
        test(b1.ToString().Equals("test -t -e 1.0"));

        b1 = communicator.stringToProxy("test -p 6.5 -e 1.0");
        test(b1.ToString().Equals("test -t -p 6.5 -e 1.0"));

        try
        {
            communicator.stringToProxy("test:tcp@adapterId");
            test(false);
        }
        catch (Ice.EndpointParseException)
        {
        }
        // This is an unknown endpoint warning, not a parse exception.
        //
        //try
        //{
        //   b1 = communicator.stringToProxy("test -f the:facet:tcp");
        //   test(false);
        //}
        //catch(Ice.EndpointParseException)
        //{
        //}
        try
        {
            communicator.stringToProxy("test: :tcp");
            test(false);
        }
        catch (Ice.EndpointParseException)
        {
        }

        //
        // Test invalid endpoint syntax
        //
        try
        {
            communicator.createObjectAdapterWithEndpoints("BadAdapter", " : ");
            test(false);
        }
        catch (Ice.EndpointParseException)
        {
        }

        try
        {
            communicator.createObjectAdapterWithEndpoints("BadAdapter", "tcp: ");
            test(false);
        }
        catch (Ice.EndpointParseException)
        {
        }

        try
        {
            communicator.createObjectAdapterWithEndpoints("BadAdapter", ":tcp");
            test(false);
        }
        catch (Ice.EndpointParseException)
        {
        }

        //
        // Test for bug ICE-5543: escaped escapes in stringToIdentity
        //
        Ice.Identity id  = new Ice.Identity("test", ",X2QNUAzSBcJ_e$AV;E\\");
        Ice.Identity id2 = Ice.Util.stringToIdentity(communicator.identityToString(id));
        test(id.Equals(id2));

        id  = new Ice.Identity("test", ",X2QNUAz\\SB\\/cJ_e$AV;E\\\\");
        id2 = Ice.Util.stringToIdentity(communicator.identityToString(id));
        test(id.Equals(id2));

        id = new Ice.Identity("/test", "cat/");
        string idStr = communicator.identityToString(id);

        test(idStr == "cat\\//\\/test");
        id2 = Ice.Util.stringToIdentity(idStr);
        test(id.Equals(id2));

        // Input string with various pitfalls
        id = Ice.Util.stringToIdentity("\\342\\x82\\254\\60\\x9\\60\\");
        test(id.name == "€0\t0\\" && id.category == "");

        try
        {
            // Illegal character < 32
            id = Ice.Util.stringToIdentity("xx\01FooBar");
            test(false);
        }
        catch (Ice.IdentityParseException)
        {
        }

        try
        {
            // Illegal surrogate
            id = Ice.Util.stringToIdentity("xx\\ud911");
            test(false);
        }
        catch (Ice.IdentityParseException)
        {
        }

        // Testing bytes 127 (\x7F, \177) and €
        id = new Ice.Identity("test", "\x7f€");

        idStr = Ice.Util.identityToString(id, Ice.ToStringMode.Unicode);
        test(idStr == "\\u007f€/test");
        id2 = Ice.Util.stringToIdentity(idStr);
        test(id.Equals(id2));
        test(Ice.Util.identityToString(id) == idStr);

        idStr = Ice.Util.identityToString(id, Ice.ToStringMode.ASCII);
        test(idStr == "\\u007f\\u20ac/test");
        id2 = Ice.Util.stringToIdentity(idStr);
        test(id.Equals(id2));

        idStr = Ice.Util.identityToString(id, Ice.ToStringMode.Compat);
        test(idStr == "\\177\\342\\202\\254/test");
        id2 = Ice.Util.stringToIdentity(idStr);
        test(id.Equals(id2));

        id2 = Ice.Util.stringToIdentity(communicator.identityToString(id));
        test(id.Equals(id2));

        // More unicode character
        id = new Ice.Identity("banana \x0E-\ud83c\udf4c\u20ac\u00a2\u0024", "greek \ud800\udd6a");

        idStr = Ice.Util.identityToString(id, Ice.ToStringMode.Unicode);
        test(idStr == "greek \ud800\udd6a/banana \\u000e-\ud83c\udf4c\u20ac\u00a2$");
        id2 = Ice.Util.stringToIdentity(idStr);
        test(id.Equals(id2));

        idStr = Ice.Util.identityToString(id, Ice.ToStringMode.ASCII);
        test(idStr == "greek \\U0001016a/banana \\u000e-\\U0001f34c\\u20ac\\u00a2$");
        id2 = Ice.Util.stringToIdentity(idStr);
        test(id.Equals(id2));

        idStr = Ice.Util.identityToString(id, Ice.ToStringMode.Compat);
        id2   = Ice.Util.stringToIdentity(idStr);
        test(idStr == "greek \\360\\220\\205\\252/banana \\016-\\360\\237\\215\\214\\342\\202\\254\\302\\242$");
        test(id.Equals(id2));

        WriteLine("ok");

        Write("testing proxyToString... ");
        Flush();
        b1 = communicator.stringToProxy(rf);
        Ice.ObjectPrx b2 = communicator.stringToProxy(communicator.proxyToString(b1));
        test(b1.Equals(b2));

        if (b1.ice_getConnection() != null) // not colloc-optimized target
        {
            b2 = b1.ice_getConnection().createProxy(Ice.Util.stringToIdentity("fixed"));
            String str = communicator.proxyToString(b2);
            test(b2.ToString() == str);
            String str2 = b1.ice_identity(b2.ice_getIdentity()).ice_secure(b2.ice_isSecure()).ToString();

            // Verify that the stringified fixed proxy is the same as a regular stringified proxy
            // but without endpoints
            test(str2.StartsWith(str));
            test(str2[str.Length] == ':');
        }
        WriteLine("ok");

        Write("testing propertyToProxy... ");
        Flush();
        Ice.Properties prop           = communicator.getProperties();
        String         propertyPrefix = "Foo.Proxy";

        prop.setProperty(propertyPrefix, "test:" + app.getTestEndpoint(0));
        b1 = communicator.propertyToProxy(propertyPrefix);
        test(b1.ice_getIdentity().name.Equals("test") && b1.ice_getIdentity().category.Length == 0 &&
             b1.ice_getAdapterId().Length == 0 && b1.ice_getFacet().Length == 0);

        string property;

        property = propertyPrefix + ".Locator";
        test(b1.ice_getLocator() == null);
        prop.setProperty(property, "locator:default -p 10000");
        b1 = communicator.propertyToProxy(propertyPrefix);
        test(b1.ice_getLocator() != null && b1.ice_getLocator().ice_getIdentity().name.Equals("locator"));
        try
        {
            prop.setProperty(property, "");
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.ToString());
        }
        property = propertyPrefix + ".LocatorCacheTimeout";
        test(b1.ice_getLocatorCacheTimeout() == -1);
        prop.setProperty(property, "1");
        b1 = communicator.propertyToProxy(propertyPrefix);
        test(b1.ice_getLocatorCacheTimeout() == 1);
        prop.setProperty(property, "");

        // Now retest with an indirect proxy.
        prop.setProperty(propertyPrefix, "test");
        property = propertyPrefix + ".Locator";
        prop.setProperty(property, "locator:default -p 10000");
        b1 = communicator.propertyToProxy(propertyPrefix);
        test(b1.ice_getLocator() != null && b1.ice_getLocator().ice_getIdentity().name.Equals("locator"));
        prop.setProperty(property, "");

        property = propertyPrefix + ".LocatorCacheTimeout";
        test(b1.ice_getLocatorCacheTimeout() == -1);
        prop.setProperty(property, "1");
        b1 = communicator.propertyToProxy(propertyPrefix);
        test(b1.ice_getLocatorCacheTimeout() == 1);
        prop.setProperty(property, "");

        // This cannot be tested so easily because the property is cached
        // on communicator initialization.
        //
        //prop.setProperty("Ice.Default.LocatorCacheTimeout", "60");
        //b1 = communicator.propertyToProxy(propertyPrefix);
        //test(b1.ice_getLocatorCacheTimeout() == 60);
        //prop.setProperty("Ice.Default.LocatorCacheTimeout", "");

        prop.setProperty(propertyPrefix, "test:" + app.getTestEndpoint(0));

        property = propertyPrefix + ".Router";
        test(b1.ice_getRouter() == null);
        prop.setProperty(property, "router:default -p 10000");
        b1 = communicator.propertyToProxy(propertyPrefix);
        test(b1.ice_getRouter() != null && b1.ice_getRouter().ice_getIdentity().name.Equals("router"));
        prop.setProperty(property, "");

        property = propertyPrefix + ".PreferSecure";
        test(!b1.ice_isPreferSecure());
        prop.setProperty(property, "1");
        b1 = communicator.propertyToProxy(propertyPrefix);
        test(b1.ice_isPreferSecure());
        prop.setProperty(property, "");

        property = propertyPrefix + ".ConnectionCached";
        test(b1.ice_isConnectionCached());
        prop.setProperty(property, "0");
        b1 = communicator.propertyToProxy(propertyPrefix);
        test(!b1.ice_isConnectionCached());
        prop.setProperty(property, "");

        property = propertyPrefix + ".InvocationTimeout";
        test(b1.ice_getInvocationTimeout() == -1);
        prop.setProperty(property, "1000");
        b1 = communicator.propertyToProxy(propertyPrefix);
        test(b1.ice_getInvocationTimeout() == 1000);
        prop.setProperty(property, "");

        property = propertyPrefix + ".EndpointSelection";
        test(b1.ice_getEndpointSelection() == Ice.EndpointSelectionType.Random);
        prop.setProperty(property, "Random");
        b1 = communicator.propertyToProxy(propertyPrefix);
        test(b1.ice_getEndpointSelection() == Ice.EndpointSelectionType.Random);
        prop.setProperty(property, "Ordered");
        b1 = communicator.propertyToProxy(propertyPrefix);
        test(b1.ice_getEndpointSelection() == Ice.EndpointSelectionType.Ordered);
        prop.setProperty(property, "");

        property = propertyPrefix + ".CollocationOptimized";
        test(b1.ice_isCollocationOptimized());
        prop.setProperty(property, "0");
        b1 = communicator.propertyToProxy(propertyPrefix);
        test(!b1.ice_isCollocationOptimized());
        prop.setProperty(property, "");

        property = propertyPrefix + ".Context.c1";
        test(!b1.ice_getContext().ContainsKey("c1"));
        prop.setProperty(property, "TEST");
        b1 = communicator.propertyToProxy(propertyPrefix);
        test(b1.ice_getContext()["c1"].Equals("TEST"));

        property = propertyPrefix + ".Context.c2";
        test(!b1.ice_getContext().ContainsKey("c2"));
        prop.setProperty(property, "TEST");
        b1 = communicator.propertyToProxy(propertyPrefix);
        test(b1.ice_getContext()["c2"].Equals("TEST"));

        prop.setProperty(propertyPrefix + ".Context.c1", "");
        prop.setProperty(propertyPrefix + ".Context.c2", "");

        WriteLine("ok");

        Write("testing proxyToProperty... ");
        Flush();

        b1 = communicator.stringToProxy("test");
        b1 = b1.ice_collocationOptimized(true);
        b1 = b1.ice_connectionCached(true);
        b1 = b1.ice_preferSecure(false);
        b1 = b1.ice_endpointSelection(Ice.EndpointSelectionType.Ordered);
        b1 = b1.ice_locatorCacheTimeout(100);
        b1 = b1.ice_invocationTimeout(1234);
        b1 = b1.ice_encodingVersion(new Ice.EncodingVersion(1, 0));

        Ice.ObjectPrx router = communicator.stringToProxy("router");
        router = router.ice_collocationOptimized(false);
        router = router.ice_connectionCached(true);
        router = router.ice_preferSecure(true);
        router = router.ice_endpointSelection(Ice.EndpointSelectionType.Random);
        router = router.ice_locatorCacheTimeout(200);
        router = router.ice_invocationTimeout(1500);

        Ice.ObjectPrx locator = communicator.stringToProxy("locator");
        locator = locator.ice_collocationOptimized(true);
        locator = locator.ice_connectionCached(false);
        locator = locator.ice_preferSecure(true);
        locator = locator.ice_endpointSelection(Ice.EndpointSelectionType.Random);
        locator = locator.ice_locatorCacheTimeout(300);
        locator = locator.ice_invocationTimeout(1500);

        locator = locator.ice_router(Ice.RouterPrxHelper.uncheckedCast(router));
        b1      = b1.ice_locator(Ice.LocatorPrxHelper.uncheckedCast(locator));

        Dictionary <string, string> proxyProps = communicator.proxyToProperty(b1, "Test");

        test(proxyProps.Count == 21);

        test(proxyProps["Test"].Equals("test -t -e 1.0"));
        test(proxyProps["Test.CollocationOptimized"].Equals("1"));
        test(proxyProps["Test.ConnectionCached"].Equals("1"));
        test(proxyProps["Test.PreferSecure"].Equals("0"));
        test(proxyProps["Test.EndpointSelection"].Equals("Ordered"));
        test(proxyProps["Test.LocatorCacheTimeout"].Equals("100"));
        test(proxyProps["Test.InvocationTimeout"].Equals("1234"));

        test(proxyProps["Test.Locator"].Equals(
                 "locator -t -e " + Ice.Util.encodingVersionToString(Ice.Util.currentEncoding)));
        // Locator collocation optimization is always disabled.
        //test(proxyProps["Test.Locator.CollocationOptimized"].Equals("1"));
        test(proxyProps["Test.Locator.ConnectionCached"].Equals("0"));
        test(proxyProps["Test.Locator.PreferSecure"].Equals("1"));
        test(proxyProps["Test.Locator.EndpointSelection"].Equals("Random"));
        test(proxyProps["Test.Locator.LocatorCacheTimeout"].Equals("300"));
        test(proxyProps["Test.Locator.InvocationTimeout"].Equals("1500"));

        test(proxyProps["Test.Locator.Router"].Equals(
                 "router -t -e " + Ice.Util.encodingVersionToString(Ice.Util.currentEncoding)));
        test(proxyProps["Test.Locator.Router.CollocationOptimized"].Equals("0"));
        test(proxyProps["Test.Locator.Router.ConnectionCached"].Equals("1"));
        test(proxyProps["Test.Locator.Router.PreferSecure"].Equals("1"));
        test(proxyProps["Test.Locator.Router.EndpointSelection"].Equals("Random"));
        test(proxyProps["Test.Locator.Router.LocatorCacheTimeout"].Equals("200"));
        test(proxyProps["Test.Locator.Router.InvocationTimeout"].Equals("1500"));

        WriteLine("ok");

        Write("testing ice_getCommunicator... ");
        Flush();
        test(baseProxy.ice_getCommunicator() == communicator);
        WriteLine("ok");

        Write("testing proxy methods... ");

// Disable Obsolete warning/error
#pragma warning disable 612, 618
        test(communicator.identityToString(
                 baseProxy.ice_identity(communicator.stringToIdentity("other")).ice_getIdentity()).Equals("other"));
#pragma warning restore 612, 618
        test(baseProxy.ice_facet("facet").ice_getFacet().Equals("facet"));
        test(baseProxy.ice_adapterId("id").ice_getAdapterId().Equals("id"));
        test(baseProxy.ice_twoway().ice_isTwoway());
        test(baseProxy.ice_oneway().ice_isOneway());
        test(baseProxy.ice_batchOneway().ice_isBatchOneway());
        test(baseProxy.ice_datagram().ice_isDatagram());
        test(baseProxy.ice_batchDatagram().ice_isBatchDatagram());
        test(baseProxy.ice_secure(true).ice_isSecure());
        test(!baseProxy.ice_secure(false).ice_isSecure());
        test(baseProxy.ice_collocationOptimized(true).ice_isCollocationOptimized());
        test(!baseProxy.ice_collocationOptimized(false).ice_isCollocationOptimized());
        test(baseProxy.ice_preferSecure(true).ice_isPreferSecure());
        test(!baseProxy.ice_preferSecure(false).ice_isPreferSecure());

        try
        {
            baseProxy.ice_timeout(0);
            test(false);
        }
        catch (ArgumentException)
        {
        }

        try
        {
            baseProxy.ice_timeout(-1);
        }
        catch (ArgumentException)
        {
            test(false);
        }

        try
        {
            baseProxy.ice_timeout(-2);
            test(false);
        }
        catch (ArgumentException)
        {
        }

        try
        {
            baseProxy.ice_invocationTimeout(0);
            test(false);
        }
        catch (ArgumentException)
        {
        }

        try
        {
            baseProxy.ice_invocationTimeout(-1);
            baseProxy.ice_invocationTimeout(-2);
        }
        catch (ArgumentException)
        {
            test(false);
        }

        try
        {
            baseProxy.ice_invocationTimeout(-3);
            test(false);
        }
        catch (ArgumentException)
        {
        }

        try
        {
            baseProxy.ice_locatorCacheTimeout(0);
        }
        catch (ArgumentException)
        {
            test(false);
        }

        try
        {
            baseProxy.ice_locatorCacheTimeout(-1);
        }
        catch (ArgumentException)
        {
            test(false);
        }

        try
        {
            baseProxy.ice_locatorCacheTimeout(-2);
            test(false);
        }
        catch (ArgumentException)
        {
        }

        WriteLine("ok");

        Write("testing proxy comparison... ");
        Flush();

        test(communicator.stringToProxy("foo").Equals(communicator.stringToProxy("foo")));
        test(!communicator.stringToProxy("foo").Equals(communicator.stringToProxy("foo2")));

        Ice.ObjectPrx compObj = communicator.stringToProxy("foo");

        test(compObj.ice_facet("facet").Equals(compObj.ice_facet("facet")));
        test(!compObj.ice_facet("facet").Equals(compObj.ice_facet("facet1")));

        test(compObj.ice_oneway().Equals(compObj.ice_oneway()));
        test(!compObj.ice_oneway().Equals(compObj.ice_twoway()));

        test(compObj.ice_secure(true).Equals(compObj.ice_secure(true)));
        test(!compObj.ice_secure(false).Equals(compObj.ice_secure(true)));

        test(compObj.ice_collocationOptimized(true).Equals(compObj.ice_collocationOptimized(true)));
        test(!compObj.ice_collocationOptimized(false).Equals(compObj.ice_collocationOptimized(true)));

        test(compObj.ice_connectionCached(true).Equals(compObj.ice_connectionCached(true)));
        test(!compObj.ice_connectionCached(false).Equals(compObj.ice_connectionCached(true)));

        test(compObj.ice_endpointSelection(Ice.EndpointSelectionType.Random).Equals(
                 compObj.ice_endpointSelection(Ice.EndpointSelectionType.Random)));
        test(!compObj.ice_endpointSelection(Ice.EndpointSelectionType.Random).Equals(
                 compObj.ice_endpointSelection(Ice.EndpointSelectionType.Ordered)));

        test(compObj.ice_connectionId("id2").Equals(compObj.ice_connectionId("id2")));
        test(!compObj.ice_connectionId("id1").Equals(compObj.ice_connectionId("id2")));
        test(compObj.ice_connectionId("id1").ice_getConnectionId().Equals("id1"));
        test(compObj.ice_connectionId("id2").ice_getConnectionId().Equals("id2"));

        test(compObj.ice_compress(true).Equals(compObj.ice_compress(true)));
        test(!compObj.ice_compress(false).Equals(compObj.ice_compress(true)));

        test(compObj.ice_timeout(20).Equals(compObj.ice_timeout(20)));
        test(!compObj.ice_timeout(10).Equals(compObj.ice_timeout(20)));

        Ice.LocatorPrx loc1 = Ice.LocatorPrxHelper.uncheckedCast(communicator.stringToProxy("loc1:default -p 10000"));
        Ice.LocatorPrx loc2 = Ice.LocatorPrxHelper.uncheckedCast(communicator.stringToProxy("loc2:default -p 10000"));
        test(compObj.ice_locator(null).Equals(compObj.ice_locator(null)));
        test(compObj.ice_locator(loc1).Equals(compObj.ice_locator(loc1)));
        test(!compObj.ice_locator(loc1).Equals(compObj.ice_locator(null)));
        test(!compObj.ice_locator(null).Equals(compObj.ice_locator(loc2)));
        test(!compObj.ice_locator(loc1).Equals(compObj.ice_locator(loc2)));

        Ice.RouterPrx rtr1 = Ice.RouterPrxHelper.uncheckedCast(communicator.stringToProxy("rtr1:default -p 10000"));
        Ice.RouterPrx rtr2 = Ice.RouterPrxHelper.uncheckedCast(communicator.stringToProxy("rtr2:default -p 10000"));
        test(compObj.ice_router(null).Equals(compObj.ice_router(null)));
        test(compObj.ice_router(rtr1).Equals(compObj.ice_router(rtr1)));
        test(!compObj.ice_router(rtr1).Equals(compObj.ice_router(null)));
        test(!compObj.ice_router(null).Equals(compObj.ice_router(rtr2)));
        test(!compObj.ice_router(rtr1).Equals(compObj.ice_router(rtr2)));

        Dictionary <string, string> ctx1 = new Dictionary <string, string>();
        ctx1["ctx1"] = "v1";
        Dictionary <string, string> ctx2 = new Dictionary <string, string>();
        ctx2["ctx2"] = "v2";
        test(compObj.ice_context(null).Equals(compObj.ice_context(null)));
        test(compObj.ice_context(ctx1).Equals(compObj.ice_context(ctx1)));
        test(!compObj.ice_context(ctx1).Equals(compObj.ice_context(null)));
        test(!compObj.ice_context(null).Equals(compObj.ice_context(ctx2)));
        test(!compObj.ice_context(ctx1).Equals(compObj.ice_context(ctx2)));

        test(compObj.ice_preferSecure(true).Equals(compObj.ice_preferSecure(true)));
        test(!compObj.ice_preferSecure(true).Equals(compObj.ice_preferSecure(false)));

        Ice.ObjectPrx compObj1 = communicator.stringToProxy("foo:tcp -h 127.0.0.1 -p 10000");
        Ice.ObjectPrx compObj2 = communicator.stringToProxy("foo:tcp -h 127.0.0.1 -p 10001");
        test(!compObj1.Equals(compObj2));

        compObj1 = communicator.stringToProxy("foo@MyAdapter1");
        compObj2 = communicator.stringToProxy("foo@MyAdapter2");
        test(!compObj1.Equals(compObj2));

        test(compObj1.ice_locatorCacheTimeout(20).Equals(compObj1.ice_locatorCacheTimeout(20)));
        test(!compObj1.ice_locatorCacheTimeout(10).Equals(compObj1.ice_locatorCacheTimeout(20)));

        test(compObj1.ice_invocationTimeout(20).Equals(compObj1.ice_invocationTimeout(20)));
        test(!compObj1.ice_invocationTimeout(10).Equals(compObj1.ice_invocationTimeout(20)));

        compObj1 = communicator.stringToProxy("foo:tcp -h 127.0.0.1 -p 1000");
        compObj2 = communicator.stringToProxy("foo@MyAdapter1");
        test(!compObj1.Equals(compObj2));

        Ice.Endpoint[] endpts1 = communicator.stringToProxy("foo:tcp -h 127.0.0.1 -p 10000").ice_getEndpoints();
        Ice.Endpoint[] endpts2 = communicator.stringToProxy("foo:tcp -h 127.0.0.1 -p 10001").ice_getEndpoints();
        test(!endpts1[0].Equals(endpts2[0]));
        test(endpts1[0].Equals(communicator.stringToProxy("foo:tcp -h 127.0.0.1 -p 10000").ice_getEndpoints()[0]));

        //
        // TODO: Ideally we should also test comparison of fixed proxies.
        //
        WriteLine("ok");

        Write("testing checked cast... ");
        Flush();
        Test.MyClassPrx cl = Test.MyClassPrxHelper.checkedCast(baseProxy);
        test(cl != null);
        Test.MyDerivedClassPrx derived = Test.MyDerivedClassPrxHelper.checkedCast(cl);
        test(derived != null);
        test(cl.Equals(baseProxy));
        test(derived.Equals(baseProxy));
        test(cl.Equals(derived));
        WriteLine("ok");

        Write("testing checked cast with context... ");
        Flush();

        Dictionary <string, string> c = cl.getContext();
        test(c == null || c.Count == 0);

        c        = new Dictionary <string, string>();
        c["one"] = "hello";
        c["two"] = "world";
        cl       = Test.MyClassPrxHelper.checkedCast(baseProxy, c);
        Dictionary <string, string> c2 = cl.getContext();
        test(Ice.CollectionComparer.Equals(c, c2));
        WriteLine("ok");

        Write("testing encoding versioning... ");
        Flush();
        string          ref20 = "test -e 2.0:" + app.getTestEndpoint(0);
        Test.MyClassPrx cl20  = Test.MyClassPrxHelper.uncheckedCast(communicator.stringToProxy(ref20));
        try
        {
            cl20.ice_ping();
            test(false);
        }
        catch (Ice.UnsupportedEncodingException)
        {
            // Server 2.0 endpoint doesn't support 1.1 version.
        }

        string          ref10 = "test -e 1.0:" + app.getTestEndpoint(0);
        Test.MyClassPrx cl10  = Test.MyClassPrxHelper.uncheckedCast(communicator.stringToProxy(ref10));
        cl10.ice_ping();
        cl10.ice_encodingVersion(Ice.Util.Encoding_1_0).ice_ping();
        cl.ice_encodingVersion(Ice.Util.Encoding_1_0).ice_ping();

        // 1.3 isn't supported but since a 1.3 proxy supports 1.1, the
        // call will use the 1.1 encoding
        string          ref13 = "test -e 1.3:" + app.getTestEndpoint(0);
        Test.MyClassPrx cl13  = Test.MyClassPrxHelper.uncheckedCast(communicator.stringToProxy(ref13));
        cl13.ice_ping();
        cl13.end_ice_ping(cl13.begin_ice_ping());

        try
        {
            // Send request with bogus 1.2 encoding.
            Ice.EncodingVersion version = new Ice.EncodingVersion(1, 2);
            Ice.OutputStream    os      = new Ice.OutputStream(communicator);
            os.startEncapsulation();
            os.endEncapsulation();
            byte[] inEncaps = os.finished();
            inEncaps[4] = version.major;
            inEncaps[5] = version.minor;
            byte[] outEncaps;
            cl.ice_invoke("ice_ping", Ice.OperationMode.Normal, inEncaps,
                          out outEncaps);
            test(false);
        }
        catch (Ice.UnknownLocalException ex)
        {
            // The server thrown an UnsupportedEncodingException
            test(ex.unknown.IndexOf("UnsupportedEncodingException") > 0);
        }

        try
        {
            // Send request with bogus 2.0 encoding.
            Ice.EncodingVersion version = new Ice.EncodingVersion(2, 0);
            Ice.OutputStream    os      = new Ice.OutputStream(communicator);
            os.startEncapsulation();
            os.endEncapsulation();
            byte[] inEncaps = os.finished();
            inEncaps[4] = version.major;
            inEncaps[5] = version.minor;
            byte[] outEncaps;
            cl.ice_invoke("ice_ping", Ice.OperationMode.Normal, inEncaps,
                          out outEncaps);
            test(false);
        }
        catch (Ice.UnknownLocalException ex)
        {
            // The server thrown an UnsupportedEncodingException
            test(ex.unknown.IndexOf("UnsupportedEncodingException") > 0);
        }

        WriteLine("ok");

        Write("testing protocol versioning... ");
        Flush();
        ref20 = "test -p 2.0:" + app.getTestEndpoint(0);
        cl20  = Test.MyClassPrxHelper.uncheckedCast(communicator.stringToProxy(ref20));
        try
        {
            cl20.ice_ping();
            test(false);
        }
        catch (Ice.UnsupportedProtocolException)
        {
            // Server 2.0 proxy doesn't support 1.0 version.
        }

        ref10 = "test -p 1.0:" + app.getTestEndpoint(0);
        cl10  = Test.MyClassPrxHelper.uncheckedCast(communicator.stringToProxy(ref10));
        cl10.ice_ping();

        // 1.3 isn't supported but since a 1.3 proxy supports 1.1, the
        // call will use the 1.1 protocol
        ref13 = "test -p 1.3:" + app.getTestEndpoint(0);
        cl13  = Test.MyClassPrxHelper.uncheckedCast(communicator.stringToProxy(ref13));
        cl13.ice_ping();
        cl13.end_ice_ping(cl13.begin_ice_ping());
        WriteLine("ok");

        Write("testing opaque endpoints... ");
        Flush();

        try
        {
            // Invalid -x option
            communicator.stringToProxy("id:opaque -t 99 -v abcd -x abc");
            test(false);
        }
        catch (Ice.EndpointParseException)
        {
        }

        try
        {
            // Missing -t and -v
            communicator.stringToProxy("id:opaque");
            test(false);
        }
        catch (Ice.EndpointParseException)
        {
        }

        try
        {
            // Repeated -t
            communicator.stringToProxy("id:opaque -t 1 -t 1 -v abcd");
            test(false);
        }
        catch (Ice.EndpointParseException)
        {
        }

        try
        {
            // Repeated -v
            communicator.stringToProxy("id:opaque -t 1 -v abcd -v abcd");
            test(false);
        }
        catch (Ice.EndpointParseException)
        {
        }

        try
        {
            // Missing -t
            communicator.stringToProxy("id:opaque -v abcd");
            test(false);
        }
        catch (Ice.EndpointParseException)
        {
        }

        try
        {
            // Missing -v
            communicator.stringToProxy("id:opaque -t 1");
            test(false);
        }
        catch (Ice.EndpointParseException)
        {
        }

        try
        {
            // Missing arg for -t
            communicator.stringToProxy("id:opaque -t -v abcd");
            test(false);
        }
        catch (Ice.EndpointParseException)
        {
        }

        try
        {
            // Missing arg for -v
            communicator.stringToProxy("id:opaque -t 1 -v");
            test(false);
        }
        catch (Ice.EndpointParseException)
        {
        }

        try
        {
            // Not a number for -t
            communicator.stringToProxy("id:opaque -t x -v abcd");
            test(false);
        }
        catch (Ice.EndpointParseException)
        {
        }

        try
        {
            // < 0 for -t
            communicator.stringToProxy("id:opaque -t -1 -v abcd");
            test(false);
        }
        catch (Ice.EndpointParseException)
        {
        }

        try
        {
            // Invalid char for -v
            communicator.stringToProxy("id:opaque -t 99 -v x?c");
            test(false);
        }
        catch (Ice.EndpointParseException)
        {
        }

        try
        {
            // Invalid lenght for base64 input
            communicator.stringToProxy("id:opaque -t 99 -v xc");
            test(false);
        }
        catch (Ice.EndpointParseException)
        {
        }

        // Legal TCP endpoint expressed as opaque endpoint
        Ice.ObjectPrx p1   = communicator.stringToProxy("test -e 1.1:opaque -t 1 -e 1.0 -v CTEyNy4wLjAuMeouAAAQJwAAAA==");
        string        pstr = communicator.proxyToString(p1);
        test(pstr.Equals("test -t -e 1.1:tcp -h 127.0.0.1 -p 12010 -t 10000"));

        // Opaque endpoint encoded with 1.1 encoding.
        Ice.ObjectPrx p2 = communicator.stringToProxy("test -e 1.1:opaque -e 1.1 -t 1 -v CTEyNy4wLjAuMeouAAAQJwAAAA==");
        test(communicator.proxyToString(p2).Equals("test -t -e 1.1:tcp -h 127.0.0.1 -p 12010 -t 10000"));

        if (communicator.getProperties().getPropertyAsInt("Ice.IPv6") == 0)
        {
            // Working?
            bool ssl = communicator.getProperties().getProperty("Ice.Default.Protocol").Equals("ssl");
            bool tcp = communicator.getProperties().getProperty("Ice.Default.Protocol").Equals("tcp");

            // Two legal TCP endpoints expressed as opaque endpoints
            p1   = communicator.stringToProxy("test -e 1.0:opaque -e 1.0 -t 1 -v CTEyNy4wLjAuMeouAAAQJwAAAA==:opaque -e 1.0 -t 1 -v CTEyNy4wLjAuMusuAAAQJwAAAA==");
            pstr = communicator.proxyToString(p1);
            test(pstr.Equals("test -t -e 1.0:tcp -h 127.0.0.1 -p 12010 -t 10000:tcp -h 127.0.0.2 -p 12011 -t 10000"));

            // Test that an SSL endpoint and a nonsense endpoint get written back out as an opaque endpoint.
            p1   = communicator.stringToProxy("test -e 1.0:opaque -e 1.0 -t 2 -v CTEyNy4wLjAuMREnAAD/////AA==:opaque -e 1.0 -t 99 -v abch");
            pstr = communicator.proxyToString(p1);
            if (ssl)
            {
                test(pstr.Equals("test -t -e 1.0:ssl -h 127.0.0.1 -p 10001 -t infinite:opaque -t 99 -e 1.0 -v abch"));
            }
            else if (tcp)
            {
                test(pstr.Equals(
                         "test -t -e 1.0:opaque -t 2 -e 1.0 -v CTEyNy4wLjAuMREnAAD/////AA==:opaque -t 99 -e 1.0 -v abch"));
            }
        }

        WriteLine("ok");
        return(cl);
    }
Пример #11
0
    public static void allTests(TestCommon.Application app)
    {
        Ice.Communicator communicator = app.communicator();
        Write("testing communicator operations... ");
        Flush();
        {
            //
            // Test: Exercise addAdminFacet, findAdminFacet, removeAdminFacet with a typical configuration.
            //
            Ice.InitializationData init = new Ice.InitializationData();
            init.properties = Ice.Util.createProperties();
            init.properties.setProperty("Ice.Admin.Endpoints", "tcp -h 127.0.0.1");
            init.properties.setProperty("Ice.Admin.InstanceName", "Test");
            Ice.Communicator com = Ice.Util.initialize(init);
            testFacets(com, true);
            com.destroy();
        }
        {
            //
            // Test: Verify that the operations work correctly in the presence of facet filters.
            //
            Ice.InitializationData init = new Ice.InitializationData();
            init.properties = Ice.Util.createProperties();
            init.properties.setProperty("Ice.Admin.Endpoints", "tcp -h 127.0.0.1");
            init.properties.setProperty("Ice.Admin.InstanceName", "Test");
            init.properties.setProperty("Ice.Admin.Facets", "Properties");
            Ice.Communicator com = Ice.Util.initialize(init);
            testFacets(com, false);
            com.destroy();
        }
        {
            //
            // Test: Verify that the operations work correctly with the Admin object disabled.
            //
            Ice.Communicator com = Ice.Util.initialize();
            testFacets(com, false);
            com.destroy();
        }
        {
            //
            // Test: Verify that the operations work correctly with Ice.Admin.Enabled=1
            //
            Ice.InitializationData init = new Ice.InitializationData();
            init.properties = Ice.Util.createProperties();
            init.properties.setProperty("Ice.Admin.Enabled", "1");
            Ice.Communicator com = Ice.Util.initialize(init);
            test(com.getAdmin() == null);
            Ice.Identity id = Ice.Util.stringToIdentity("test-admin");
            try
            {
                com.createAdmin(null, id);
                test(false);
            }
            catch (Ice.InitializationException)
            {
            }

            Ice.ObjectAdapter adapter = com.createObjectAdapter("");
            test(com.createAdmin(adapter, id) != null);
            test(com.getAdmin() != null);

            testFacets(com, true);
            com.destroy();
        }
        {
            //
            // Test: Verify that the operations work correctly when creation of the Admin object is delayed.
            //
            Ice.InitializationData init = new Ice.InitializationData();
            init.properties = Ice.Util.createProperties();
            init.properties.setProperty("Ice.Admin.Endpoints", "tcp -h 127.0.0.1");
            init.properties.setProperty("Ice.Admin.InstanceName", "Test");
            init.properties.setProperty("Ice.Admin.DelayCreation", "1");
            Ice.Communicator com = Ice.Util.initialize(init);
            testFacets(com, true);
            com.getAdmin();
            testFacets(com, true);
            com.destroy();
        }
        WriteLine("ok");

        string @ref = "factory:" + app.getTestEndpoint(0) + " -t 10000";
        RemoteCommunicatorFactoryPrx factory =
            RemoteCommunicatorFactoryPrxHelper.uncheckedCast(communicator.stringToProxy(@ref));

        Write("testing process facet... ");
        Flush();
        {
            //
            // Test: Verify that Process::shutdown() operation shuts down the communicator.
            //
            Dictionary <string, string> props = new Dictionary <string, string>();
            props.Add("Ice.Admin.Endpoints", "tcp -h 127.0.0.1");
            props.Add("Ice.Admin.InstanceName", "Test");
            RemoteCommunicatorPrx com  = factory.createCommunicator(props);
            Ice.ObjectPrx         obj  = com.getAdmin();
            Ice.ProcessPrx        proc = Ice.ProcessPrxHelper.checkedCast(obj, "Process");
            proc.shutdown();
            com.waitForShutdown();
            com.destroy();
        }
        WriteLine("ok");

        Write("testing properties facet... ");
        Flush();
        {
            Dictionary <string, string> props = new Dictionary <string, string>();
            props.Add("Ice.Admin.Endpoints", "tcp -h 127.0.0.1");
            props.Add("Ice.Admin.InstanceName", "Test");
            props.Add("Prop1", "1");
            props.Add("Prop2", "2");
            props.Add("Prop3", "3");
            RemoteCommunicatorPrx  com = factory.createCommunicator(props);
            Ice.ObjectPrx          obj = com.getAdmin();
            Ice.PropertiesAdminPrx pa  = Ice.PropertiesAdminPrxHelper.checkedCast(obj, "Properties");

            //
            // Test: PropertiesAdmin::getProperty()
            //
            test(pa.getProperty("Prop2").Equals("2"));
            test(pa.getProperty("Bogus").Equals(""));

            //
            // Test: PropertiesAdmin::getProperties()
            //
            Dictionary <string, string> pd = pa.getPropertiesForPrefix("");
            test(pd.Count == 5);
            test(pd["Ice.Admin.Endpoints"].Equals("tcp -h 127.0.0.1"));
            test(pd["Ice.Admin.InstanceName"].Equals("Test"));
            test(pd["Prop1"].Equals("1"));
            test(pd["Prop2"].Equals("2"));
            test(pd["Prop3"].Equals("3"));

            Dictionary <string, string> changes;

            //
            // Test: PropertiesAdmin::setProperties()
            //
            Dictionary <string, string> setProps = new Dictionary <string, string>();
            setProps.Add("Prop1", "10"); // Changed
            setProps.Add("Prop2", "20"); // Changed
            setProps.Add("Prop3", "");   // Removed
            setProps.Add("Prop4", "4");  // Added
            setProps.Add("Prop5", "5");  // Added
            pa.setProperties(setProps);
            test(pa.getProperty("Prop1").Equals("10"));
            test(pa.getProperty("Prop2").Equals("20"));
            test(pa.getProperty("Prop3").Equals(""));
            test(pa.getProperty("Prop4").Equals("4"));
            test(pa.getProperty("Prop5").Equals("5"));
            changes = com.getChanges();
            test(changes.Count == 5);
            test(changes["Prop1"].Equals("10"));
            test(changes["Prop2"].Equals("20"));
            test(changes["Prop3"].Equals(""));
            test(changes["Prop4"].Equals("4"));
            test(changes["Prop5"].Equals("5"));
            pa.setProperties(setProps);
            changes = com.getChanges();
            test(changes.Count == 0);

            com.destroy();
        }
        WriteLine("ok");

        Write("testing logger facet... ");
        Flush();
        {
            Dictionary <String, String> props = new Dictionary <String, String>();
            props.Add("Ice.Admin.Endpoints", "tcp -h 127.0.0.1");
            props.Add("Ice.Admin.InstanceName", "Test");
            props.Add("NullLogger", "1");
            RemoteCommunicatorPrx com = factory.createCommunicator(props);

            com.trace("testCat", "trace");
            com.warning("warning");
            com.error("error");
            com.print("print");

            Ice.ObjectPrx      obj    = com.getAdmin();
            Ice.LoggerAdminPrx logger = Ice.LoggerAdminPrxHelper.checkedCast(obj, "Logger");
            test(logger != null);

            string prefix = null;

            //
            // Get all
            //
            Ice.LogMessage[] logMessages = logger.getLog(null, null, -1, out prefix);

            test(logMessages.Length == 4);
            test(prefix.Equals("NullLogger"));
            test(logMessages[0].traceCategory.Equals("testCat") && logMessages[0].message.Equals("trace"));
            test(logMessages[1].message.Equals("warning"));
            test(logMessages[2].message.Equals("error"));
            test(logMessages[3].message.Equals("print"));

            //
            // Get only errors and warnings
            //
            com.error("error2");
            com.print("print2");
            com.trace("testCat", "trace2");
            com.warning("warning2");

            Ice.LogMessageType[] messageTypes = { Ice.LogMessageType.ErrorMessage, Ice.LogMessageType.WarningMessage };

            logMessages = logger.getLog(messageTypes, null, -1, out prefix);

            test(logMessages.Length == 4);
            test(prefix.Equals("NullLogger"));

            foreach (var msg in logMessages)
            {
                test(msg.type == Ice.LogMessageType.ErrorMessage || msg.type == Ice.LogMessageType.WarningMessage);
            }

            //
            // Get only errors and traces with Cat = "testCat"
            //
            com.trace("testCat2", "A");
            com.trace("testCat", "trace3");
            com.trace("testCat2", "B");

            messageTypes = new Ice.LogMessageType[] { Ice.LogMessageType.ErrorMessage, Ice.LogMessageType.TraceMessage };
            string[] categories = { "testCat" };
            logMessages = logger.getLog(messageTypes, categories, -1, out prefix);
            test(logMessages.Length == 5);
            test(prefix.Equals("NullLogger"));

            foreach (var msg in logMessages)
            {
                test(msg.type == Ice.LogMessageType.ErrorMessage ||
                     (msg.type == Ice.LogMessageType.TraceMessage && msg.traceCategory.Equals("testCat")));
            }

            //
            // Same, but limited to last 2 messages (trace3 + error3)
            //
            com.error("error3");

            logMessages = logger.getLog(messageTypes, categories, 2, out prefix);
            test(logMessages.Length == 2);
            test(prefix.Equals("NullLogger"));

            test(logMessages[0].message.Equals("trace3"));
            test(logMessages[1].message.Equals("error3"));

            //
            // Now, test RemoteLogger
            //
            Ice.ObjectAdapter adapter =
                communicator.createObjectAdapterWithEndpoints("RemoteLoggerAdapter", "tcp -h localhost");

            RemoteLoggerI remoteLogger = new RemoteLoggerI();

            Ice.RemoteLoggerPrx myProxy = Ice.RemoteLoggerPrxHelper.uncheckedCast(adapter.addWithUUID(remoteLogger));

            adapter.activate();

            //
            // No filtering
            //
            logMessages = logger.getLog(null, null, -1, out prefix);
            remoteLogger.checkNextInit(prefix, logMessages);

            logger.attachRemoteLogger(myProxy, null, null, -1);
            remoteLogger.wait(1);

            remoteLogger.checkNextLog(Ice.LogMessageType.TraceMessage, "rtrace", "testCat");
            remoteLogger.checkNextLog(Ice.LogMessageType.WarningMessage, "rwarning", "");
            remoteLogger.checkNextLog(Ice.LogMessageType.ErrorMessage, "rerror", "");
            remoteLogger.checkNextLog(Ice.LogMessageType.PrintMessage, "rprint", "");

            com.trace("testCat", "rtrace");
            com.warning("rwarning");
            com.error("rerror");
            com.print("rprint");

            remoteLogger.wait(4);

            test(logger.detachRemoteLogger(myProxy));
            test(!logger.detachRemoteLogger(myProxy));

            //
            // Use Error + Trace with "traceCat" filter with 4 limit
            //
            logMessages = logger.getLog(messageTypes, categories, 4, out prefix);
            test(logMessages.Length == 4);
            remoteLogger.checkNextInit(prefix, logMessages);

            logger.attachRemoteLogger(myProxy, messageTypes, categories, 4);
            remoteLogger.wait(1);

            remoteLogger.checkNextLog(Ice.LogMessageType.TraceMessage, "rtrace2", "testCat");
            remoteLogger.checkNextLog(Ice.LogMessageType.ErrorMessage, "rerror2", "");

            com.warning("rwarning2");
            com.trace("testCat", "rtrace2");
            com.warning("rwarning3");
            com.error("rerror2");
            com.print("rprint2");

            remoteLogger.wait(2);

            //
            // Attempt reconnection with slightly different proxy
            //
            try
            {
                logger.attachRemoteLogger(Ice.RemoteLoggerPrxHelper.uncheckedCast(myProxy.ice_oneway()),
                                          messageTypes, categories, 4);
                test(false);
            }
            catch (Ice.RemoteLoggerAlreadyAttachedException)
            {
                // expected
            }

            com.destroy();
        }
        WriteLine("ok");


        Write("testing custom facet... ");
        Flush();
        {
            //
            // Test: Verify that the custom facet is present.
            //
            Dictionary <string, string> props = new Dictionary <string, string>();
            props.Add("Ice.Admin.Endpoints", "tcp -h 127.0.0.1");
            props.Add("Ice.Admin.InstanceName", "Test");
            RemoteCommunicatorPrx com = factory.createCommunicator(props);
            Ice.ObjectPrx         obj = com.getAdmin();
            TestFacetPrx          tf  = TestFacetPrxHelper.checkedCast(obj, "TestFacet");
            tf.op();
            com.destroy();
        }
        WriteLine("ok");

        Write("testing facet filtering... ");
        Flush();
        {
            //
            // Test: Set Ice.Admin.Facets to expose only the Properties facet,
            // meaning no other facet is available.
            //
            Dictionary <string, string> props = new Dictionary <string, string>();
            props.Add("Ice.Admin.Endpoints", "tcp -h 127.0.0.1");
            props.Add("Ice.Admin.InstanceName", "Test");
            props.Add("Ice.Admin.Facets", "Properties");
            RemoteCommunicatorPrx com  = factory.createCommunicator(props);
            Ice.ObjectPrx         obj  = com.getAdmin();
            Ice.ProcessPrx        proc = Ice.ProcessPrxHelper.checkedCast(obj, "Process");
            test(proc == null);
            TestFacetPrx tf = TestFacetPrxHelper.checkedCast(obj, "TestFacet");
            test(tf == null);
            com.destroy();
        }
        {
            //
            // Test: Set Ice.Admin.Facets to expose only the Process facet,
            // meaning no other facet is available.
            //
            Dictionary <string, string> props = new Dictionary <string, string>();
            props.Add("Ice.Admin.Endpoints", "tcp -h 127.0.0.1");
            props.Add("Ice.Admin.InstanceName", "Test");
            props.Add("Ice.Admin.Facets", "Process");
            RemoteCommunicatorPrx  com = factory.createCommunicator(props);
            Ice.ObjectPrx          obj = com.getAdmin();
            Ice.PropertiesAdminPrx pa  = Ice.PropertiesAdminPrxHelper.checkedCast(obj, "Properties");
            test(pa == null);
            TestFacetPrx tf = TestFacetPrxHelper.checkedCast(obj, "TestFacet");
            test(tf == null);
            com.destroy();
        }
        {
            //
            // Test: Set Ice.Admin.Facets to expose only the TestFacet facet,
            // meaning no other facet is available.
            //
            Dictionary <string, string> props = new Dictionary <string, string>();
            props.Add("Ice.Admin.Endpoints", "tcp -h 127.0.0.1");
            props.Add("Ice.Admin.InstanceName", "Test");
            props.Add("Ice.Admin.Facets", "TestFacet");
            RemoteCommunicatorPrx  com = factory.createCommunicator(props);
            Ice.ObjectPrx          obj = com.getAdmin();
            Ice.PropertiesAdminPrx pa  = Ice.PropertiesAdminPrxHelper.checkedCast(obj, "Properties");
            test(pa == null);
            Ice.ProcessPrx proc = Ice.ProcessPrxHelper.checkedCast(obj, "Process");
            test(proc == null);
            com.destroy();
        }
        {
            //
            // Test: Set Ice.Admin.Facets to expose two facets. Use whitespace to separate the
            // facet names.
            //
            Dictionary <string, string> props = new Dictionary <string, string>();
            props.Add("Ice.Admin.Endpoints", "tcp -h 127.0.0.1");
            props.Add("Ice.Admin.InstanceName", "Test");
            props.Add("Ice.Admin.Facets", "Properties TestFacet");
            RemoteCommunicatorPrx  com = factory.createCommunicator(props);
            Ice.ObjectPrx          obj = com.getAdmin();
            Ice.PropertiesAdminPrx pa  = Ice.PropertiesAdminPrxHelper.checkedCast(obj, "Properties");
            test(pa.getProperty("Ice.Admin.InstanceName").Equals("Test"));
            TestFacetPrx tf = TestFacetPrxHelper.checkedCast(obj, "TestFacet");
            tf.op();
            Ice.ProcessPrx proc = Ice.ProcessPrxHelper.checkedCast(obj, "Process");
            test(proc == null);
            com.destroy();
        }
        {
            //
            // Test: Set Ice.Admin.Facets to expose two facets. Use a comma to separate the
            // facet names.
            //
            Dictionary <string, string> props = new Dictionary <string, string>();
            props.Add("Ice.Admin.Endpoints", "tcp -h 127.0.0.1");
            props.Add("Ice.Admin.InstanceName", "Test");
            props.Add("Ice.Admin.Facets", "TestFacet, Process");
            RemoteCommunicatorPrx  com = factory.createCommunicator(props);
            Ice.ObjectPrx          obj = com.getAdmin();
            Ice.PropertiesAdminPrx pa  = Ice.PropertiesAdminPrxHelper.checkedCast(obj, "Properties");
            test(pa == null);
            TestFacetPrx tf = TestFacetPrxHelper.checkedCast(obj, "TestFacet");
            tf.op();
            Ice.ProcessPrx proc = Ice.ProcessPrxHelper.checkedCast(obj, "Process");
            proc.shutdown();
            com.waitForShutdown();
            com.destroy();
        }
        WriteLine("ok");

        factory.shutdown();
    }
Пример #12
0
    allTests(Ice.Communicator communicator)
    {
        Ice.ObjectAdapter oa = communicator.createObjectAdapterWithEndpoints("MyOA", "tcp -h localhost");
        oa.activate();

        Ice.Object servant = new MyObjectI();

        //
        // Register default servant with category "foo"
        //
        oa.addDefaultServant(servant, "foo");

        //
        // Start test
        //
        Console.Out.Write("testing single category... ");
        Console.Out.Flush();

        Ice.Object r = oa.findDefaultServant("foo");
        test(r == servant);

        r = oa.findDefaultServant("bar");
        test(r == null);

        Ice.Identity identity = new Ice.Identity();
        identity.category = "foo";

        string[] names = new string[] { "foo", "bar", "x", "y", "abcdefg" };

        Test.MyObjectPrx prx = null;
        for (int idx = 0; idx < 5; ++idx)
        {
            identity.name = names[idx];
            prx           = Test.MyObjectPrxHelper.uncheckedCast(oa.createProxy(identity));
            prx.ice_ping();
            test(prx.getName() == names[idx]);
        }

        identity.name = "ObjectNotExist";
        prx           = Test.MyObjectPrxHelper.uncheckedCast(oa.createProxy(identity));
        try
        {
            prx.ice_ping();
            test(false);
        }
        catch (Ice.ObjectNotExistException)
        {
            // Expected
        }

        try
        {
            prx.getName();
            test(false);
        }
        catch (Ice.ObjectNotExistException)
        {
            // Expected
        }

        identity.name = "FacetNotExist";
        prx           = Test.MyObjectPrxHelper.uncheckedCast(oa.createProxy(identity));
        try
        {
            prx.ice_ping();
            test(false);
        }
        catch (Ice.FacetNotExistException)
        {
            // Expected
        }

        try
        {
            prx.getName();
            test(false);
        }
        catch (Ice.FacetNotExistException)
        {
            // Expected
        }

        identity.category = "bar";
        for (int idx = 0; idx < 5; idx++)
        {
            identity.name = names[idx];
            prx           = Test.MyObjectPrxHelper.uncheckedCast(oa.createProxy(identity));

            try
            {
                prx.ice_ping();
                test(false);
            }
            catch (Ice.ObjectNotExistException)
            {
                // Expected
            }

            try
            {
                prx.getName();
                test(false);
            }
            catch (Ice.ObjectNotExistException)
            {
                // Expected
            }
        }

        oa.removeDefaultServant("foo");
        identity.category = "foo";
        prx = Test.MyObjectPrxHelper.uncheckedCast(oa.createProxy(identity));
        try
        {
            prx.ice_ping();
        }
        catch (Ice.ObjectNotExistException)
        {
            // Expected
        }

        Console.Out.WriteLine("ok");

        Console.Out.Write("testing default category... ");
        Console.Out.Flush();

        oa.addDefaultServant(servant, "");

        r = oa.findDefaultServant("bar");
        test(r == null);

        r = oa.findDefaultServant("");
        test(r == servant);

        for (int idx = 0; idx < 5; ++idx)
        {
            identity.name = names[idx];
            prx           = Test.MyObjectPrxHelper.uncheckedCast(oa.createProxy(identity));
            prx.ice_ping();
            test(prx.getName() == names[idx]);
        }

        Console.Out.WriteLine("ok");
    }
Пример #13
0
    public static TestIntfPrx allTests(TestCommon.Application app)
    {
        Ice.Communicator communicator = app.communicator();
        Write("testing stringToProxy... ");
        Flush();
        string @ref = "test:" + app.getTestEndpoint(0);

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

        Write("testing checked cast... ");
        Flush();
        TestIntfPrx obj = TestIntfPrxHelper.checkedCast(@base);

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

        {
            Write("creating/destroying/recreating object adapter... ");
            Flush();
            Ice.ObjectAdapter adapter =
                communicator.createObjectAdapterWithEndpoints("TransientTestAdapter", "default");
            try
            {
                communicator.createObjectAdapterWithEndpoints("TransientTestAdapter", "default");
                test(false);
            }
            catch (Ice.AlreadyRegisteredException)
            {
            }
            adapter.destroy();

            //
            // Use a different port than the first adapter to avoid an "address already in use" error.
            //
            adapter = communicator.createObjectAdapterWithEndpoints("TransientTestAdapter", "default");
            adapter.destroy();
            Console.Out.WriteLine("ok");
        }

        Write("creating/activating/deactivating object adapter in one operation... ");
        Flush();
        obj.transient();
        obj.end_transient(obj.begin_transient());
        WriteLine("ok");

        {
            Write("testing connection closure... ");
            Flush();
            for (int i = 0; i < 10; ++i)
            {
                Ice.InitializationData initData = new Ice.InitializationData();
                initData.properties = communicator.getProperties().ice_clone_();
                Ice.Communicator comm = Ice.Util.initialize(initData);
                comm.stringToProxy("test:" + app.getTestEndpoint(0)).begin_ice_ping();
                comm.destroy();
            }
            WriteLine("ok");
        }

        Write("testing object adapter published endpoints... ");
        Flush();
        {
            communicator.getProperties().setProperty("PAdapter.PublishedEndpoints", "tcp -h localhost -p 12345 -t 30000");
            Ice.ObjectAdapter adapter = communicator.createObjectAdapter("PAdapter");
            test(adapter.getPublishedEndpoints().Length == 1);
            Ice.Endpoint endpt = adapter.getPublishedEndpoints()[0];
            test(endpt.ToString().Equals("tcp -h localhost -p 12345 -t 30000"));
            Ice.ObjectPrx prx =
                communicator.stringToProxy("dummy:tcp -h localhost -p 12346 -t 20000:tcp -h localhost -p 12347 -t 10000");
            adapter.setPublishedEndpoints(prx.ice_getEndpoints());
            test(adapter.getPublishedEndpoints().Length == 2);
            Ice.Identity id = new Ice.Identity();
            id.name = "dummy";
            test(IceUtilInternal.Arrays.Equals(adapter.createProxy(id).ice_getEndpoints(), prx.ice_getEndpoints()));
            test(IceUtilInternal.Arrays.Equals(adapter.getPublishedEndpoints(), prx.ice_getEndpoints()));
            adapter.refreshPublishedEndpoints();
            test(adapter.getPublishedEndpoints().Length == 1);
            test(adapter.getPublishedEndpoints()[0].Equals(endpt));
            communicator.getProperties().setProperty("PAdapter.PublishedEndpoints", "tcp -h localhost -p 12345 -t 20000");
            adapter.refreshPublishedEndpoints();
            test(adapter.getPublishedEndpoints().Length == 1);
            test(adapter.getPublishedEndpoints()[0].ToString().Equals("tcp -h localhost -p 12345 -t 20000"));
            adapter.destroy();
            test(adapter.getPublishedEndpoints().Length == 0);
        }
        WriteLine("ok");

        if (obj.ice_getConnection() != null)
        {
            Write("testing object adapter with bi-dir connection... ");
            Flush();
            Ice.ObjectAdapter adapter = communicator.createObjectAdapter("");
            obj.ice_getConnection().setAdapter(adapter);
            obj.ice_getConnection().setAdapter(null);
            adapter.deactivate();
            try
            {
                obj.ice_getConnection().setAdapter(adapter);
                test(false);
            }
            catch (Ice.ObjectAdapterDeactivatedException)
            {
            }
            WriteLine("ok");
        }

        Write("testing object adapter with router... ");
        Flush();
        {
            Ice.Identity routerId = new Ice.Identity();
            routerId.name = "router";
            Ice.RouterPrx     router  = Ice.RouterPrxHelper.uncheckedCast(@base.ice_identity(routerId).ice_connectionId("rc"));
            Ice.ObjectAdapter adapter = communicator.createObjectAdapterWithRouter("", router);
            test(adapter.getPublishedEndpoints().Length == 1);
            test(adapter.getPublishedEndpoints()[0].ToString().Equals("tcp -h localhost -p 23456 -t 30000"));
            adapter.refreshPublishedEndpoints();
            test(adapter.getPublishedEndpoints().Length == 1);
            test(adapter.getPublishedEndpoints()[0].ToString().Equals("tcp -h localhost -p 23457 -t 30000"));
            try
            {
                adapter.setPublishedEndpoints(router.ice_getEndpoints());
                test(false);
            }
            catch (ArgumentException)
            {
                // Expected.
            }
            adapter.destroy();

            try
            {
                routerId.name = "test";
                router        = Ice.RouterPrxHelper.uncheckedCast(@base.ice_identity(routerId));
                communicator.createObjectAdapterWithRouter("", router);
                test(false);
            }
            catch (Ice.OperationNotExistException)
            {
                // Expected: the "test" object doesn't implement Ice::Router!
            }

            try
            {
                router = Ice.RouterPrxHelper.uncheckedCast(communicator.stringToProxy("test:" + app.getTestEndpoint(1)));
                communicator.createObjectAdapterWithRouter("", router);
                test(false);
            }
            catch (Ice.ConnectFailedException)
            {
            }
        }
        WriteLine("ok");

        Write("testing object adapter creation with port in use... ");
        Flush();
        {
            var adapter1 = communicator.createObjectAdapterWithEndpoints("Adpt1", app.getTestEndpoint(10));
            try
            {
                communicator.createObjectAdapterWithEndpoints("Adpt2", app.getTestEndpoint(10));
                test(false);
            }
            catch (Ice.LocalException)
            {
                // Expected can't re-use the same endpoint.
            }
            adapter1.destroy();
        }
        WriteLine("ok");

        Write("deactivating object adapter in the server... ");
        Flush();
        obj.deactivate();
        WriteLine("ok");

        Write("testing whether server is gone... ");
        Flush();
        try
        {
            obj.ice_timeout(100).ice_ping(); // Use timeout to speed up testing on Windows
            test(false);
        }
        catch (Ice.LocalException)
        {
            WriteLine("ok");
        }

        return(obj);
    }
Пример #14
0
    public static TestIntfPrx allTests(TestCommon.Application app, bool collocated)
    {
        Ice.Communicator communicator = app.communicator();
        Write("testing stringToProxy... ");
        Flush();
        String @ref = "Test:" + app.getTestEndpoint(0) + " -t 2000";

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

        Write("testing checked cast... ");
        Flush();
        TestIntfPrx testPrx = TestIntfPrxHelper.checkedCast(@base);

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

        Write("base... ");
        Flush();
        {
            try
            {
                testPrx.baseAsBase();
                test(false);
            }
            catch (Base b)
            {
                test(b.b.Equals("Base.b"));
                test(b.GetType().FullName.Equals("Test.Base"));
            }
            catch (Exception)
            {
                test(false);
            }
        }
        WriteLine("ok");

        Write("base (AMI)... ");
        Flush();
        {
            Callback cb = new Callback();
            testPrx.begin_baseAsBase().whenCompleted(
                () =>
            {
                test(false);
            },
                (Ice.Exception ex) =>
            {
                try
                {
                    throw ex;
                }
                catch (Base b)
                {
                    test(b.b.Equals("Base.b"));
                    test(b.GetType().Name.Equals("Base"));
                }
                catch (Exception)
                {
                    test(false);
                }
                cb.called();
            });
            cb.check();

            try
            {
                testPrx.baseAsBaseAsync().Wait();
                test(false);
            }
            catch (AggregateException ae)
            {
                try
                {
                    throw ae.InnerException;
                }
                catch (Base b)
                {
                    test(b.b.Equals("Base.b"));
                    test(b.GetType().Name.Equals("Base"));
                }
                catch (Exception)
                {
                    test(false);
                }
            }
        }
        WriteLine("ok");

        Write("slicing of unknown derived... ");
        Flush();
        {
            try
            {
                testPrx.unknownDerivedAsBase();
                test(false);
            }
            catch (Base b)
            {
                test(b.b.Equals("UnknownDerived.b"));
                test(b.GetType().FullName.Equals("Test.Base"));
            }
            catch (Exception)
            {
                test(false);
            }
        }
        WriteLine("ok");

        Write("slicing of unknown derived (AMI)... ");
        Flush();
        {
            Callback cb = new Callback();
            testPrx.begin_unknownDerivedAsBase().whenCompleted(
                () =>
            {
                test(false);
            },
                (Ice.Exception ex) =>
            {
                try
                {
                    throw ex;
                }
                catch (Base b)
                {
                    test(b.b.Equals("UnknownDerived.b"));
                    test(b.GetType().Name.Equals("Base"));
                }
                catch (Exception)
                {
                    test(false);
                }
                cb.called();
            });
            cb.check();

            try
            {
                testPrx.unknownDerivedAsBaseAsync().Wait();
                test(false);
            }
            catch (AggregateException ae)
            {
                try
                {
                    throw ae.InnerException;
                }
                catch (Base b)
                {
                    test(b.b.Equals("UnknownDerived.b"));
                    test(b.GetType().Name.Equals("Base"));
                }
                catch (Exception)
                {
                    test(false);
                }
            }
        }
        WriteLine("ok");

        Write("non-slicing of known derived as base... ");
        Flush();
        {
            try
            {
                testPrx.knownDerivedAsBase();
                test(false);
            }
            catch (KnownDerived k)
            {
                test(k.b.Equals("KnownDerived.b"));
                test(k.kd.Equals("KnownDerived.kd"));
                test(k.GetType().FullName.Equals("Test.KnownDerived"));
            }
            catch (Exception)
            {
                test(false);
            }
        }
        WriteLine("ok");

        Write("non-slicing of known derived as base (AMI)... ");
        Flush();
        {
            Callback cb = new Callback();
            testPrx.begin_knownDerivedAsBase().whenCompleted(
                () =>
            {
                test(false);
            },
                (Ice.Exception ex) =>
            {
                try
                {
                    throw ex;
                }
                catch (KnownDerived k)
                {
                    test(k.b.Equals("KnownDerived.b"));
                    test(k.kd.Equals("KnownDerived.kd"));
                    test(k.GetType().Name.Equals("KnownDerived"));
                }
                catch (Exception)
                {
                    test(false);
                }
                cb.called();
            });
            cb.check();

            try
            {
                testPrx.knownDerivedAsBaseAsync().Wait();
                test(false);
            }
            catch (AggregateException ae)
            {
                try
                {
                    throw ae.InnerException;
                }
                catch (KnownDerived k)
                {
                    test(k.b.Equals("KnownDerived.b"));
                    test(k.kd.Equals("KnownDerived.kd"));
                    test(k.GetType().Name.Equals("KnownDerived"));
                }
                catch (Exception)
                {
                    test(false);
                }
            }
        }
        WriteLine("ok");

        Write("non-slicing of known derived as derived... ");
        Flush();
        {
            try
            {
                testPrx.knownDerivedAsKnownDerived();
                test(false);
            }
            catch (KnownDerived k)
            {
                test(k.b.Equals("KnownDerived.b"));
                test(k.kd.Equals("KnownDerived.kd"));
                test(k.GetType().FullName.Equals("Test.KnownDerived"));
            }
            catch (Exception)
            {
                test(false);
            }
        }
        WriteLine("ok");

        Write("non-slicing of known derived as derived (AMI)... ");
        Flush();
        {
            Callback cb = new Callback();
            testPrx.begin_knownDerivedAsKnownDerived().whenCompleted(
                () =>
            {
                test(false);
            },
                (Ice.Exception ex) =>
            {
                try
                {
                    throw ex;
                }
                catch (KnownDerived k)
                {
                    test(k.b.Equals("KnownDerived.b"));
                    test(k.kd.Equals("KnownDerived.kd"));
                    test(k.GetType().Name.Equals("KnownDerived"));
                }
                catch (Exception)
                {
                    test(false);
                }
                cb.called();
            });
            cb.check();

            try
            {
                testPrx.knownDerivedAsKnownDerivedAsync().Wait();
                test(false);
            }
            catch (AggregateException ae)
            {
                try
                {
                    throw ae.InnerException;
                }
                catch (KnownDerived k)
                {
                    test(k.b.Equals("KnownDerived.b"));
                    test(k.kd.Equals("KnownDerived.kd"));
                    test(k.GetType().Name.Equals("KnownDerived"));
                }
                catch (Exception)
                {
                    test(false);
                }
            }
        }
        WriteLine("ok");

        Write("slicing of unknown intermediate as base... ");
        Flush();
        {
            try
            {
                testPrx.unknownIntermediateAsBase();
                test(false);
            }
            catch (Base b)
            {
                test(b.b.Equals("UnknownIntermediate.b"));
                test(b.GetType().FullName.Equals("Test.Base"));
            }
            catch (Exception)
            {
                test(false);
            }
        }
        WriteLine("ok");

        Write("slicing of unknown intermediate as base (AMI)... ");
        Flush();
        {
            Callback cb = new Callback();
            testPrx.begin_unknownIntermediateAsBase().whenCompleted(
                () =>
            {
                test(false);
            },
                (Ice.Exception ex) =>
            {
                try
                {
                    throw ex;
                }
                catch (Base b)
                {
                    test(b.b.Equals("UnknownIntermediate.b"));
                    test(b.GetType().Name.Equals("Base"));
                }
                catch (Exception)
                {
                    test(false);
                }
                cb.called();
            });
            cb.check();

            try
            {
                testPrx.unknownIntermediateAsBaseAsync().Wait();
                test(false);
            }
            catch (AggregateException ae)
            {
                try
                {
                    throw ae.InnerException;
                }
                catch (Base b)
                {
                    test(b.b.Equals("UnknownIntermediate.b"));
                    test(b.GetType().Name.Equals("Base"));
                }
                catch (Exception)
                {
                    test(false);
                }
            }
        }
        WriteLine("ok");

        Write("slicing of known intermediate as base... ");
        Flush();
        {
            try
            {
                testPrx.knownIntermediateAsBase();
                test(false);
            }
            catch (KnownIntermediate ki)
            {
                test(ki.b.Equals("KnownIntermediate.b"));
                test(ki.ki.Equals("KnownIntermediate.ki"));
                test(ki.GetType().FullName.Equals("Test.KnownIntermediate"));
            }
            catch (Exception)
            {
                test(false);
            }
        }
        WriteLine("ok");

        Write("slicing of known intermediate as base (AMI)... ");
        Flush();
        {
            Callback cb = new Callback();
            testPrx.begin_knownIntermediateAsBase().whenCompleted(
                () =>
            {
                test(false);
            },
                (Ice.Exception ex) =>
            {
                try
                {
                    throw ex;
                }
                catch (KnownIntermediate ki)
                {
                    test(ki.b.Equals("KnownIntermediate.b"));
                    test(ki.ki.Equals("KnownIntermediate.ki"));
                    test(ki.GetType().Name.Equals("KnownIntermediate"));
                }
                catch (Exception)
                {
                    test(false);
                }
                cb.called();
            });
            cb.check();

            try
            {
                testPrx.knownIntermediateAsBaseAsync().Wait();
                test(false);
            }
            catch (AggregateException ae)
            {
                try
                {
                    throw ae.InnerException;
                }
                catch (KnownIntermediate ki)
                {
                    test(ki.b.Equals("KnownIntermediate.b"));
                    test(ki.ki.Equals("KnownIntermediate.ki"));
                    test(ki.GetType().Name.Equals("KnownIntermediate"));
                }
                catch (Exception)
                {
                    test(false);
                }
            }
        }
        WriteLine("ok");

        Write("slicing of known most derived as base... ");
        Flush();
        {
            try
            {
                testPrx.knownMostDerivedAsBase();
                test(false);
            }
            catch (KnownMostDerived kmd)
            {
                test(kmd.b.Equals("KnownMostDerived.b"));
                test(kmd.ki.Equals("KnownMostDerived.ki"));
                test(kmd.kmd.Equals("KnownMostDerived.kmd"));
                test(kmd.GetType().FullName.Equals("Test.KnownMostDerived"));
            }
            catch (Exception)
            {
                test(false);
            }
        }
        WriteLine("ok");

        Write("slicing of known most derived as base (AMI)... ");
        Flush();
        {
            Callback cb = new Callback();
            testPrx.begin_knownMostDerivedAsBase().whenCompleted(
                () =>
            {
                test(false);
            },
                (Ice.Exception ex) =>
            {
                try
                {
                    throw ex;
                }
                catch (KnownMostDerived kmd)
                {
                    test(kmd.b.Equals("KnownMostDerived.b"));
                    test(kmd.ki.Equals("KnownMostDerived.ki"));
                    test(kmd.kmd.Equals("KnownMostDerived.kmd"));
                    test(kmd.GetType().Name.Equals("KnownMostDerived"));
                }
                catch (Exception)
                {
                    test(false);
                }
                cb.called();
            });
            cb.check();

            try
            {
                testPrx.knownMostDerivedAsBaseAsync().Wait();
                test(false);
            }
            catch (AggregateException ae)
            {
                try
                {
                    throw ae.InnerException;
                }
                catch (KnownMostDerived kmd)
                {
                    test(kmd.b.Equals("KnownMostDerived.b"));
                    test(kmd.ki.Equals("KnownMostDerived.ki"));
                    test(kmd.kmd.Equals("KnownMostDerived.kmd"));
                    test(kmd.GetType().Name.Equals("KnownMostDerived"));
                }
                catch (Exception)
                {
                    test(false);
                }
            }
        }
        WriteLine("ok");

        Write("non-slicing of known intermediate as intermediate... ");
        Flush();
        {
            try
            {
                testPrx.knownIntermediateAsKnownIntermediate();
                test(false);
            }
            catch (KnownIntermediate ki)
            {
                test(ki.b.Equals("KnownIntermediate.b"));
                test(ki.ki.Equals("KnownIntermediate.ki"));
                test(ki.GetType().FullName.Equals("Test.KnownIntermediate"));
            }
            catch (Exception)
            {
                test(false);
            }
        }
        WriteLine("ok");

        Write("non-slicing of known intermediate as intermediate (AMI)... ");
        Flush();
        {
            Callback cb = new Callback();
            testPrx.begin_knownIntermediateAsKnownIntermediate().whenCompleted(
                () =>
            {
                test(false);
            },
                (Ice.Exception ex) =>
            {
                try
                {
                    throw ex;
                }
                catch (KnownIntermediate ki)
                {
                    test(ki.b.Equals("KnownIntermediate.b"));
                    test(ki.ki.Equals("KnownIntermediate.ki"));
                    test(ki.GetType().Name.Equals("KnownIntermediate"));
                }
                catch (Exception)
                {
                    test(false);
                }
                cb.called();
            });
            cb.check();

            try
            {
                testPrx.knownIntermediateAsKnownIntermediateAsync().Wait();
                test(false);
            }
            catch (AggregateException ae)
            {
                try
                {
                    throw ae.InnerException;
                }
                catch (KnownIntermediate ki)
                {
                    test(ki.b.Equals("KnownIntermediate.b"));
                    test(ki.ki.Equals("KnownIntermediate.ki"));
                    test(ki.GetType().Name.Equals("KnownIntermediate"));
                }
                catch (Exception)
                {
                    test(false);
                }
            }
        }
        WriteLine("ok");

        Write("non-slicing of known most derived as intermediate... ");
        Flush();
        {
            try
            {
                testPrx.knownMostDerivedAsKnownIntermediate();
                test(false);
            }
            catch (KnownMostDerived kmd)
            {
                test(kmd.b.Equals("KnownMostDerived.b"));
                test(kmd.ki.Equals("KnownMostDerived.ki"));
                test(kmd.kmd.Equals("KnownMostDerived.kmd"));
                test(kmd.GetType().FullName.Equals("Test.KnownMostDerived"));
            }
            catch (Exception)
            {
                test(false);
            }
        }
        WriteLine("ok");

        Write("non-slicing of known most derived as intermediate (AMI)... ");
        Flush();
        {
            Callback cb = new Callback();
            testPrx.begin_knownMostDerivedAsKnownIntermediate().whenCompleted(
                () =>
            {
                test(false);
            },
                (Ice.Exception ex) =>
            {
                try
                {
                    throw ex;
                }
                catch (KnownMostDerived kmd)
                {
                    test(kmd.b.Equals("KnownMostDerived.b"));
                    test(kmd.ki.Equals("KnownMostDerived.ki"));
                    test(kmd.kmd.Equals("KnownMostDerived.kmd"));
                    test(kmd.GetType().Name.Equals("KnownMostDerived"));
                }
                catch (Exception)
                {
                    test(false);
                }
                cb.called();
            });
            cb.check();

            try
            {
                testPrx.knownMostDerivedAsKnownIntermediateAsync().Wait();
                test(false);
            }
            catch (AggregateException ae)
            {
                try
                {
                    throw ae.InnerException;
                }
                catch (KnownMostDerived kmd)
                {
                    test(kmd.b.Equals("KnownMostDerived.b"));
                    test(kmd.ki.Equals("KnownMostDerived.ki"));
                    test(kmd.kmd.Equals("KnownMostDerived.kmd"));
                    test(kmd.GetType().Name.Equals("KnownMostDerived"));
                }
                catch (Exception)
                {
                    test(false);
                }
            }
        }
        WriteLine("ok");

        Write("non-slicing of known most derived as most derived... ");
        Flush();
        {
            try
            {
                testPrx.knownMostDerivedAsKnownMostDerived();
                test(false);
            }
            catch (KnownMostDerived kmd)
            {
                test(kmd.b.Equals("KnownMostDerived.b"));
                test(kmd.ki.Equals("KnownMostDerived.ki"));
                test(kmd.kmd.Equals("KnownMostDerived.kmd"));
                test(kmd.GetType().FullName.Equals("Test.KnownMostDerived"));
            }
            catch (Exception)
            {
                test(false);
            }
        }
        WriteLine("ok");

        Write("non-slicing of known most derived as most derived (AMI)... ");
        Flush();
        {
            Callback cb = new Callback();
            testPrx.begin_knownMostDerivedAsKnownMostDerived().whenCompleted(
                () =>
            {
                test(false);
            },
                (Ice.Exception ex) =>
            {
                try
                {
                    throw ex;
                }
                catch (KnownMostDerived kmd)
                {
                    test(kmd.b.Equals("KnownMostDerived.b"));
                    test(kmd.ki.Equals("KnownMostDerived.ki"));
                    test(kmd.kmd.Equals("KnownMostDerived.kmd"));
                    test(kmd.GetType().Name.Equals("KnownMostDerived"));
                }
                catch (Exception)
                {
                    test(false);
                }
                cb.called();
            });
            cb.check();

            try
            {
                testPrx.knownMostDerivedAsKnownMostDerivedAsync().Wait();
                test(false);
            }
            catch (AggregateException ae)
            {
                try
                {
                    throw ae.InnerException;
                }
                catch (KnownMostDerived kmd)
                {
                    test(kmd.b.Equals("KnownMostDerived.b"));
                    test(kmd.ki.Equals("KnownMostDerived.ki"));
                    test(kmd.kmd.Equals("KnownMostDerived.kmd"));
                    test(kmd.GetType().Name.Equals("KnownMostDerived"));
                }
                catch (Exception)
                {
                    test(false);
                }
            }
        }
        WriteLine("ok");

        Write("slicing of unknown most derived, known intermediate as base... ");
        Flush();
        {
            try
            {
                testPrx.unknownMostDerived1AsBase();
                test(false);
            }
            catch (KnownIntermediate ki)
            {
                test(ki.b.Equals("UnknownMostDerived1.b"));
                test(ki.ki.Equals("UnknownMostDerived1.ki"));
                test(ki.GetType().FullName.Equals("Test.KnownIntermediate"));
            }
            catch (Exception)
            {
                test(false);
            }
        }
        WriteLine("ok");

        Write("slicing of unknown most derived, known intermediate as base (AMI)... ");
        Flush();
        {
            Callback cb = new Callback();
            testPrx.begin_unknownMostDerived1AsBase().whenCompleted(
                () =>
            {
                test(false);
            },
                (Ice.Exception ex) =>
            {
                try
                {
                    throw ex;
                }
                catch (KnownIntermediate ki)
                {
                    test(ki.b.Equals("UnknownMostDerived1.b"));
                    test(ki.ki.Equals("UnknownMostDerived1.ki"));
                    test(ki.GetType().Name.Equals("KnownIntermediate"));
                }
                catch (Exception)
                {
                    test(false);
                }
                cb.called();
            });
            cb.check();

            try
            {
                testPrx.unknownMostDerived1AsBaseAsync().Wait();
                test(false);
            }
            catch (AggregateException ae)
            {
                try
                {
                    throw ae.InnerException;
                }
                catch (KnownIntermediate ki)
                {
                    test(ki.b.Equals("UnknownMostDerived1.b"));
                    test(ki.ki.Equals("UnknownMostDerived1.ki"));
                    test(ki.GetType().Name.Equals("KnownIntermediate"));
                }
                catch (Exception)
                {
                    test(false);
                }
            }
        }
        WriteLine("ok");

        Write("slicing of unknown most derived, known intermediate as intermediate... ");
        Flush();
        {
            try
            {
                testPrx.unknownMostDerived1AsKnownIntermediate();
                test(false);
            }
            catch (KnownIntermediate ki)
            {
                test(ki.b.Equals("UnknownMostDerived1.b"));
                test(ki.ki.Equals("UnknownMostDerived1.ki"));
                test(ki.GetType().FullName.Equals("Test.KnownIntermediate"));
            }
            catch (Exception)
            {
                test(false);
            }
        }
        WriteLine("ok");

        Write("slicing of unknown most derived, known intermediate as intermediate (AMI)... ");
        Flush();
        {
            Callback cb = new Callback();
            testPrx.begin_unknownMostDerived1AsKnownIntermediate().whenCompleted(
                () =>
            {
                test(false);
            },
                (Ice.Exception ex) =>
            {
                try
                {
                    throw ex;
                }
                catch (KnownIntermediate ki)
                {
                    test(ki.b.Equals("UnknownMostDerived1.b"));
                    test(ki.ki.Equals("UnknownMostDerived1.ki"));
                    test(ki.GetType().Name.Equals("KnownIntermediate"));
                }
                catch (Exception)
                {
                    test(false);
                }
                cb.called();
            });
            cb.check();

            try
            {
                testPrx.unknownMostDerived1AsKnownIntermediateAsync().Wait();
                test(false);
            }
            catch (AggregateException ae)
            {
                try
                {
                    throw ae.InnerException;
                }
                catch (KnownIntermediate ki)
                {
                    test(ki.b.Equals("UnknownMostDerived1.b"));
                    test(ki.ki.Equals("UnknownMostDerived1.ki"));
                    test(ki.GetType().Name.Equals("KnownIntermediate"));
                }
                catch (Exception)
                {
                    test(false);
                }
            }
        }
        WriteLine("ok");

        Write("slicing of unknown most derived, unknown intermediate thrown as base... ");
        Flush();
        {
            try
            {
                testPrx.unknownMostDerived2AsBase();
                test(false);
            }
            catch (Base b)
            {
                test(b.b.Equals("UnknownMostDerived2.b"));
                test(b.GetType().FullName.Equals("Test.Base"));
            }
            catch (Exception)
            {
                test(false);
            }
        }
        WriteLine("ok");

        Write("slicing of unknown most derived, unknown intermediate thrown as base (AMI)... ");
        Flush();
        {
            Callback cb = new Callback();
            testPrx.begin_unknownMostDerived2AsBase().whenCompleted(
                () =>
            {
                test(false);
            },
                (Ice.Exception ex) =>
            {
                try
                {
                    throw ex;
                }
                catch (Base b)
                {
                    test(b.b.Equals("UnknownMostDerived2.b"));
                    test(b.GetType().Name.Equals("Base"));
                }
                catch (Exception)
                {
                    test(false);
                }
                cb.called();
            });
            cb.check();

            try
            {
                testPrx.unknownMostDerived2AsBaseAsync().Wait();
                test(false);
            }
            catch (AggregateException ae)
            {
                try
                {
                    throw ae.InnerException;
                }
                catch (Base b)
                {
                    test(b.b.Equals("UnknownMostDerived2.b"));
                    test(b.GetType().Name.Equals("Base"));
                }
                catch (Exception)
                {
                    test(false);
                }
            }
        }
        WriteLine("ok");

        Write("unknown most derived in compact format... ");
        Flush();
        {
            try
            {
                testPrx.unknownMostDerived2AsBaseCompact();
                test(false);
            }
            catch (Base)
            {
                //
                // For the 1.0 encoding, the unknown exception is sliced to Base.
                //
                test(testPrx.ice_getEncodingVersion().Equals(Ice.Util.Encoding_1_0));
            }
            catch (Ice.UnknownUserException)
            {
                //
                // A MarshalException is raised for the compact format because the
                // most-derived type is unknown and the exception cannot be sliced.
                //
                test(!testPrx.ice_getEncodingVersion().Equals(Ice.Util.Encoding_1_0));
            }
            catch (Ice.OperationNotExistException)
            {
            }
            catch (Exception)
            {
                test(false);
            }
        }
        WriteLine("ok");

        string defaultHost = communicator.getProperties().getProperty("Ice.Default.Host");

        if (defaultHost.Equals("127.0.0.1") || defaultHost.Equals("::1"))
        {
            Write("preserved exceptions... ");
            Flush();
            {
                Ice.ObjectAdapter adapter = communicator.createObjectAdapterWithEndpoints("Relay", "default");
                RelayPrx          relay   = RelayPrxHelper.uncheckedCast(adapter.addWithUUID(new RelayI()));
                adapter.activate();

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

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

                try
                {
                    testPrx.relayUnknownPreservedAsBase(relay);
                    test(false);
                }
                catch (Preserved2 ex)
                {
                    test(ex.b.Equals("base"));
                    test(ex.kp.Equals("preserved"));
                    test(ex.kpd.Equals("derived"));
                    test(ex.p1.ice_id().Equals(PreservedClass.ice_staticId()));
                    PreservedClass pc = ex.p1 as PreservedClass;
                    test(pc.bc.Equals("bc"));
                    test(pc.pc.Equals("pc"));
                    test(ex.p2 == ex.p1);
                }
                catch (KnownPreservedDerived ex)
                {
                    //
                    // For the 1.0 encoding, the unknown exception is sliced to KnownPreserved.
                    //
                    test(testPrx.ice_getEncodingVersion().Equals(Ice.Util.Encoding_1_0));
                    test(ex.b.Equals("base"));
                    test(ex.kp.Equals("preserved"));
                    test(ex.kpd.Equals("derived"));
                }
                catch (Ice.OperationNotExistException)
                {
                }
                catch (Exception)
                {
                    test(false);
                }

                try
                {
                    testPrx.relayUnknownPreservedAsKnownPreserved(relay);
                    test(false);
                }
                catch (Preserved2 ex)
                {
                    test(ex.b.Equals("base"));
                    test(ex.kp.Equals("preserved"));
                    test(ex.kpd.Equals("derived"));
                    test(ex.p1.ice_id().Equals(PreservedClass.ice_staticId()));
                    PreservedClass pc = ex.p1 as PreservedClass;
                    test(pc.bc.Equals("bc"));
                    test(pc.pc.Equals("pc"));
                    test(ex.p2 == ex.p1);
                }
                catch (KnownPreservedDerived ex)
                {
                    //
                    // For the 1.0 encoding, the unknown exception is sliced to KnownPreserved.
                    //
                    test(testPrx.ice_getEncodingVersion().Equals(Ice.Util.Encoding_1_0));
                    test(ex.b.Equals("base"));
                    test(ex.kp.Equals("preserved"));
                    test(ex.kpd.Equals("derived"));
                }
                catch (Ice.OperationNotExistException)
                {
                }
                catch (Exception)
                {
                    test(false);
                }

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

        return(testPrx);
    }
Пример #15
0
    public static TestIntfPrx allTests(Ice.Communicator communicator, bool collocated)
#endif
    {
        Write("testing stringToProxy... ");
        Flush();
        String @ref = "Test:default -p 12010 -t 2000";

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

        Write("testing checked cast... ");
        Flush();
        TestIntfPrx testPrx = TestIntfPrxHelper.checkedCast(@base);

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

        Write("base... ");
        Flush();
        {
            try
            {
                testPrx.baseAsBase();
                test(false);
            }
            catch (Base b)
            {
                test(b.b.Equals("Base.b"));
                test(b.GetType().FullName.Equals("Test.Base"));
            }
            catch (Exception)
            {
                test(false);
            }
        }
        WriteLine("ok");

        Write("base (AMI)... ");
        Flush();
        {
            Callback cb = new Callback();
            testPrx.begin_baseAsBase().whenCompleted(
                () =>
            {
                test(false);
            },
                (Ice.Exception ex) =>
            {
                try
                {
                    throw ex;
                }
                catch (Base b)
                {
                    test(b.b.Equals("Base.b"));
                    test(b.GetType().Name.Equals("Base"));
                }
                catch (Exception)
                {
                    test(false);
                }
                cb.called();
            });
            cb.check();
        }
        WriteLine("ok");

        Write("slicing of unknown derived... ");
        Flush();
        {
            try
            {
                testPrx.unknownDerivedAsBase();
                test(false);
            }
            catch (Base b)
            {
                test(b.b.Equals("UnknownDerived.b"));
                test(b.GetType().FullName.Equals("Test.Base"));
            }
            catch (Exception)
            {
                test(false);
            }
        }
        WriteLine("ok");

        Write("slicing of unknown derived (AMI)... ");
        Flush();
        {
            Callback cb = new Callback();
            testPrx.begin_unknownDerivedAsBase().whenCompleted(
                () =>
            {
                test(false);
            },
                (Ice.Exception ex) =>
            {
                try
                {
                    throw ex;
                }
                catch (Base b)
                {
                    test(b.b.Equals("UnknownDerived.b"));
                    test(b.GetType().Name.Equals("Base"));
                }
                catch (Exception)
                {
                    test(false);
                }
                cb.called();
            });
            cb.check();
        }
        WriteLine("ok");

        Write("non-slicing of known derived as base... ");
        Flush();
        {
            try
            {
                testPrx.knownDerivedAsBase();
                test(false);
            }
            catch (KnownDerived k)
            {
                test(k.b.Equals("KnownDerived.b"));
                test(k.kd.Equals("KnownDerived.kd"));
                test(k.GetType().FullName.Equals("Test.KnownDerived"));
            }
            catch (Exception)
            {
                test(false);
            }
        }
        WriteLine("ok");

        Write("non-slicing of known derived as base (AMI)... ");
        Flush();
        {
            Callback cb = new Callback();
            testPrx.begin_knownDerivedAsBase().whenCompleted(
                () =>
            {
                test(false);
            },
                (Ice.Exception ex) =>
            {
                try
                {
                    throw ex;
                }
                catch (KnownDerived k)
                {
                    test(k.b.Equals("KnownDerived.b"));
                    test(k.kd.Equals("KnownDerived.kd"));
                    test(k.GetType().Name.Equals("KnownDerived"));
                }
                catch (Exception)
                {
                    test(false);
                }
                cb.called();
            });
            cb.check();
        }
        WriteLine("ok");

        Write("non-slicing of known derived as derived... ");
        Flush();
        {
            try
            {
                testPrx.knownDerivedAsKnownDerived();
                test(false);
            }
            catch (KnownDerived k)
            {
                test(k.b.Equals("KnownDerived.b"));
                test(k.kd.Equals("KnownDerived.kd"));
                test(k.GetType().FullName.Equals("Test.KnownDerived"));
            }
            catch (Exception)
            {
                test(false);
            }
        }
        WriteLine("ok");

        Write("non-slicing of known derived as derived (AMI)... ");
        Flush();
        {
            Callback cb = new Callback();
            testPrx.begin_knownDerivedAsKnownDerived().whenCompleted(
                () =>
            {
                test(false);
            },
                (Ice.Exception ex) =>
            {
                try
                {
                    throw ex;
                }
                catch (KnownDerived k)
                {
                    test(k.b.Equals("KnownDerived.b"));
                    test(k.kd.Equals("KnownDerived.kd"));
                    test(k.GetType().Name.Equals("KnownDerived"));
                }
                catch (Exception)
                {
                    test(false);
                }
                cb.called();
            });
            cb.check();
        }
        WriteLine("ok");

        Write("slicing of unknown intermediate as base... ");
        Flush();
        {
            try
            {
                testPrx.unknownIntermediateAsBase();
                test(false);
            }
            catch (Base b)
            {
                test(b.b.Equals("UnknownIntermediate.b"));
                test(b.GetType().FullName.Equals("Test.Base"));
            }
            catch (Exception)
            {
                test(false);
            }
        }
        WriteLine("ok");

        Write("slicing of unknown intermediate as base (AMI)... ");
        Flush();
        {
            Callback cb = new Callback();
            testPrx.begin_unknownIntermediateAsBase().whenCompleted(
                () =>
            {
                test(false);
            },
                (Ice.Exception ex) =>
            {
                try
                {
                    throw ex;
                }
                catch (Base b)
                {
                    test(b.b.Equals("UnknownIntermediate.b"));
                    test(b.GetType().Name.Equals("Base"));
                }
                catch (Exception)
                {
                    test(false);
                }
                cb.called();
            });
            cb.check();
        }
        WriteLine("ok");

        Write("slicing of known intermediate as base... ");
        Flush();
        {
            try
            {
                testPrx.knownIntermediateAsBase();
                test(false);
            }
            catch (KnownIntermediate ki)
            {
                test(ki.b.Equals("KnownIntermediate.b"));
                test(ki.ki.Equals("KnownIntermediate.ki"));
                test(ki.GetType().FullName.Equals("Test.KnownIntermediate"));
            }
            catch (Exception)
            {
                test(false);
            }
        }
        WriteLine("ok");

        Write("slicing of known intermediate as base (AMI)... ");
        Flush();
        {
            Callback cb = new Callback();
            testPrx.begin_knownIntermediateAsBase().whenCompleted(
                () =>
            {
                test(false);
            },
                (Ice.Exception ex) =>
            {
                try
                {
                    throw ex;
                }
                catch (KnownIntermediate ki)
                {
                    test(ki.b.Equals("KnownIntermediate.b"));
                    test(ki.ki.Equals("KnownIntermediate.ki"));
                    test(ki.GetType().Name.Equals("KnownIntermediate"));
                }
                catch (Exception)
                {
                    test(false);
                }
                cb.called();
            });
            cb.check();
        }
        WriteLine("ok");

        Write("slicing of known most derived as base... ");
        Flush();
        {
            try
            {
                testPrx.knownMostDerivedAsBase();
                test(false);
            }
            catch (KnownMostDerived kmd)
            {
                test(kmd.b.Equals("KnownMostDerived.b"));
                test(kmd.ki.Equals("KnownMostDerived.ki"));
                test(kmd.kmd.Equals("KnownMostDerived.kmd"));
                test(kmd.GetType().FullName.Equals("Test.KnownMostDerived"));
            }
            catch (Exception)
            {
                test(false);
            }
        }
        WriteLine("ok");

        Write("slicing of known most derived as base (AMI)... ");
        Flush();
        {
            Callback cb = new Callback();
            testPrx.begin_knownMostDerivedAsBase().whenCompleted(
                () =>
            {
                test(false);
            },
                (Ice.Exception ex) =>
            {
                try
                {
                    throw ex;
                }
                catch (KnownMostDerived kmd)
                {
                    test(kmd.b.Equals("KnownMostDerived.b"));
                    test(kmd.ki.Equals("KnownMostDerived.ki"));
                    test(kmd.kmd.Equals("KnownMostDerived.kmd"));
                    test(kmd.GetType().Name.Equals("KnownMostDerived"));
                }
                catch (Exception)
                {
                    test(false);
                }
                cb.called();
            });
            cb.check();
        }
        WriteLine("ok");

        Write("non-slicing of known intermediate as intermediate... ");
        Flush();
        {
            try
            {
                testPrx.knownIntermediateAsKnownIntermediate();
                test(false);
            }
            catch (KnownIntermediate ki)
            {
                test(ki.b.Equals("KnownIntermediate.b"));
                test(ki.ki.Equals("KnownIntermediate.ki"));
                test(ki.GetType().FullName.Equals("Test.KnownIntermediate"));
            }
            catch (Exception)
            {
                test(false);
            }
        }
        WriteLine("ok");

        Write("non-slicing of known intermediate as intermediate (AMI)... ");
        Flush();
        {
            Callback cb = new Callback();
            testPrx.begin_knownIntermediateAsKnownIntermediate().whenCompleted(
                () =>
            {
                test(false);
            },
                (Ice.Exception ex) =>
            {
                try
                {
                    throw ex;
                }
                catch (KnownIntermediate ki)
                {
                    test(ki.b.Equals("KnownIntermediate.b"));
                    test(ki.ki.Equals("KnownIntermediate.ki"));
                    test(ki.GetType().Name.Equals("KnownIntermediate"));
                }
                catch (Exception)
                {
                    test(false);
                }
                cb.called();
            });
            cb.check();
        }
        WriteLine("ok");

        Write("non-slicing of known most derived as intermediate... ");
        Flush();
        {
            try
            {
                testPrx.knownMostDerivedAsKnownIntermediate();
                test(false);
            }
            catch (KnownMostDerived kmd)
            {
                test(kmd.b.Equals("KnownMostDerived.b"));
                test(kmd.ki.Equals("KnownMostDerived.ki"));
                test(kmd.kmd.Equals("KnownMostDerived.kmd"));
                test(kmd.GetType().FullName.Equals("Test.KnownMostDerived"));
            }
            catch (Exception)
            {
                test(false);
            }
        }
        WriteLine("ok");

        Write("non-slicing of known most derived as intermediate (AMI)... ");
        Flush();
        {
            Callback cb = new Callback();
            testPrx.begin_knownMostDerivedAsKnownIntermediate().whenCompleted(
                () =>
            {
                test(false);
            },
                (Ice.Exception ex) =>
            {
                try
                {
                    throw ex;
                }
                catch (KnownMostDerived kmd)
                {
                    test(kmd.b.Equals("KnownMostDerived.b"));
                    test(kmd.ki.Equals("KnownMostDerived.ki"));
                    test(kmd.kmd.Equals("KnownMostDerived.kmd"));
                    test(kmd.GetType().Name.Equals("KnownMostDerived"));
                }
                catch (Exception)
                {
                    test(false);
                }
                cb.called();
            });
            cb.check();
        }
        WriteLine("ok");

        Write("non-slicing of known most derived as most derived... ");
        Flush();
        {
            try
            {
                testPrx.knownMostDerivedAsKnownMostDerived();
                test(false);
            }
            catch (KnownMostDerived kmd)
            {
                test(kmd.b.Equals("KnownMostDerived.b"));
                test(kmd.ki.Equals("KnownMostDerived.ki"));
                test(kmd.kmd.Equals("KnownMostDerived.kmd"));
                test(kmd.GetType().FullName.Equals("Test.KnownMostDerived"));
            }
            catch (Exception)
            {
                test(false);
            }
        }
        WriteLine("ok");

        Write("non-slicing of known most derived as most derived (AMI)... ");
        Flush();
        {
            Callback cb = new Callback();
            testPrx.begin_knownMostDerivedAsKnownMostDerived().whenCompleted(
                () =>
            {
                test(false);
            },
                (Ice.Exception ex) =>
            {
                try
                {
                    throw ex;
                }
                catch (KnownMostDerived kmd)
                {
                    test(kmd.b.Equals("KnownMostDerived.b"));
                    test(kmd.ki.Equals("KnownMostDerived.ki"));
                    test(kmd.kmd.Equals("KnownMostDerived.kmd"));
                    test(kmd.GetType().Name.Equals("KnownMostDerived"));
                }
                catch (Exception)
                {
                    test(false);
                }
                cb.called();
            });
            cb.check();
        }
        WriteLine("ok");

        Write("slicing of unknown most derived, known intermediate as base... ");
        Flush();
        {
            try
            {
                testPrx.unknownMostDerived1AsBase();
                test(false);
            }
            catch (KnownIntermediate ki)
            {
                test(ki.b.Equals("UnknownMostDerived1.b"));
                test(ki.ki.Equals("UnknownMostDerived1.ki"));
                test(ki.GetType().FullName.Equals("Test.KnownIntermediate"));
            }
            catch (Exception)
            {
                test(false);
            }
        }
        WriteLine("ok");

        Write("slicing of unknown most derived, known intermediate as base (AMI)... ");
        Flush();
        {
            Callback cb = new Callback();
            testPrx.begin_unknownMostDerived1AsBase().whenCompleted(
                () =>
            {
                test(false);
            },
                (Ice.Exception ex) =>
            {
                try
                {
                    throw ex;
                }
                catch (KnownIntermediate ki)
                {
                    test(ki.b.Equals("UnknownMostDerived1.b"));
                    test(ki.ki.Equals("UnknownMostDerived1.ki"));
                    test(ki.GetType().Name.Equals("KnownIntermediate"));
                }
                catch (Exception)
                {
                    test(false);
                }
                cb.called();
            });
            cb.check();
        }
        WriteLine("ok");

        Write("slicing of unknown most derived, known intermediate as intermediate... ");
        Flush();
        {
            try
            {
                testPrx.unknownMostDerived1AsKnownIntermediate();
                test(false);
            }
            catch (KnownIntermediate ki)
            {
                test(ki.b.Equals("UnknownMostDerived1.b"));
                test(ki.ki.Equals("UnknownMostDerived1.ki"));
                test(ki.GetType().FullName.Equals("Test.KnownIntermediate"));
            }
            catch (Exception)
            {
                test(false);
            }
        }
        WriteLine("ok");

        Write("slicing of unknown most derived, known intermediate as intermediate (AMI)... ");
        Flush();
        {
            Callback cb = new Callback();
            testPrx.begin_unknownMostDerived1AsKnownIntermediate().whenCompleted(
                () =>
            {
                test(false);
            },
                (Ice.Exception ex) =>
            {
                try
                {
                    throw ex;
                }
                catch (KnownIntermediate ki)
                {
                    test(ki.b.Equals("UnknownMostDerived1.b"));
                    test(ki.ki.Equals("UnknownMostDerived1.ki"));
                    test(ki.GetType().Name.Equals("KnownIntermediate"));
                }
                catch (Exception)
                {
                    test(false);
                }
                cb.called();
            });
            cb.check();
        }
        WriteLine("ok");

        Write("slicing of unknown most derived, unknown intermediate thrown as base... ");
        Flush();
        {
            try
            {
                testPrx.unknownMostDerived2AsBase();
                test(false);
            }
            catch (Base b)
            {
                test(b.b.Equals("UnknownMostDerived2.b"));
                test(b.GetType().FullName.Equals("Test.Base"));
            }
            catch (Exception)
            {
                test(false);
            }
        }
        WriteLine("ok");

        Write("slicing of unknown most derived, unknown intermediate thrown as base (AMI)... ");
        Flush();
        {
            Callback cb = new Callback();
            testPrx.begin_unknownMostDerived2AsBase().whenCompleted(
                () =>
            {
                test(false);
            },
                (Ice.Exception ex) =>
            {
                try
                {
                    throw ex;
                }
                catch (Base b)
                {
                    test(b.b.Equals("UnknownMostDerived2.b"));
                    test(b.GetType().Name.Equals("Base"));
                }
                catch (Exception)
                {
                    test(false);
                }
                cb.called();
            });
            cb.check();
        }
        WriteLine("ok");

        Write("unknown most derived in compact format... ");
        Flush();
        {
            try
            {
                testPrx.unknownMostDerived2AsBaseCompact();
                test(false);
            }
            catch (Base)
            {
                //
                // For the 1.0 encoding, the unknown exception is sliced to Base.
                //
                test(testPrx.ice_getEncodingVersion().Equals(Ice.Util.Encoding_1_0));
            }
            catch (Ice.UnknownUserException)
            {
                //
                // A MarshalException is raised for the compact format because the
                // most-derived type is unknown and the exception cannot be sliced.
                //
                test(!testPrx.ice_getEncodingVersion().Equals(Ice.Util.Encoding_1_0));
            }
            catch (Ice.OperationNotExistException)
            {
            }
            catch (Exception)
            {
                test(false);
            }
        }
        WriteLine("ok");

        //
        // No server side in Silverlight
        //
#if !SILVERLIGHT
        Write("preserved exceptions... ");
        Flush();
        {
            Ice.ObjectAdapter adapter = communicator.createObjectAdapterWithEndpoints("Relay", "default");
            RelayPrx          relay   = RelayPrxHelper.uncheckedCast(adapter.addWithUUID(new RelayI()));
            adapter.activate();

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

            try
            {
                testPrx.relayKnownPreservedAsKnownPreserved(relay);
                test(false);
            }
            catch (KnownPreservedDerived ex)
            {
                test(ex.b.Equals("base"));
                test(ex.kp.Equals("preserved"));
                test(ex.kpd.Equals("derived"));
            }

            /*
             * catch(Exception)
             * {
             *  test(false);
             * }
             */
            catch (Ice.OperationNotExistException)
            {
            }
            catch (Exception)
            {
                test(false);
            }

            try
            {
                testPrx.relayUnknownPreservedAsBase(relay);
                test(false);
            }
            catch (Preserved2 ex)
            {
                test(ex.b.Equals("base"));
                test(ex.kp.Equals("preserved"));
                test(ex.kpd.Equals("derived"));
                test(ex.p1.ice_id().Equals(PreservedClass.ice_staticId()));
                PreservedClass pc = ex.p1 as PreservedClass;
                test(pc.bc.Equals("bc"));
                test(pc.pc.Equals("pc"));
                test(ex.p2 == ex.p1);
            }
            catch (KnownPreservedDerived ex)
            {
                //
                // For the 1.0 encoding, the unknown exception is sliced to KnownPreserved.
                //
                test(testPrx.ice_getEncodingVersion().Equals(Ice.Util.Encoding_1_0));
                test(ex.b.Equals("base"));
                test(ex.kp.Equals("preserved"));
                test(ex.kpd.Equals("derived"));
            }
            catch (Ice.OperationNotExistException)
            {
            }
            catch (Exception)
            {
                test(false);
            }

            try
            {
                testPrx.relayUnknownPreservedAsKnownPreserved(relay);
                test(false);
            }
            catch (Preserved2 ex)
            {
                test(ex.b.Equals("base"));
                test(ex.kp.Equals("preserved"));
                test(ex.kpd.Equals("derived"));
                test(ex.p1.ice_id().Equals(PreservedClass.ice_staticId()));
                PreservedClass pc = ex.p1 as PreservedClass;
                test(pc.bc.Equals("bc"));
                test(pc.pc.Equals("pc"));
                test(ex.p2 == ex.p1);
            }
            catch (KnownPreservedDerived ex)
            {
                //
                // For the 1.0 encoding, the unknown exception is sliced to KnownPreserved.
                //
                test(testPrx.ice_getEncodingVersion().Equals(Ice.Util.Encoding_1_0));
                test(ex.b.Equals("base"));
                test(ex.kp.Equals("preserved"));
                test(ex.kpd.Equals("derived"));
            }
            catch (Ice.OperationNotExistException)
            {
            }
            catch (Exception)
            {
                test(false);
            }

            adapter.destroy();
        }
        WriteLine("ok");
#endif

#if SILVERLIGHT
        testPrx.shutdown();
#else
        return(testPrx);
#endif
    }
Пример #16
0
    private static int run(Ice.Communicator communicator)
    {
        //
        // Create an object adapter.
        //
        var adapter =
            communicator.createObjectAdapterWithEndpoints("SimpleFilesystem", "default -h localhost -p 10000");

        //
        // Create the root directory (with name "/" and no parent)
        //
        var root = new DirectoryI(communicator, "/", null);

        root.activate(adapter);

        //
        // Create a file called "README" in the root directory
        //
        var file = new FileI(communicator, "README", root);
        var text = new string[] { "This file system contains a collection of poetry." };

        try
        {
            file.write(text);
        }
        catch (GenericError e)
        {
            Console.Error.WriteLine(e.reason);
        }
        file.activate(adapter);

        //
        // Create a directory called "Coleridge" in the root directory
        //
        var coleridge = new DirectoryI(communicator, "Coleridge", root);

        coleridge.activate(adapter);

        //
        // Create a file called "Kubla_Khan" in the Coleridge directory
        //
        file = new FileI(communicator, "Kubla_Khan", coleridge);
        text = new string[] { "In Xanadu did Kubla Khan",
                              "A stately pleasure-dome decree:",
                              "Where Alph, the sacred river, ran",
                              "Through caverns measureless to man",
                              "Down to a sunless sea." };
        try
        {
            file.write(text);
        }
        catch (GenericError e)
        {
            Console.Error.WriteLine(e.reason);
        }
        file.activate(adapter);

        //
        // All objects are created, allow client requests now
        //
        adapter.activate();

        //
        // Wait until we are done
        //
        communicator.waitForShutdown();

        return(0);
    }