예제 #1
0
            allTests(global::Test.TestHelper helper)
            {
                var           output       = helper.getWriter();
                Communicator  communicator = helper.communicator();
                ObjectAdapter oa           = communicator.createObjectAdapterWithEndpoints("MyOA", "tcp -h localhost");

                oa.Activate();

                var  servantI = new MyObjectI();
                var  servantT = default(MyObjectTraits);
                Disp servantD = (incoming, current) => servantT.Dispatch(servantI, incoming, current);

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

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

                Disp r = oa.FindDefaultServant("foo");

                test(r == servantD);

                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" };

                IMyObjectPrx prx = null;

                for (int idx = 0; idx < 5; ++idx)
                {
                    identity.name = names[idx];
                    prx           = IMyObjectPrx.UncheckedCast(oa.CreateProxy(identity));
                    prx.IcePing();
                    test(prx.getName() == names[idx]);
                }

                identity.name = "ObjectNotExist";
                prx           = IMyObjectPrx.UncheckedCast(oa.CreateProxy(identity));
                try
                {
                    prx.IcePing();
                    test(false);
                }
                catch (ObjectNotExistException)
                {
                    // Expected
                }

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

                identity.name = "FacetNotExist";
                prx           = IMyObjectPrx.UncheckedCast(oa.CreateProxy(identity));
                try
                {
                    prx.IcePing();
                    test(false);
                }
                catch (FacetNotExistException)
                {
                    // Expected
                }

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

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

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

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

                oa.RemoveDefaultServant("foo");
                identity.category = "foo";
                prx = Test.IMyObjectPrx.UncheckedCast(oa.CreateProxy(identity));
                try
                {
                    prx.IcePing();
                }
                catch (Ice.ObjectNotExistException)
                {
                    // Expected
                }

                output.WriteLine("ok");

                output.Write("testing default category... ");
                output.Flush();

                oa.AddDefaultServant(servantD, "");

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

                r = oa.FindDefaultServant("");
                test(r == servantD);

                for (int idx = 0; idx < 5; ++idx)
                {
                    identity.name = names[idx];
                    prx           = Test.IMyObjectPrx.UncheckedCast(oa.CreateProxy(identity));
                    prx.IcePing();
                    test(prx.getName() == names[idx]);
                }

                output.WriteLine("ok");
            }
예제 #2
0
        allTests(global::Test.TestHelper helper)
        {
            var           output       = helper.getWriter();
            Communicator  communicator = helper.communicator();
            ObjectAdapter oa           = communicator.CreateObjectAdapterWithEndpoints("MyOA", "tcp -h localhost");

            oa.Activate();

            var  servantI = new MyObject();
            Disp servantD = (servantI as IObject).Dispatch;

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

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

            Disp r = oa.FindDefaultServant("foo");

            test(r == servantD);

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

            Identity identity = new Identity("", "foo");

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

            IMyObjectPrx prx = null;

            for (int idx = 0; idx < 5; ++idx)
            {
                identity = new Identity(names[idx], identity.Category);
                prx      = oa.CreateProxy(identity, IMyObjectPrx.Factory);
                prx.IcePing();
                test(prx.getName() == names[idx]);
            }

            identity = new Identity("ObjectNotExist", identity.Category);
            prx      = oa.CreateProxy(identity, IMyObjectPrx.Factory);
            try
            {
                prx.IcePing();
                test(false);
            }
            catch (ObjectNotExistException)
            {
                // Expected
            }

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

            identity = new Identity("FacetNotExist", identity.Category);
            prx      = oa.CreateProxy(identity, IMyObjectPrx.Factory);
            try
            {
                prx.IcePing();
                test(false);
            }
            catch (FacetNotExistException)
            {
                // Expected
            }

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

            identity = new Identity(identity.Name, "bar");
            for (int idx = 0; idx < 5; idx++)
            {
                identity = new Identity(names[idx], identity.Category);
                prx      = oa.CreateProxy(identity, Test.IMyObjectPrx.Factory);

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

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

            oa.RemoveDefaultServant("foo");
            identity = new Identity(identity.Name, "foo");
            prx      = oa.CreateProxy(identity, IMyObjectPrx.Factory);
            try
            {
                prx.IcePing();
            }
            catch (ObjectNotExistException)
            {
                // Expected
            }

            output.WriteLine("ok");

            output.Write("testing default category... ");
            output.Flush();

            oa.AddDefaultServant(servantD, "");

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

            r = oa.FindDefaultServant("");
            test(r == servantD);

            for (int idx = 0; idx < 5; ++idx)
            {
                identity = new Identity(names[idx], identity.Category);
                prx      = oa.CreateProxy(identity, IMyObjectPrx.Factory);
                prx.IcePing();
                test(prx.getName() == names[idx]);
            }

            output.WriteLine("ok");
        }