Пример #1
0
    public static GPrx allTests(TestCommon.Application app)
    {
        Ice.Communicator communicator = app.communicator();

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

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

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

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

        adapter.deactivate();

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        test(hf != null);
        test(hf.callG().Equals("G"));
        test(hf.callH().Equals("H"));
        WriteLine("ok");
        return(gf);
    }
Пример #2
0
            public static Test.GPrx allTests(global::Test.TestHelper helper)
            {
                Communicator communicator = helper.communicator();
                var          output       = helper.getWriter();

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

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

                var obj = new EmptyI();

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

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

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

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

                adapter.Deactivate();

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                test(hf.callG().Equals("G"));
                test(hf.callH().Equals("H"));
                output.WriteLine("ok");
                return(gf);
            }