Exemple #1
0
        public static IGPrx 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 Empty();

            adapter.Add("d", obj);
            adapter.Add("d", "facetABCD", obj);
            try
            {
                adapter.Add("d", "facetABCD", obj);
                test(false);
            }
            catch (System.ArgumentException)
            {
            }
            adapter.Remove("d", "facetABCD");
            adapter.Remove("d", "facetABCD"); // multiple Remove are fine as of Ice 4.0
            output.WriteLine("ok");

            adapter.Deactivate();

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

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

            test(d.Facet.Length == 0);
            var df = prx.Clone("facetABCD", IDPrx.Factory);

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

            test(df2.Facet == "facetABCD");
            var df3 = df.Clone(facet: "", IDPrx.Factory);

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

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

            output.Write("testing non-facets A, B, C, and D... ");
            output.Flush();
            d = IDPrx.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 = IDPrx.CheckedCast(d.Clone(facet: "facetABCD", IObjectPrx.Factory));
            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 = IFPrx.CheckedCast(d.Clone(facet: "facetEF", IObjectPrx.Factory));

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

            output.Write("testing facet G... ");
            output.Flush();
            var gf = IGPrx.CheckedCast(ff.Clone(facet: "facetGH", IObjectPrx.Factory));

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

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

            test(hf.callG().Equals("G"));
            test(hf.callH().Equals("H"));
            output.WriteLine("ok");
            return(gf);
        }
Exemple #2
0
        public static async Task <IGPrx> RunAsync(TestHelper helper)
        {
            Communicator?communicator = helper.Communicator;

            TestHelper.Assert(communicator != null);
            TextWriter output = helper.Output;

            output.Write("testing Ice.Admin.Facets property... ");
            TestHelper.Assert(communicator.GetPropertyAsList("Ice.Admin.Facets") == null);
            communicator.SetProperty("Ice.Admin.Facets", "foobar");
            string[]? facetFilter = communicator.GetPropertyAsList("Ice.Admin.Facets");
            TestHelper.Assert(facetFilter != null && facetFilter.Length == 1 && facetFilter[0].Equals("foobar"));
            communicator.SetProperty("Ice.Admin.Facets", "foo\\'bar");
            facetFilter = communicator.GetPropertyAsList("Ice.Admin.Facets");
            TestHelper.Assert(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");
            TestHelper.Assert(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");
            TestHelper.Assert(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");
            // TestHelper.Assert(facetFilter.Length == 0);
            communicator.SetProperty("Ice.Admin.Facets", "");
            output.WriteLine("ok");

            output.Write("testing facet registration exceptions... ");
            communicator.SetProperty("FacetExceptionTestAdapter.Endpoints", helper.GetTestEndpoint(ephemeral: true));
            ObjectAdapter adapter = communicator.CreateObjectAdapter("FacetExceptionTestAdapter");

            var obj = new Empty();

            adapter.Add("d", obj);
            adapter.Add("d#facetABCD", obj);
            try
            {
                adapter.Add("d#facetABCD", obj);
                TestHelper.Assert(false);
            }
            catch (ArgumentException)
            {
            }
            adapter.Remove("d#facetABCD");
            adapter.Remove("d#facetABCD"); // multiple Remove are fine as of Ice 4.0
            output.WriteLine("ok");

            await adapter.DisposeAsync();

            var   prx = IObjectPrx.Parse(helper.GetTestProxy("d", 0), communicator);
            IDPrx?d;
            IDPrx?df2;
            IDPrx?df3;

            output.Write("testing unchecked cast... ");
            output.Flush();
            d = prx.Clone(IDPrx.Factory);
            TestHelper.Assert(d != null);
            TestHelper.Assert(d.Facet.Length == 0);
            IDPrx df = prx.Clone(IDPrx.Factory, facet: "facetABCD");

            TestHelper.Assert(df.Facet == "facetABCD");
            df2 = df.Clone(IDPrx.Factory);
            TestHelper.Assert(df2 != null);
            TestHelper.Assert(df2.Facet == "facetABCD");
            df3 = df.Clone(IDPrx.Factory, facet: "");
            TestHelper.Assert(df3 != null);
            TestHelper.Assert(df3.Facet.Length == 0);
            output.WriteLine("ok");

            output.Write("testing checked cast... ");
            output.Flush();
            d = prx.CheckedCast(IDPrx.Factory);
            TestHelper.Assert(d != null);
            TestHelper.Assert(d.Facet.Length == 0);
            df = prx.Clone(IDPrx.Factory, facet: "facetABCD");
            TestHelper.Assert(df.Facet == "facetABCD");
            df2 = df.Clone(IDPrx.Factory);
            TestHelper.Assert(df2 != null);
            TestHelper.Assert(df2.Facet == "facetABCD");
            df3 = df.Clone(IDPrx.Factory, facet: "");
            TestHelper.Assert(df3.Facet.Length == 0);
            output.WriteLine("ok");

            output.Write("testing non-facets A, B, C, and D... ");
            output.Flush();
            d = prx.Clone(IDPrx.Factory);
            TestHelper.Assert(d != null);
            TestHelper.Assert(d.Equals(prx));
            TestHelper.Assert(d.CallA().Equals("A"));
            TestHelper.Assert(d.CallB().Equals("B"));
            TestHelper.Assert(d.CallC().Equals("C"));
            TestHelper.Assert(d.CallD().Equals("D"));
            output.WriteLine("ok");

            output.Write("testing facets A, B, C, and D... ");
            output.Flush();
            df = d.Clone(IDPrx.Factory, facet: "facetABCD");
            TestHelper.Assert(df != null);
            TestHelper.Assert(df.CallA().Equals("A"));
            TestHelper.Assert(df.CallB().Equals("B"));
            TestHelper.Assert(df.CallC().Equals("C"));
            TestHelper.Assert(df.CallD().Equals("D"));
            output.WriteLine("ok");

            output.Write("testing facets E and F... ");
            output.Flush();
            IFPrx ff = d.Clone(IFPrx.Factory, facet: "facetEF");

            TestHelper.Assert(ff.CallE().Equals("E"));
            TestHelper.Assert(ff.CallF().Equals("F"));
            output.WriteLine("ok");

            output.Write("testing facet G... ");
            output.Flush();
            IGPrx gf = ff.Clone(IGPrx.Factory, facet: "facetGH");

            TestHelper.Assert(gf.CallG().Equals("G"));
            output.WriteLine("ok");

            output.Write("testing whether casting preserves the facet... ");
            output.Flush();
            var hf = gf.Clone(IHPrx.Factory);

            TestHelper.Assert(hf != null);
            TestHelper.Assert(hf.CallG().Equals("G"));
            TestHelper.Assert(hf.CallH().Equals("H"));
            output.WriteLine("ok");
            return(gf);
        }