Пример #1
0
        public static void Run(TestHelper helper)
        {
            Communicator?communicator = helper.Communicator();

            TestHelper.Assert(communicator != null);
            var com = IRemoteCommunicatorPrx.Parse(helper.GetTestProxy("communicator", 0), communicator);

            var rand = new Random(unchecked ((int)DateTime.Now.Ticks));

            System.IO.TextWriter output = helper.GetWriter();

            output.Write("testing binding with single endpoint... ");
            output.Flush();
            {
                IRemoteObjectAdapterPrx?adapter = com.CreateObjectAdapter("Adapter", "default");
                TestHelper.Assert(adapter != null);
                ITestIntfPrx?test1 = adapter.GetTestIntf();
                ITestIntfPrx?test2 = adapter.GetTestIntf();
                TestHelper.Assert(test1 != null && test2 != null);
                TestHelper.Assert(test1.GetConnection() == test2.GetConnection());

                test1.IcePing();
                test2.IcePing();

                com.DeactivateObjectAdapter(adapter);

                var test3 = ITestIntfPrx.UncheckedCast(test1);
                TestHelper.Assert(test3.GetConnection() == test1.GetConnection());
                TestHelper.Assert(test3.GetConnection() == test2.GetConnection());

                try
                {
                    test3.IcePing();
                    TestHelper.Assert(false);
                }
                catch (ConnectFailedException)
                {
                }
            }
            output.WriteLine("ok");

            output.Write("testing binding with multiple endpoints... ");
            output.Flush();
            {
                var adapters = new List <IRemoteObjectAdapterPrx>
                {
                    com.CreateObjectAdapter("Adapter11", "default") !,
                    com.CreateObjectAdapter("Adapter12", "default") !,
                    com.CreateObjectAdapter("Adapter13", "default") !
                };

                // Ensure that when a connection is opened it's reused for new proxies and that all endpoints are
                // eventually tried.
                var names = new List <string>
                {
                    "Adapter11",
                    "Adapter12",
                    "Adapter13"
                };

                while (names.Count > 0)
                {
                    var adpts = new List <IRemoteObjectAdapterPrx>(adapters);

                    ITestIntfPrx test1 = CreateTestIntfPrx(adpts);
                    Shuffle(ref adpts);
                    ITestIntfPrx test2 = CreateTestIntfPrx(adpts);
                    Shuffle(ref adpts);
                    ITestIntfPrx test3 = CreateTestIntfPrx(adpts);
                    test1.IcePing();
                    TestHelper.Assert(test1.GetConnection() == test2.GetConnection());
                    TestHelper.Assert(test2.GetConnection() == test3.GetConnection());

                    names.Remove(test1.GetAdapterName());
                    test1.GetConnection() !.Close(ConnectionClose.GracefullyWithWait);
                }

                // Ensure that the proxy correctly caches the connection(we always send the request over the same
                // connection.)
                {
                    foreach (IRemoteObjectAdapterPrx adpt in adapters)
                    {
                        adpt.GetTestIntf() !.IcePing();
                    }

                    ITestIntfPrx t    = CreateTestIntfPrx(adapters);
                    string       name = t.GetAdapterName();

                    for (int i = 0; i < 10 && t.GetAdapterName().Equals(name); i++)
                    {
                        TestHelper.Assert(t.GetAdapterName() == name);
                    }

                    foreach (IRemoteObjectAdapterPrx adpt in adapters)
                    {
                        adpt.GetTestIntf() !.GetConnection() !.Close(ConnectionClose.GracefullyWithWait);
                    }
                }

                // Deactivate an adapter and ensure that we can still establish the connection to the remaining
                // adapters.
                com.DeactivateObjectAdapter(adapters[0]);
                names.Add("Adapter12");
                names.Add("Adapter13");
                while (names.Count > 0)
                {
                    var adpts = new List <IRemoteObjectAdapterPrx>(adapters);

                    ITestIntfPrx test1 = CreateTestIntfPrx(adpts);
                    Shuffle(ref adpts);
                    ITestIntfPrx test2 = CreateTestIntfPrx(adpts);
                    Shuffle(ref adpts);
                    ITestIntfPrx test3 = CreateTestIntfPrx(adpts);

                    TestHelper.Assert(test1.GetConnection() == test2.GetConnection());
                    TestHelper.Assert(test2.GetConnection() == test3.GetConnection());

                    names.Remove(test1.GetAdapterName());
                    test1.GetConnection() !.Close(ConnectionClose.GracefullyWithWait);
                }

                // Deactivate an adapter and ensure that we can still establish the connection to the remaining
                // adapter.
                com.DeactivateObjectAdapter(adapters[2]);
                ITestIntfPrx obj = CreateTestIntfPrx(adapters);
                TestHelper.Assert(obj.GetAdapterName().Equals("Adapter12"));

                Deactivate(com, adapters);
            }
            output.WriteLine("ok");

            output.Write("testing binding with multiple random endpoints... ");
            output.Flush();
            {
                var adapters = new IRemoteObjectAdapterPrx[5]
                {
                    com.CreateObjectAdapter("AdapterRandom11", "default") !,
                    com.CreateObjectAdapter("AdapterRandom12", "default") !,
                    com.CreateObjectAdapter("AdapterRandom13", "default") !,
                    com.CreateObjectAdapter("AdapterRandom14", "default") !,
                    com.CreateObjectAdapter("AdapterRandom15", "default") !
                };

                int count        = 20;
                int adapterCount = adapters.Length;
                while (--count > 0)
                {
                    ITestIntfPrx[] proxies;
                    if (count == 1)
                    {
                        com.DeactivateObjectAdapter(adapters[4]);
                        --adapterCount;
                    }
                    proxies = new ITestIntfPrx[10];

                    int i;
                    for (i = 0; i < proxies.Length; ++i)
                    {
                        var adpts = new IRemoteObjectAdapterPrx[rand.Next(adapters.Length)];
                        if (adpts.Length == 0)
                        {
                            adpts = new IRemoteObjectAdapterPrx[1];
                        }
                        for (int j = 0; j < adpts.Length; ++j)
                        {
                            adpts[j] = adapters[rand.Next(adapters.Length)];
                        }
                        proxies[i] = CreateTestIntfPrx(new List <IRemoteObjectAdapterPrx>(adpts));
                    }

                    for (i = 0; i < proxies.Length; i++)
                    {
                        proxies[i].GetAdapterNameAsync();
                    }
                    for (i = 0; i < proxies.Length; i++)
                    {
                        try
                        {
                            proxies[i].IcePing();
                        }
                        catch
                        {
                        }
                    }

                    var connections = new List <Connection>();
                    for (i = 0; i < proxies.Length; i++)
                    {
                        if (proxies[i].GetCachedConnection() is Connection connection)
                        {
                            if (!connections.Contains(connection))
                            {
                                connections.Add(connection);
                            }
                        }
                    }
                    TestHelper.Assert(connections.Count <= adapterCount);

                    foreach (IRemoteObjectAdapterPrx a in adapters)
                    {
                        try
                        {
                            a.GetTestIntf() !.GetConnection() !.Close(ConnectionClose.GracefullyWithWait);
                        }
                        catch
                        {
                            // Expected if adapter is down.
                        }
                    }
                }
            }
            output.WriteLine("ok");

            output.Write("testing binding with multiple endpoints and AMI... ");
            output.Flush();
            {
                var adapters = new List <IRemoteObjectAdapterPrx>
                {
                    com.CreateObjectAdapter("AdapterAMI11", "default") !,
                    com.CreateObjectAdapter("AdapterAMI12", "default") !,
                    com.CreateObjectAdapter("AdapterAMI13", "default") !
                };

                //
                // Ensure that when a connection is opened it's reused for new
                // proxies and that all endpoints are eventually tried.
                //
                var names = new List <string>
                {
                    "AdapterAMI11",
                    "AdapterAMI12",
                    "AdapterAMI13"
                };

                while (names.Count > 0)
                {
                    var adpts = new List <IRemoteObjectAdapterPrx>(adapters);

                    ITestIntfPrx test1 = CreateTestIntfPrx(adpts);
                    Shuffle(ref adpts);
                    ITestIntfPrx test2 = CreateTestIntfPrx(adpts);
                    Shuffle(ref adpts);
                    ITestIntfPrx test3 = CreateTestIntfPrx(adpts);
                    test1.IcePing();
                    TestHelper.Assert(test1.GetConnection() == test2.GetConnection());
                    TestHelper.Assert(test2.GetConnection() == test3.GetConnection());

                    names.Remove(GetAdapterNameWithAMI(test1));
                    test1.GetConnection() !.Close(ConnectionClose.GracefullyWithWait);
                }

                // Ensure that the proxy correctly caches the connection (we always send the request over the
                // same connection.)
                {
                    foreach (IRemoteObjectAdapterPrx?adpt in adapters)
                    {
                        adpt.GetTestIntf() !.IcePing();
                    }

                    ITestIntfPrx t    = CreateTestIntfPrx(adapters);
                    string       name = GetAdapterNameWithAMI(t);

                    for (int i = 0; i < 10; i++)
                    {
                        TestHelper.Assert(GetAdapterNameWithAMI(t) == name);
                    }

                    foreach (IRemoteObjectAdapterPrx?adpt in adapters)
                    {
                        adpt.GetTestIntf() !.GetConnection() !.Close(ConnectionClose.GracefullyWithWait);
                    }
                }

                //
                // Deactivate an adapter and ensure that we can still
                // establish the connection to the remaining adapters.
                //
                com.DeactivateObjectAdapter(adapters[0]);
                names.Add("AdapterAMI12");
                names.Add("AdapterAMI13");
                while (names.Count > 0)
                {
                    var adpts = new List <IRemoteObjectAdapterPrx>(adapters);

                    ITestIntfPrx test1 = CreateTestIntfPrx(adpts);
                    Shuffle(ref adpts);
                    ITestIntfPrx test2 = CreateTestIntfPrx(adpts);
                    Shuffle(ref adpts);
                    ITestIntfPrx test3 = CreateTestIntfPrx(adpts);

                    TestHelper.Assert(test1.GetConnection() == test2.GetConnection());
                    TestHelper.Assert(test2.GetConnection() == test3.GetConnection());

                    names.Remove(GetAdapterNameWithAMI(test1));
                    test1.GetConnection() !.Close(ConnectionClose.GracefullyWithWait);
                }

                // Deactivate an adapter and ensure that we can still establish the connection
                // to the remaining adapter.
                com.DeactivateObjectAdapter(adapters[2]);
                ITestIntfPrx obj = CreateTestIntfPrx(adapters);
                TestHelper.Assert(GetAdapterNameWithAMI(obj).Equals("AdapterAMI12"));

                Deactivate(com, adapters);
            }
            output.WriteLine("ok");

            output.Write("testing random endpoint selection... ");
            output.Flush();
            {
                var adapters = new List <IRemoteObjectAdapterPrx>
                {
                    com.CreateObjectAdapter("Adapter21", "default") !,
                    com.CreateObjectAdapter("Adapter22", "default") !,
                    com.CreateObjectAdapter("Adapter23", "default") !
                };

                ITestIntfPrx obj = CreateTestIntfPrx(adapters);
                TestHelper.Assert(obj.EndpointSelection == EndpointSelectionType.Random);

                var names = new List <string>
                {
                    "Adapter21",
                    "Adapter22",
                    "Adapter23"
                };

                while (names.Count > 0)
                {
                    names.Remove(obj.GetAdapterName());
                    obj.GetConnection() !.Close(ConnectionClose.GracefullyWithWait);
                }

                obj = obj.Clone(endpointSelection: EndpointSelectionType.Random);
                TestHelper.Assert(obj.EndpointSelection == EndpointSelectionType.Random);

                names.Add("Adapter21");
                names.Add("Adapter22");
                names.Add("Adapter23");
                while (names.Count > 0)
                {
                    names.Remove(obj.GetAdapterName());
                    obj.GetConnection() !.Close(ConnectionClose.GracefullyWithWait);
                }

                Deactivate(com, adapters);
            }
            output.WriteLine("ok");

            output.Write("testing ordered endpoint selection... ");
            output.Flush();
            {
                var adapters = new List <IRemoteObjectAdapterPrx>
                {
                    com.CreateObjectAdapter("Adapter31", "default") !,
                    com.CreateObjectAdapter("Adapter32", "default") !,
                    com.CreateObjectAdapter("Adapter33", "default") !
                };

                ITestIntfPrx obj = CreateTestIntfPrx(adapters);
                obj = obj.Clone(endpointSelection: EndpointSelectionType.Ordered);
                TestHelper.Assert(obj.EndpointSelection == EndpointSelectionType.Ordered);

                // Ensure that endpoints are tried in order by deactivating the adapters
                // one after the other.
                for (int i = 0; i < 3; i++)
                {
                    TestHelper.Assert(obj.GetAdapterName() == "Adapter31");
                }
                com.DeactivateObjectAdapter(adapters[0]);

                for (int i = 0; i < 3; i++)
                {
                    TestHelper.Assert(obj.GetAdapterName() == "Adapter32");
                }
                com.DeactivateObjectAdapter(adapters[1]);

                for (int i = 0; i < 3; i++)
                {
                    TestHelper.Assert(obj.GetAdapterName() == "Adapter33");
                }
                com.DeactivateObjectAdapter(adapters[2]);

                try
                {
                    obj.GetAdapterName();
                }
                catch (ConnectFailedException)
                {
                }

                IReadOnlyList <Endpoint> endpoints = obj.Endpoints;

                adapters.Clear();

                // TODO: ice1-only for now, because we send the client endpoints for use in OA configuration.
                if (communicator.DefaultProtocol == Protocol.Ice1)
                {
                    // Now, re-activate the adapters with the same endpoints in the opposite order.
                    adapters.Add(com.CreateObjectAdapterWithEndpoints("Adapter36", endpoints[2].ToString()));
                    for (int i = 0; i < 3; i++)
                    {
                        TestHelper.Assert(obj.GetAdapterName() == "Adapter36");
                    }
                    obj.GetConnection() !.Close(ConnectionClose.GracefullyWithWait);

                    adapters.Add(com.CreateObjectAdapterWithEndpoints("Adapter35", endpoints[1].ToString()));
                    for (int i = 0; i < 3; i++)
                    {
                        TestHelper.Assert(obj.GetAdapterName() == "Adapter35");
                    }
                    obj.GetConnection() !.Close(ConnectionClose.GracefullyWithWait);

                    adapters.Add(com.CreateObjectAdapterWithEndpoints("Adapter34", endpoints[0].ToString()));
                    for (int i = 0; i < 3; i++)
                    {
                        TestHelper.Assert(obj.GetAdapterName() == "Adapter34");
                    }
                    Deactivate(com, adapters);
                }
            }
            output.WriteLine("ok");

            output.Write("testing per request binding with single endpoint... ");
            output.Flush();
            {
                IRemoteObjectAdapterPrx?adapter = com.CreateObjectAdapter("Adapter41", "default");
                TestHelper.Assert(adapter != null);
                ITestIntfPrx test1 = adapter.GetTestIntf() !.Clone(cacheConnection: false);
                ITestIntfPrx test2 = adapter.GetTestIntf() !.Clone(cacheConnection: false);
                TestHelper.Assert(!test1.IsConnectionCached);
                TestHelper.Assert(!test2.IsConnectionCached);
                TestHelper.Assert(test1.GetConnection() != null && test2.GetConnection() != null);
                TestHelper.Assert(test1.GetConnection() == test2.GetConnection());

                test1.IcePing();

                com.DeactivateObjectAdapter(adapter);

                var test3 = ITestIntfPrx.UncheckedCast(test1);
                try
                {
                    TestHelper.Assert(test3.GetConnection() == test1.GetConnection());
                    TestHelper.Assert(false);
                }
                catch (ConnectFailedException)
                {
                }
            }
            output.WriteLine("ok");

            output.Write("testing per request binding with multiple endpoints... ");
            output.Flush();
            {
                var adapters = new List <IRemoteObjectAdapterPrx>
                {
                    com.CreateObjectAdapter("Adapter51", "default") !,
                    com.CreateObjectAdapter("Adapter52", "default") !,
                    com.CreateObjectAdapter("Adapter53", "default") !
                };

                ITestIntfPrx obj = CreateTestIntfPrx(adapters).Clone(cacheConnection: false);
                TestHelper.Assert(!obj.IsConnectionCached);

                var names = new List <string>
                {
                    "Adapter51",
                    "Adapter52",
                    "Adapter53"
                };
                while (names.Count > 0)
                {
                    names.Remove(obj.GetAdapterName());
                }

                com.DeactivateObjectAdapter(adapters[0]);

                names.Add("Adapter52");
                names.Add("Adapter53");
                while (names.Count > 0)
                {
                    names.Remove(obj.GetAdapterName());
                }

                com.DeactivateObjectAdapter(adapters[2]);

                TestHelper.Assert(obj.GetAdapterName().Equals("Adapter52"));

                Deactivate(com, adapters);
            }
            output.WriteLine("ok");

            output.Write("testing per request binding with multiple endpoints and AMI... ");
            output.Flush();
            {
                var adapters = new List <IRemoteObjectAdapterPrx>
                {
                    com.CreateObjectAdapter("AdapterAMI51", "default") !,
                    com.CreateObjectAdapter("AdapterAMI52", "default") !,
                    com.CreateObjectAdapter("AdapterAMI53", "default") !
                };

                ITestIntfPrx obj = CreateTestIntfPrx(adapters).Clone(cacheConnection: false);
                TestHelper.Assert(!obj.IsConnectionCached);

                var names = new List <string>
                {
                    "AdapterAMI51",
                    "AdapterAMI52",
                    "AdapterAMI53"
                };
                while (names.Count > 0)
                {
                    names.Remove(GetAdapterNameWithAMI(obj));
                }

                com.DeactivateObjectAdapter(adapters[0]);

                names.Add("AdapterAMI52");
                names.Add("AdapterAMI53");
                while (names.Count > 0)
                {
                    names.Remove(GetAdapterNameWithAMI(obj));
                }

                com.DeactivateObjectAdapter(adapters[2]);

                TestHelper.Assert(GetAdapterNameWithAMI(obj).Equals("AdapterAMI52"));

                Deactivate(com, adapters);
            }
            output.WriteLine("ok");

            output.Write("testing per request binding and ordered endpoint selection... ");
            output.Flush();
            {
                var adapters = new List <IRemoteObjectAdapterPrx>
                {
                    com.CreateObjectAdapter("Adapter61", "default") !,
                    com.CreateObjectAdapter("Adapter62", "default") !,
                    com.CreateObjectAdapter("Adapter63", "default") !
                };

                ITestIntfPrx obj = CreateTestIntfPrx(adapters);
                obj = obj.Clone(endpointSelection: EndpointSelectionType.Ordered);
                TestHelper.Assert(obj.EndpointSelection == EndpointSelectionType.Ordered);
                obj = obj.Clone(cacheConnection: false);
                TestHelper.Assert(!obj.IsConnectionCached);

                // Ensure that endpoints are tried in order by deactivating the adapters one after the other.
                for (int i = 0; i < 3; i++)
                {
                    TestHelper.Assert(obj.GetAdapterName() == "Adapter61");
                }
                com.DeactivateObjectAdapter(adapters[0]);

                for (int i = 0; i < 3; i++)
                {
                    TestHelper.Assert(obj.GetAdapterName() == "Adapter62");
                }
                com.DeactivateObjectAdapter(adapters[1]);

                for (int i = 0; i < 3; i++)
                {
                    TestHelper.Assert(obj.GetAdapterName() == "Adapter63");
                }
                com.DeactivateObjectAdapter(adapters[2]);

                try
                {
                    obj.GetAdapterName();
                }
                catch (ConnectFailedException)
                {
                }

                IReadOnlyList <Endpoint> endpoints = obj.Endpoints;

                adapters.Clear();

                // TODO: ice1-only for now, because we send the client endpoints for use in OA configuration.
                if (communicator.DefaultProtocol == Protocol.Ice1)
                {
                    // Now, re-activate the adapters with the same endpoints in the opposite order.
                    adapters.Add(com.CreateObjectAdapterWithEndpoints("Adapter66", endpoints[2].ToString()));
                    for (int i = 0; i < 3; i++)
                    {
                        TestHelper.Assert(obj.GetAdapterName() == "Adapter66");
                    }

                    adapters.Add(com.CreateObjectAdapterWithEndpoints("Adapter65", endpoints[1].ToString()));
                    for (int i = 0; i < 3; i++)
                    {
                        TestHelper.Assert(obj.GetAdapterName() == "Adapter65");
                    }

                    adapters.Add(com.CreateObjectAdapterWithEndpoints("Adapter64", endpoints[0].ToString()));
                    for (int i = 0; i < 3; i++)
                    {
                        TestHelper.Assert(obj.GetAdapterName() == "Adapter64");
                    }

                    Deactivate(com, adapters);
                }
            }
            output.WriteLine("ok");

            output.Write("testing per request binding and ordered endpoint selection and AMI... ");
            output.Flush();
            {
                var adapters = new List <IRemoteObjectAdapterPrx>
                {
                    com.CreateObjectAdapter("AdapterAMI61", "default") !,
                    com.CreateObjectAdapter("AdapterAMI62", "default") !,
                    com.CreateObjectAdapter("AdapterAMI63", "default") !
                };

                ITestIntfPrx?obj = CreateTestIntfPrx(adapters);
                obj = obj.Clone(endpointSelection: EndpointSelectionType.Ordered);
                TestHelper.Assert(obj.EndpointSelection == EndpointSelectionType.Ordered);
                obj = obj.Clone(cacheConnection: false);
                TestHelper.Assert(!obj.IsConnectionCached);

                // Ensure that endpoints are tried in order by deactivating the adapters one after the other.
                for (int i = 0; i < 3; i++)
                {
                    TestHelper.Assert(GetAdapterNameWithAMI(obj) == "AdapterAMI61");
                }
                com.DeactivateObjectAdapter(adapters[0]);

                for (int i = 0; i < 3; i++)
                {
                    TestHelper.Assert(GetAdapterNameWithAMI(obj) == "AdapterAMI62");
                }
                com.DeactivateObjectAdapter(adapters[1]);

                for (int i = 0; i < 3; i++)
                {
                    TestHelper.Assert(GetAdapterNameWithAMI(obj) == "AdapterAMI63");
                }
                com.DeactivateObjectAdapter(adapters[2]);

                try
                {
                    obj.GetAdapterName();
                }
                catch (ConnectFailedException)
                {
                }

                IReadOnlyList <Endpoint> endpoints = obj.Endpoints;

                adapters.Clear();

                // TODO: ice1-only for now, because we send the client endpoints for use in OA configuration.
                if (communicator.DefaultProtocol == Protocol.Ice1)
                {
                    // Now, re-activate the adapters with the same endpoints in the opposite order.
                    adapters.Add(com.CreateObjectAdapterWithEndpoints("AdapterAMI66", endpoints[2].ToString()));
                    for (int i = 0; i < 3; i++)
                    {
                        TestHelper.Assert(GetAdapterNameWithAMI(obj) == "AdapterAMI66");
                    }

                    adapters.Add(com.CreateObjectAdapterWithEndpoints("AdapterAMI65", endpoints[1].ToString()));
                    for (int i = 0; i < 3; i++)
                    {
                        TestHelper.Assert(GetAdapterNameWithAMI(obj) == "AdapterAMI65");
                    }

                    adapters.Add(com.CreateObjectAdapterWithEndpoints("AdapterAMI64", endpoints[0].ToString()));
                    for (int i = 0; i < 3; i++)
                    {
                        TestHelper.Assert(GetAdapterNameWithAMI(obj) == "AdapterAMI64");
                    }
                    Deactivate(com, adapters);
                }
            }
            output.WriteLine("ok");

            if (communicator.DefaultProtocol == Protocol.Ice1)
            {
                output.Write("testing endpoint mode filtering... ");
                output.Flush();
                {
                    var adapters = new List <IRemoteObjectAdapterPrx>
                    {
                        com.CreateObjectAdapter("Adapter71", "default"),
                        com.CreateObjectAdapter("Adapter72", "udp")
                    };

                    ITestIntfPrx obj = CreateTestIntfPrx(adapters);
                    TestHelper.Assert(obj.GetAdapterName().Equals("Adapter71"));

                    ITestIntfPrx testUDP = obj.Clone(invocationMode: InvocationMode.Datagram);
                    TestHelper.Assert(obj.GetConnection() != testUDP.GetConnection());
                    try
                    {
                        testUDP.GetAdapterName();
                        TestHelper.Assert(false);
                    }
                    catch (InvalidOperationException)
                    {
                        // expected
                    }
                }
                output.WriteLine("ok");
            }
            if (communicator.GetProperty("Ice.Plugin.IceSSL") != null)
            {
                output.Write("testing secure and non-secure endpoints... ");
                output.Flush();
                {
                    var adapters = new List <IRemoteObjectAdapterPrx>
                    {
                        com.CreateObjectAdapter("Adapter81", "ssl") !,
                        com.CreateObjectAdapter("Adapter82", "tcp") !
                    };

                    ITestIntfPrx obj = CreateTestIntfPrx(adapters);

                    for (int i = 0; i < 5; i++)
                    {
                        TestHelper.Assert(obj.GetAdapterName().Equals("Adapter82"));
                        obj.GetConnection() !.Close(ConnectionClose.GracefullyWithWait);
                    }

                    ITestIntfPrx testNonSecure = obj.Clone(preferNonSecure: true);
                    // TODO: update when PreferNonSecure default is updated
                    ITestIntfPrx testSecure = obj.Clone(preferNonSecure: false);
                    TestHelper.Assert(obj.GetConnection() != testSecure.GetConnection());
                    TestHelper.Assert(obj.GetConnection() == testNonSecure.GetConnection());

                    com.DeactivateObjectAdapter(adapters[1]);

                    for (int i = 0; i < 5; i++)
                    {
                        TestHelper.Assert(obj.GetAdapterName().Equals("Adapter81"));
                        obj.GetConnection() !.Close(ConnectionClose.GracefullyWithWait);
                    }

                    // TODO: ice1-only for now, because we send the client endpoints for use in OA configuration.
                    if (communicator.DefaultProtocol == Protocol.Ice1)
                    {
                        com.CreateObjectAdapterWithEndpoints("Adapter83", obj.Endpoints[1].ToString()); // Recreate a tcp OA.

                        for (int i = 0; i < 5; i++)
                        {
                            TestHelper.Assert(obj.GetAdapterName().Equals("Adapter83"));
                            obj.GetConnection() !.Close(ConnectionClose.GracefullyWithWait);
                        }
                    }

                    com.DeactivateObjectAdapter(adapters[0]);

                    try
                    {
                        testSecure.IcePing();
                        TestHelper.Assert(false);
                    }
                    catch (ConnectionRefusedException)
                    {
                        // expected
                    }
                    Deactivate(com, adapters);
                }
                output.WriteLine("ok");
            }

            {
                output.Write("testing ipv4 & ipv6 connections... ");
                output.Flush();

                var ipv4 = new Dictionary <string, string>()
                {
                    { "IPv4", "1" },
                    { "IPv6", "0" },
                    { "Adapter.Endpoints", "tcp -h localhost" }
                };

                var ipv6 = new Dictionary <string, string>()
                {
                    { "IPv4", "0" },
                    { "IPv6", "1" },
                    { "Adapter.Endpoints", "tcp -h localhost" }
                };

                var bothPreferIPv4 = new Dictionary <string, string>()
                {
                    { "IPv4", "1" },
                    { "IPv6", "1" },
                    { "PreferIPv6Address", "0" },
                    { "Adapter.Endpoints", "tcp -h localhost" }
                };

                var bothPreferIPv6 = new Dictionary <string, string>()
                {
                    { "IPv4", "1" },
                    { "IPv6", "1" },
                    { "PreferIPv6Address", "1" },
                    { "Adapter.Endpoints", "tcp -h localhost" }
                };

                Dictionary <string, string>[] clientProps =
                {
                    ipv4, ipv6, bothPreferIPv4, bothPreferIPv6
                };

                string endpoint = "tcp -p " + helper.GetTestPort(2).ToString();

                var anyipv4 = new Dictionary <string, string>(ipv4)
                {
                    ["Adapter.Endpoints"]          = endpoint,
                    ["Adapter.PublishedEndpoints"] = $"{endpoint} -h 127.0.0.1"
                };

                var anyipv6 = new Dictionary <string, string>(ipv6)
                {
                    ["Adapter.Endpoints"]          = endpoint,
                    ["Adapter.PublishedEndpoints"] = $"{endpoint} -h \".1\""
                };

                var anyboth = new Dictionary <string, string>()
                {
                    { "IPv4", "1" },
                    { "IPv6", "1" },
                    { "Adapter.Endpoints", endpoint },
                    { "Adapter.PublishedEndpoints", $"{endpoint} -h \"::1\":{endpoint} -h 127.0.0.1" }
                };

                var localipv4 = new Dictionary <string, string>(ipv4)
                {
                    ["Adapter.Endpoints"] = "tcp -h 127.0.0.1"
                };

                var localipv6 = new Dictionary <string, string>(ipv6)
                {
                    ["Adapter.Endpoints"] = "tcp -h \"::1\""
                };

                Dictionary <string, string>[] serverProps =
                {
                    anyipv4,
                    anyipv6,
                    anyboth,
                    localipv4,
                    localipv6
                };

                bool ipv6NotSupported = false;
                foreach (Dictionary <string, string> p in serverProps)
                {
                    var           serverCommunicator = new Communicator(p);
                    ObjectAdapter oa;
                    try
                    {
                        oa = serverCommunicator.CreateObjectAdapter("Adapter");
                        oa.Activate();
                    }
                    catch (DNSException)
                    {
                        serverCommunicator.Dispose();
                        continue; // IP version not supported.
                    }
                    catch (TransportException)
                    {
                        if (p == ipv6)
                        {
                            ipv6NotSupported = true;
                        }
                        serverCommunicator.Dispose();
                        continue; // IP version not supported.
                    }

                    IObjectPrx prx = oa.CreateProxy("dummy", IObjectPrx.Factory);
                    try
                    {
                        prx.IcePing();
                    }
                    catch (DNSException) // TODO: is this really an expected exception?
                    {
                        serverCommunicator.Dispose();
                        continue;
                    }
                    catch (ObjectNotExistException) // TODO: is this really an expected exception?
                    {
                        serverCommunicator.Dispose();
                        continue;
                    }

                    string strPrx = prx.ToString() !;
                    foreach (Dictionary <string, string> q in clientProps)
                    {
                        var clientCommunicator = new Communicator(q);
                        prx = IObjectPrx.Parse(strPrx, clientCommunicator);
                        try
                        {
                            prx.IcePing();
                            TestHelper.Assert(false);
                        }
                        catch (ObjectNotExistException)
                        {
                            // Expected, no object registered.
                        }
                        catch (DNSException)
                        {
                            // Expected if no IPv4 or IPv6 address is
                            // associated to localhost or if trying to connect
                            // to an any endpoint with the wrong IP version,
                            // e.g.: resolving an IPv4 address when only IPv6
                            // is enabled fails with a DNS exception.
                        }
                        catch (TransportException)
                        {
                            TestHelper.Assert((p == ipv4 && q == ipv6) || (p == ipv6 && q == ipv4) ||
                                              (p == bothPreferIPv4 && q == ipv6) || (p == bothPreferIPv6 && q == ipv4) ||
                                              (p == bothPreferIPv6 && q == ipv6 && ipv6NotSupported) ||
                                              (p == anyipv4 && q == ipv6) || (p == anyipv6 && q == ipv4) ||
                                              (p == localipv4 && q == ipv6) || (p == localipv6 && q == ipv4) ||
                                              (p == ipv6 && q == bothPreferIPv4) || (p == ipv6 && q == bothPreferIPv6) ||
                                              (p == bothPreferIPv6 && q == ipv6));
                        }
                        clientCommunicator.Dispose();
                    }
                    serverCommunicator.Dispose();
                }

                output.WriteLine("ok");
            }

            com.Shutdown();
        }
Пример #2
0
        public static ITestIntfPrx allTests(TestHelper helper)
        {
            Communicator?communicator = helper.Communicator();

            TestHelper.Assert(communicator != null);
            string sref = "test:" + helper.GetTestEndpoint(0);
            var    obj  = IObjectPrx.Parse(sref, communicator);

            TestHelper.Assert(obj != null);
            var proxy = ITestIntfPrx.UncheckedCast(obj);

            TestHelper.Assert(proxy != null);

            System.IO.TextWriter output = helper.GetWriter();

            output.Write("testing enum values... ");
            output.Flush();

            TestHelper.Assert((int)ByteEnum.benum1 == 0);
            TestHelper.Assert((int)ByteEnum.benum2 == 1);
            TestHelper.Assert((int)ByteEnum.benum3 == Constants.ByteConst1);
            TestHelper.Assert((int)ByteEnum.benum4 == Constants.ByteConst1 + 1);
            TestHelper.Assert((int)ByteEnum.benum5 == Constants.ShortConst1);
            TestHelper.Assert((int)ByteEnum.benum6 == Constants.ShortConst1 + 1);
            TestHelper.Assert((int)ByteEnum.benum7 == Constants.IntConst1);
            TestHelper.Assert((int)ByteEnum.benum8 == Constants.IntConst1 + 1);
            TestHelper.Assert((int)ByteEnum.benum9 == Constants.LongConst1);
            TestHelper.Assert((int)ByteEnum.benum10 == Constants.LongConst1 + 1);
            TestHelper.Assert((int)ByteEnum.benum11 == Constants.ByteConst2);

            TestHelper.Assert((int)ShortEnum.senum1 == 3);
            TestHelper.Assert((int)ShortEnum.senum2 == 4);
            TestHelper.Assert((int)ShortEnum.senum3 == Constants.ByteConst1);
            TestHelper.Assert((int)ShortEnum.senum4 == Constants.ByteConst1 + 1);
            TestHelper.Assert((int)ShortEnum.senum5 == Constants.ShortConst1);
            TestHelper.Assert((int)ShortEnum.senum6 == Constants.ShortConst1 + 1);
            TestHelper.Assert((int)ShortEnum.senum7 == Constants.IntConst1);
            TestHelper.Assert((int)ShortEnum.senum8 == Constants.IntConst1 + 1);
            TestHelper.Assert((int)ShortEnum.senum9 == Constants.LongConst1);
            TestHelper.Assert((int)ShortEnum.senum10 == Constants.LongConst1 + 1);
            TestHelper.Assert((int)ShortEnum.senum11 == Constants.ShortConst2);

            TestHelper.Assert((int)IntEnum.ienum1 == 0);
            TestHelper.Assert((int)IntEnum.ienum2 == 1);
            TestHelper.Assert((int)IntEnum.ienum3 == Constants.ByteConst1);
            TestHelper.Assert((int)IntEnum.ienum4 == Constants.ByteConst1 + 1);
            TestHelper.Assert((int)IntEnum.ienum5 == Constants.ShortConst1);
            TestHelper.Assert((int)IntEnum.ienum6 == Constants.ShortConst1 + 1);
            TestHelper.Assert((int)IntEnum.ienum7 == Constants.IntConst1);
            TestHelper.Assert((int)IntEnum.ienum8 == Constants.IntConst1 + 1);
            TestHelper.Assert((int)IntEnum.ienum9 == Constants.LongConst1);
            TestHelper.Assert((int)IntEnum.ienum10 == Constants.LongConst1 + 1);
            TestHelper.Assert((int)IntEnum.ienum11 == Constants.IntConst2);
            TestHelper.Assert((int)IntEnum.ienum12 == Constants.LongConst2);

            TestHelper.Assert((int)SimpleEnum.red == 0);
            TestHelper.Assert((int)SimpleEnum.green == 1);
            TestHelper.Assert((int)SimpleEnum.blue == 2);

            output.WriteLine("ok");

            output.Write("testing enum operations... ");
            output.Flush();
            {
                (ByteEnum r, ByteEnum o) = proxy.OpByte(ByteEnum.benum1);
                TestHelper.Assert(r == ByteEnum.benum1 && o == ByteEnum.benum1);
                (r, o) = proxy.OpByte(ByteEnum.benum11);
                TestHelper.Assert(r == ByteEnum.benum11 && o == ByteEnum.benum11);
            }

            {
                (ByteEnum? r, ByteEnum? o) = proxy.OpTaggedByte(ByteEnum.benum1);
                TestHelper.Assert(r == ByteEnum.benum1 && o == ByteEnum.benum1);
                (r, o) = proxy.OpTaggedByte(ByteEnum.benum11);
                TestHelper.Assert(r == ByteEnum.benum11 && o == ByteEnum.benum11);
                (r, o) = proxy.OpTaggedByte(null);
                TestHelper.Assert(r == null && o == null);
            }

            {
                (ShortEnum r, ShortEnum o) = proxy.OpShort(ShortEnum.senum1);
                TestHelper.Assert(r == ShortEnum.senum1 && o == ShortEnum.senum1);
                (r, o) = proxy.OpShort(ShortEnum.senum11);
                TestHelper.Assert(r == ShortEnum.senum11 && o == ShortEnum.senum11);
            }

            {
                (IntEnum r, IntEnum o) = proxy.OpInt(IntEnum.ienum1);
                TestHelper.Assert(r == IntEnum.ienum1 && o == IntEnum.ienum1);
                (r, o) = proxy.OpInt(IntEnum.ienum11);
                TestHelper.Assert(r == IntEnum.ienum11 && o == IntEnum.ienum11);
                (r, o) = proxy.OpInt(IntEnum.ienum12);
                TestHelper.Assert(r == IntEnum.ienum12 && o == IntEnum.ienum12);
            }

            {
                (SimpleEnum r, SimpleEnum o) = proxy.OpSimple(SimpleEnum.green);
                TestHelper.Assert(r == SimpleEnum.green && o == SimpleEnum.green);
            }

            {
                (FLByteEnum r, FLByteEnum o) = proxy.OpFLByte(FLByteEnum.benum1);
                TestHelper.Assert(r == FLByteEnum.benum1 && o == FLByteEnum.benum1);
                (r, o) = proxy.OpFLByte(FLByteEnum.benum11);
                TestHelper.Assert(r == FLByteEnum.benum11 && o == FLByteEnum.benum11);
            }

            {
                (FLByteEnum? r, FLByteEnum? o) = proxy.OpTaggedFLByte(FLByteEnum.benum1);
                TestHelper.Assert(r == FLByteEnum.benum1 && o == FLByteEnum.benum1);
                (r, o) = proxy.OpTaggedFLByte(FLByteEnum.benum11);
                TestHelper.Assert(r == FLByteEnum.benum11 && o == FLByteEnum.benum11);
                (r, o) = proxy.OpTaggedFLByte(null);
                TestHelper.Assert(r == null && o == null);
            }

            {
                (FLShortEnum r, FLShortEnum o) = proxy.OpFLShort(FLShortEnum.senum1);
                TestHelper.Assert(r == FLShortEnum.senum1 && o == FLShortEnum.senum1);
                (r, o) = proxy.OpFLShort(FLShortEnum.senum11);
                TestHelper.Assert(r == FLShortEnum.senum11 && o == FLShortEnum.senum11);
            }

            {
                (FLUShortEnum r, FLUShortEnum o) = proxy.OpFLUShort(FLUShortEnum.senum1);
                TestHelper.Assert(r == FLUShortEnum.senum1 && o == FLUShortEnum.senum1);
                (r, o) = proxy.OpFLUShort(FLUShortEnum.senum11);
                TestHelper.Assert(r == FLUShortEnum.senum11 && o == FLUShortEnum.senum11);
            }

            {
                (FLIntEnum r, FLIntEnum o) = proxy.OpFLInt(FLIntEnum.ienum1);
                TestHelper.Assert(r == FLIntEnum.ienum1 && o == FLIntEnum.ienum1);
                (r, o) = proxy.OpFLInt(FLIntEnum.ienum11);
                TestHelper.Assert(r == FLIntEnum.ienum11 && o == FLIntEnum.ienum11);
                (r, o) = proxy.OpFLInt(FLIntEnum.ienum12);
                TestHelper.Assert(r == FLIntEnum.ienum12 && o == FLIntEnum.ienum12);
            }

            {
                (FLUIntEnum r, FLUIntEnum o) = proxy.OpFLUInt(FLUIntEnum.ienum1);
                TestHelper.Assert(r == FLUIntEnum.ienum1 && o == FLUIntEnum.ienum1);
                (r, o) = proxy.OpFLUInt(FLUIntEnum.ienum11);
                TestHelper.Assert(r == FLUIntEnum.ienum11 && o == FLUIntEnum.ienum11);
                (r, o) = proxy.OpFLUInt(FLUIntEnum.ienum12);
                TestHelper.Assert(r == FLUIntEnum.ienum12 && o == FLUIntEnum.ienum12);
            }

            {
                (FLSimpleEnum r, FLSimpleEnum o) = proxy.OpFLSimple(FLSimpleEnum.green);
                TestHelper.Assert(r == FLSimpleEnum.green && o == FLSimpleEnum.green);
            }

            output.WriteLine("ok");

            output.Write("testing enum sequences operations... ");
            output.Flush();

            {
                var b1 = new ByteEnum[11]
                {
                    ByteEnum.benum1,
                    ByteEnum.benum2,
                    ByteEnum.benum3,
                    ByteEnum.benum4,
                    ByteEnum.benum5,
                    ByteEnum.benum6,
                    ByteEnum.benum7,
                    ByteEnum.benum8,
                    ByteEnum.benum9,
                    ByteEnum.benum10,
                    ByteEnum.benum11
                };

                (ByteEnum[] b3, ByteEnum[] b2) = proxy.OpByteSeq(b1);
                TestHelper.Assert(b1.SequenceEqual(b2));
                TestHelper.Assert(b1.SequenceEqual(b3));
            }

            {
                var s1 = new ShortEnum[11]
                {
                    ShortEnum.senum1,
                    ShortEnum.senum2,
                    ShortEnum.senum3,
                    ShortEnum.senum4,
                    ShortEnum.senum5,
                    ShortEnum.senum6,
                    ShortEnum.senum7,
                    ShortEnum.senum8,
                    ShortEnum.senum9,
                    ShortEnum.senum10,
                    ShortEnum.senum11
                };

                (ShortEnum[] s3, ShortEnum[] s2) = proxy.OpShortSeq(s1);
                TestHelper.Assert(s1.SequenceEqual(s2));
                TestHelper.Assert(s1.SequenceEqual(s3));
            }

            {
                var i1 = new IntEnum[11]
                {
                    IntEnum.ienum1,
                    IntEnum.ienum2,
                    IntEnum.ienum3,
                    IntEnum.ienum4,
                    IntEnum.ienum5,
                    IntEnum.ienum6,
                    IntEnum.ienum7,
                    IntEnum.ienum8,
                    IntEnum.ienum9,
                    IntEnum.ienum10,
                    IntEnum.ienum11
                };

                (IntEnum[] i3, IntEnum[] i2) = proxy.OpIntSeq(i1);
                TestHelper.Assert(i1.SequenceEqual(i2));
                TestHelper.Assert(i1.SequenceEqual(i3));
            }

            {
                var s1 = new SimpleEnum[3]
                {
                    SimpleEnum.red,
                    SimpleEnum.green,
                    SimpleEnum.blue
                };

                (SimpleEnum[] s3, SimpleEnum[] s2) = proxy.OpSimpleSeq(s1);
                TestHelper.Assert(s1.SequenceEqual(s2));
                TestHelper.Assert(s1.SequenceEqual(s3));
            }

            {
                var b1 = new FLByteEnum[11]
                {
                    FLByteEnum.benum1,
                    FLByteEnum.benum2,
                    FLByteEnum.benum3,
                    FLByteEnum.benum4,
                    FLByteEnum.benum5,
                    FLByteEnum.benum6,
                    FLByteEnum.benum7,
                    FLByteEnum.benum8,
                    FLByteEnum.benum9,
                    FLByteEnum.benum10,
                    FLByteEnum.benum11
                };

                (FLByteEnum[] b3, FLByteEnum[] b2) = proxy.OpFLByteSeq(b1);
                TestHelper.Assert(b1.SequenceEqual(b2));
                TestHelper.Assert(b1.SequenceEqual(b3));
            }

            {
                var s1 = new FLShortEnum[11]
                {
                    FLShortEnum.senum1,
                    FLShortEnum.senum2,
                    FLShortEnum.senum3,
                    FLShortEnum.senum4,
                    FLShortEnum.senum5,
                    FLShortEnum.senum6,
                    FLShortEnum.senum7,
                    FLShortEnum.senum8,
                    FLShortEnum.senum9,
                    FLShortEnum.senum10,
                    FLShortEnum.senum11
                };

                (FLShortEnum[] s3, FLShortEnum[] s2) = proxy.OpFLShortSeq(s1);
                TestHelper.Assert(s1.SequenceEqual(s2));
                TestHelper.Assert(s1.SequenceEqual(s3));
            }

            {
                var s1 = new FLUShortEnum[11]
                {
                    FLUShortEnum.senum1,
                    FLUShortEnum.senum2,
                    FLUShortEnum.senum3,
                    FLUShortEnum.senum4,
                    FLUShortEnum.senum5,
                    FLUShortEnum.senum6,
                    FLUShortEnum.senum7,
                    FLUShortEnum.senum8,
                    FLUShortEnum.senum9,
                    FLUShortEnum.senum10,
                    FLUShortEnum.senum11
                };

                (FLUShortEnum[] s3, FLUShortEnum[] s2) = proxy.OpFLUShortSeq(s1);
                TestHelper.Assert(s1.SequenceEqual(s2));
                TestHelper.Assert(s1.SequenceEqual(s3));
            }

            {
                var i1 = new FLIntEnum[11]
                {
                    FLIntEnum.ienum1,
                    FLIntEnum.ienum2,
                    FLIntEnum.ienum3,
                    FLIntEnum.ienum4,
                    FLIntEnum.ienum5,
                    FLIntEnum.ienum6,
                    FLIntEnum.ienum7,
                    FLIntEnum.ienum8,
                    FLIntEnum.ienum9,
                    FLIntEnum.ienum10,
                    FLIntEnum.ienum11
                };

                (FLIntEnum[] i3, FLIntEnum[] i2) = proxy.OpFLIntSeq(i1);
                TestHelper.Assert(i1.SequenceEqual(i2));
                TestHelper.Assert(i1.SequenceEqual(i3));
            }

            {
                var i1 = new FLUIntEnum[11]
                {
                    FLUIntEnum.ienum1,
                    FLUIntEnum.ienum2,
                    FLUIntEnum.ienum3,
                    FLUIntEnum.ienum4,
                    FLUIntEnum.ienum5,
                    FLUIntEnum.ienum6,
                    FLUIntEnum.ienum7,
                    FLUIntEnum.ienum8,
                    FLUIntEnum.ienum9,
                    FLUIntEnum.ienum10,
                    FLUIntEnum.ienum11
                };

                (FLUIntEnum[] i3, FLUIntEnum[] i2) = proxy.OpFLUIntSeq(i1);
                TestHelper.Assert(i1.SequenceEqual(i2));
                TestHelper.Assert(i1.SequenceEqual(i3));
            }

            {
                var s1 = new FLSimpleEnum[3]
                {
                    FLSimpleEnum.red,
                    FLSimpleEnum.green,
                    FLSimpleEnum.blue
                };

                (FLSimpleEnum[] s3, FLSimpleEnum[] s2) = proxy.OpFLSimpleSeq(s1);
                TestHelper.Assert(s1.SequenceEqual(s2));
                TestHelper.Assert(s1.SequenceEqual(s3));
            }

            {
                var b1 = new ByteEnum[11]
                {
                    ByteEnum.benum1,
                    ByteEnum.benum2,
                    ByteEnum.benum3,
                    ByteEnum.benum4,
                    ByteEnum.benum5,
                    ByteEnum.benum6,
                    ByteEnum.benum7,
                    ByteEnum.benum8,
                    ByteEnum.benum9,
                    ByteEnum.benum10,
                    ByteEnum.benum11
                };

                (ByteEnum[]? b3, ByteEnum[]? b2) = proxy.OpTaggedByteSeq(b1);
                TestHelper.Assert(b2 != null && b3 != null);

                TestHelper.Assert(b1.SequenceEqual(b2));
                TestHelper.Assert(b1.SequenceEqual(b3));

                (b3, b2) = proxy.OpTaggedByteSeq(null);
                TestHelper.Assert(b2 == null && b3 == null);
            }

            {
                var b1 = new FLByteEnum[11]
                {
                    FLByteEnum.benum1,
                    FLByteEnum.benum2,
                    FLByteEnum.benum3,
                    FLByteEnum.benum4,
                    FLByteEnum.benum5,
                    FLByteEnum.benum6,
                    FLByteEnum.benum7,
                    FLByteEnum.benum8,
                    FLByteEnum.benum9,
                    FLByteEnum.benum10,
                    FLByteEnum.benum11
                };

                (FLByteEnum[]? b3, FLByteEnum[]? b2) = proxy.OpTaggedFLByteSeq(b1);
                TestHelper.Assert(b2 != null && b3 != null);

                TestHelper.Assert(b1.SequenceEqual(b2));
                TestHelper.Assert(b1.SequenceEqual(b3));

                (b3, b2) = proxy.OpTaggedFLByteSeq(null);
                TestHelper.Assert(b2 == null && b3 == null);
            }

            {
                var i1 = new FLIntEnum[11]
                {
                    FLIntEnum.ienum1,
                    FLIntEnum.ienum2,
                    FLIntEnum.ienum3,
                    FLIntEnum.ienum4,
                    FLIntEnum.ienum5,
                    FLIntEnum.ienum6,
                    FLIntEnum.ienum7,
                    FLIntEnum.ienum8,
                    FLIntEnum.ienum9,
                    FLIntEnum.ienum10,
                    FLIntEnum.ienum11
                };

                (FLIntEnum[]? i3, FLIntEnum[]? i2) = proxy.OpTaggedFLIntSeq(i1);
                TestHelper.Assert(i2 != null && i3 != null);

                TestHelper.Assert(i1.SequenceEqual(i2));
                TestHelper.Assert(i1.SequenceEqual(i3));

                (i3, i2) = proxy.OpTaggedFLIntSeq(null);
                TestHelper.Assert(i2 == null && i3 == null);
            }

            output.WriteLine("ok");
            return(proxy);
        }
Пример #3
0
        public static ITestIntfPrx allTests(TestHelper helper)
        {
            Communicator?communicator = helper.Communicator();

            TestHelper.Assert(communicator != null);
            string sref = "test:" + helper.GetTestEndpoint(0);
            var    obj  = IObjectPrx.Parse(sref, communicator);

            TestHelper.Assert(obj != null);
            var proxy = ITestIntfPrx.UncheckedCast(obj);

            TestHelper.Assert(proxy != null);

            System.IO.TextWriter output = helper.GetWriter();

            output.Write("testing enum values... ");
            output.Flush();

            TestHelper.Assert((int)ByteEnum.benum1 == 0);
            TestHelper.Assert((int)ByteEnum.benum2 == 1);
            TestHelper.Assert((int)ByteEnum.benum3 == Constants.ByteConst1);
            TestHelper.Assert((int)ByteEnum.benum4 == Constants.ByteConst1 + 1);
            TestHelper.Assert((int)ByteEnum.benum5 == Constants.ShortConst1);
            TestHelper.Assert((int)ByteEnum.benum6 == Constants.ShortConst1 + 1);
            TestHelper.Assert((int)ByteEnum.benum7 == Constants.IntConst1);
            TestHelper.Assert((int)ByteEnum.benum8 == Constants.IntConst1 + 1);
            TestHelper.Assert((int)ByteEnum.benum9 == Constants.LongConst1);
            TestHelper.Assert((int)ByteEnum.benum10 == Constants.LongConst1 + 1);
            TestHelper.Assert((int)ByteEnum.benum11 == Constants.ByteConst2);

            TestHelper.Assert((int)ShortEnum.senum1 == 3);
            TestHelper.Assert((int)ShortEnum.senum2 == 4);
            TestHelper.Assert((int)ShortEnum.senum3 == Constants.ByteConst1);
            TestHelper.Assert((int)ShortEnum.senum4 == Constants.ByteConst1 + 1);
            TestHelper.Assert((int)ShortEnum.senum5 == Constants.ShortConst1);
            TestHelper.Assert((int)ShortEnum.senum6 == Constants.ShortConst1 + 1);
            TestHelper.Assert((int)ShortEnum.senum7 == Constants.IntConst1);
            TestHelper.Assert((int)ShortEnum.senum8 == Constants.IntConst1 + 1);
            TestHelper.Assert((int)ShortEnum.senum9 == Constants.LongConst1);
            TestHelper.Assert((int)ShortEnum.senum10 == Constants.LongConst1 + 1);
            TestHelper.Assert((int)ShortEnum.senum11 == Constants.ShortConst2);

            TestHelper.Assert((int)IntEnum.ienum1 == 0);
            TestHelper.Assert((int)IntEnum.ienum2 == 1);
            TestHelper.Assert((int)IntEnum.ienum3 == Constants.ByteConst1);
            TestHelper.Assert((int)IntEnum.ienum4 == Constants.ByteConst1 + 1);
            TestHelper.Assert((int)IntEnum.ienum5 == Constants.ShortConst1);
            TestHelper.Assert((int)IntEnum.ienum6 == Constants.ShortConst1 + 1);
            TestHelper.Assert((int)IntEnum.ienum7 == Constants.IntConst1);
            TestHelper.Assert((int)IntEnum.ienum8 == Constants.IntConst1 + 1);
            TestHelper.Assert((int)IntEnum.ienum9 == Constants.LongConst1);
            TestHelper.Assert((int)IntEnum.ienum10 == Constants.LongConst1 + 1);
            TestHelper.Assert((int)IntEnum.ienum11 == Constants.IntConst2);
            TestHelper.Assert((int)IntEnum.ienum12 == Constants.LongConst2);

            TestHelper.Assert((int)SimpleEnum.red == 0);
            TestHelper.Assert((int)SimpleEnum.green == 1);
            TestHelper.Assert((int)SimpleEnum.blue == 2);

            output.WriteLine("ok");

            output.Write("testing enum operations... ");
            output.Flush();
            {
                (ByteEnum r, ByteEnum o) = proxy.opByte(ByteEnum.benum1);
                TestHelper.Assert(r == ByteEnum.benum1 && o == ByteEnum.benum1);
                (r, o) = proxy.opByte(ByteEnum.benum11);
                TestHelper.Assert(r == ByteEnum.benum11 && o == ByteEnum.benum11);
            }

            {
                (ShortEnum r, ShortEnum o) = proxy.opShort(ShortEnum.senum1);
                TestHelper.Assert(r == ShortEnum.senum1 && o == ShortEnum.senum1);
                (r, o) = proxy.opShort(ShortEnum.senum11);
                TestHelper.Assert(r == ShortEnum.senum11 && o == ShortEnum.senum11);
            }

            {
                (IntEnum r, IntEnum o) = proxy.opInt(IntEnum.ienum1);
                TestHelper.Assert(r == IntEnum.ienum1 && o == IntEnum.ienum1);
                (r, o) = proxy.opInt(IntEnum.ienum11);
                TestHelper.Assert(r == IntEnum.ienum11 && o == IntEnum.ienum11);
                (r, o) = proxy.opInt(IntEnum.ienum12);
                TestHelper.Assert(r == IntEnum.ienum12 && o == IntEnum.ienum12);
            }

            {
                (SimpleEnum r, SimpleEnum o) = proxy.opSimple(SimpleEnum.green);
                TestHelper.Assert(r == SimpleEnum.green && o == SimpleEnum.green);
            }

            output.WriteLine("ok");

            output.Write("testing enum sequences operations... ");
            output.Flush();

            {
                var b1 = new ByteEnum[11]
                {
                    ByteEnum.benum1,
                    ByteEnum.benum2,
                    ByteEnum.benum3,
                    ByteEnum.benum4,
                    ByteEnum.benum5,
                    ByteEnum.benum6,
                    ByteEnum.benum7,
                    ByteEnum.benum8,
                    ByteEnum.benum9,
                    ByteEnum.benum10,
                    ByteEnum.benum11
                };

                (ByteEnum[] b3, ByteEnum[] b2) = proxy.opByteSeq(b1);

                for (int i = 0; i < b1.Length; ++i)
                {
                    TestHelper.Assert(b1[i] == b2[i]);
                    TestHelper.Assert(b1[i] == b3[i]);
                }
            }

            {
                var s1 = new ShortEnum[11]
                {
                    ShortEnum.senum1,
                    ShortEnum.senum2,
                    ShortEnum.senum3,
                    ShortEnum.senum4,
                    ShortEnum.senum5,
                    ShortEnum.senum6,
                    ShortEnum.senum7,
                    ShortEnum.senum8,
                    ShortEnum.senum9,
                    ShortEnum.senum10,
                    ShortEnum.senum11
                };

                (ShortEnum[] s3, ShortEnum[] s2) = proxy.opShortSeq(s1);

                for (int i = 0; i < s1.Length; ++i)
                {
                    TestHelper.Assert(s1[i] == s2[i]);
                    TestHelper.Assert(s1[i] == s3[i]);
                }
            }

            {
                var i1 = new IntEnum[11]
                {
                    IntEnum.ienum1,
                    IntEnum.ienum2,
                    IntEnum.ienum3,
                    IntEnum.ienum4,
                    IntEnum.ienum5,
                    IntEnum.ienum6,
                    IntEnum.ienum7,
                    IntEnum.ienum8,
                    IntEnum.ienum9,
                    IntEnum.ienum10,
                    IntEnum.ienum11
                };

                (IntEnum[] i3, IntEnum[] i2) = proxy.opIntSeq(i1);

                for (int i = 0; i < i1.Length; ++i)
                {
                    TestHelper.Assert(i1[i] == i2[i]);
                    TestHelper.Assert(i1[i] == i3[i]);
                }
            }

            {
                var s1 = new SimpleEnum[3]
                {
                    SimpleEnum.red,
                    SimpleEnum.green,
                    SimpleEnum.blue
                };

                (SimpleEnum[] s3, SimpleEnum[] s2) = proxy.opSimpleSeq(s1);

                for (int i = 0; i < s1.Length; ++i)
                {
                    TestHelper.Assert(s1[i] == s2[i]);
                    TestHelper.Assert(s1[i] == s3[i]);
                }
            }

            output.WriteLine("ok");
            return(proxy);
        }
Пример #4
0
    public static void allTests(Test.TestHelper helper)
    {
        var          output       = helper.getWriter();
        Communicator communicator = helper.communicator();
        string       sref         = "test:" + helper.getTestEndpoint(0);
        var          obj          = IObjectPrx.Parse(sref, communicator);

        test(obj != null);

        ITestIntfPrx p = ITestIntfPrx.UncheckedCast(obj);

        sref = "testController:" + helper.getTestEndpoint(1);
        obj  = IObjectPrx.Parse(sref, communicator);
        test(obj != null);

        var testController = ITestIntfControllerPrx.UncheckedCast(obj);

        output.Write("testing dispatcher with continuations... ");
        output.Flush();
        {
            p.op();

            Callback      cb           = new Callback(output);
            Action <Task> continuation = (Task previous) =>
            {
                try
                {
                    previous.Wait();
                    cb.response();
                }
                catch (AggregateException ex)
                {
                    cb.exception((Ice.Exception)ex.InnerException);
                }
            };
            // We use sleepAsync instead of opAsync to ensure the response isn't received before
            // we setup the continuation
            var t = p.sleepAsync(500).ContinueWith(continuation, TaskContinuationOptions.ExecuteSynchronously);
            t.Wait();
            cb.check();

            var i = p.Clone(connectionId: "dummy");

            //
            // sleepAsync doesn't help here as the test will fail with Ice.NoEndpointException and sleepAsync
            // will not be called.
            //
            //i.sleepAsync(500).ContinueWith(continuation, TaskContinuationOptions.ExecuteSynchronously).Wait();
            //cb.check();

            //
            // Expect InvocationTimeoutException.
            //
            {
                // The continuation might be (rarely) executed on the current thread if the setup of the
                // continuation occurs after the invocation timeout.
                var          thread = Thread.CurrentThread;
                ITestIntfPrx to     = p.Clone(invocationTimeout: 20);
                to.sleepAsync(500).ContinueWith(
                    previous =>
                {
                    try
                    {
                        previous.Wait();
                        test(false);
                    }
                    catch (AggregateException ex)
                    {
                        test(ex.InnerException is Ice.InvocationTimeoutException);
                        test(Dispatcher.isDispatcherThread() || thread == Thread.CurrentThread);
                    }
                }, TaskContinuationOptions.ExecuteSynchronously).Wait();
            }

            //
            // Repeat using the proxy scheduler in this case we don't need to call sleepAsync, continuations
            // are waranted to run with the dispatcher even if not executed synchronously.
            //

            t = p.opAsync().ContinueWith(continuation, p.Scheduler);
            t.Wait();
            cb.check();

            i.opAsync().ContinueWith(continuation, i.Scheduler).Wait();
            cb.check();

            //
            // Expect InvocationTimeoutException.
            //
            {
                ITestIntfPrx to = p.Clone(invocationTimeout: 10);
                to.sleepAsync(500).ContinueWith(
                    previous =>
                {
                    try
                    {
                        previous.Wait();
                        test(false);
                    }
                    catch (AggregateException ex)
                    {
                        test(ex.InnerException is Ice.InvocationTimeoutException);
                        test(Dispatcher.isDispatcherThread());
                    }
                }, p.Scheduler).Wait();
            }

            //
            // Hold adapter to ensure the invocations don't complete synchronously
            // Also disable collocation optimization on p
            //
            testController.holdAdapter();
            var           p2            = p.Clone(collocationOptimized: false);
            Action <Task> continuation2 = (Task previous) =>
            {
                test(Dispatcher.isDispatcherThread());
                try
                {
                    previous.Wait();
                }
                catch (AggregateException ex)
                {
                    test(ex.InnerException is Ice.CommunicatorDestroyedException);
                }
            };

            byte[] seq = new byte[10 * 1024];
            (new Random()).NextBytes(seq);
            Progress sentSynchronously;
            do
            {
                sentSynchronously = new Progress();
                t = p2.opWithPayloadAsync(seq, progress: sentSynchronously).ContinueWith(
                    continuation2,
                    TaskContinuationOptions.ExecuteSynchronously);
            }while (sentSynchronously.getResult());
            testController.resumeAdapter();
            t.Wait();
        }
        output.WriteLine("ok");

        output.Write("testing dispatcher with async/await... ");
        output.Flush();
        {
            TaskCompletionSource <object> t = new TaskCompletionSource <object>();
            p.opAsync().ContinueWith(async previous => // Execute the code below from the Ice client thread pool
            {
                try
                {
                    await p.opAsync();
                    test(Dispatcher.isDispatcherThread());

                    try
                    {
                        ITestIntfPrx i = p.Clone(adapterId: "dummy");
                        await i.opAsync();
                        test(false);
                    }
                    catch (System.Exception)
                    {
                        test(Dispatcher.isDispatcherThread());
                    }

                    ITestIntfPrx to = p.Clone(invocationTimeout: 10);
                    try
                    {
                        await to.sleepAsync(500);
                        test(false);
                    }
                    catch (Ice.InvocationTimeoutException)
                    {
                        test(Dispatcher.isDispatcherThread());
                    }
                    t.SetResult(null);
                }
                catch (System.Exception ex)
                {
                    t.SetException(ex);
                }
            }, p.Scheduler);

            t.Task.Wait();
        }
        output.WriteLine("ok");

        p.shutdown();
    }
Пример #5
0
        public static ITestIntfPrx Run(TestHelper helper)
        {
            Communicator?communicator = helper.Communicator();

            TestHelper.Assert(communicator != null);
            string sref = helper.GetTestProxy("test", 0);
            var    obj  = IObjectPrx.Parse(sref, communicator);

            TestHelper.Assert(obj != null);
            var proxy = ITestIntfPrx.UncheckedCast(obj);

            TestHelper.Assert(proxy != null);

            System.IO.TextWriter output = helper.GetWriter();

            output.Write("testing enum values... ");
            output.Flush();

            TestHelper.Assert((int)ByteEnum.benum1 == 0);
            TestHelper.Assert((int)ByteEnum.benum2 == 1);
            TestHelper.Assert((int)ByteEnum.benum3 == Constants.ByteConst1);
            TestHelper.Assert((int)ByteEnum.benum4 == Constants.ByteConst1 + 1);
            TestHelper.Assert((int)ByteEnum.benum5 == Constants.ShortConst1);
            TestHelper.Assert((int)ByteEnum.benum6 == Constants.ShortConst1 + 1);
            TestHelper.Assert((int)ByteEnum.benum7 == Constants.IntConst1);
            TestHelper.Assert((int)ByteEnum.benum8 == Constants.IntConst1 + 1);
            TestHelper.Assert((int)ByteEnum.benum9 == Constants.LongConst1);
            TestHelper.Assert((int)ByteEnum.benum10 == Constants.LongConst1 + 1);
            TestHelper.Assert((int)ByteEnum.benum11 == Constants.ByteConst2);

            TestHelper.Assert((int)ShortEnum.senum1 == 3);
            TestHelper.Assert((int)ShortEnum.senum2 == 4);
            TestHelper.Assert((int)ShortEnum.senum3 == Constants.ByteConst1);
            TestHelper.Assert((int)ShortEnum.senum4 == Constants.ByteConst1 + 1);
            TestHelper.Assert((int)ShortEnum.senum5 == Constants.ShortConst1);
            TestHelper.Assert((int)ShortEnum.senum6 == Constants.ShortConst1 + 1);
            TestHelper.Assert((int)ShortEnum.senum7 == Constants.IntConst1);
            TestHelper.Assert((int)ShortEnum.senum8 == Constants.IntConst1 + 1);
            TestHelper.Assert((int)ShortEnum.senum9 == Constants.LongConst1);
            TestHelper.Assert((int)ShortEnum.senum10 == Constants.LongConst1 + 1);
            TestHelper.Assert((int)ShortEnum.senum11 == Constants.ShortConst2);

            TestHelper.Assert((int)IntEnum.ienum1 == 0);
            TestHelper.Assert((int)IntEnum.ienum2 == 1);
            TestHelper.Assert((int)IntEnum.ienum3 == Constants.ByteConst1);
            TestHelper.Assert((int)IntEnum.ienum4 == Constants.ByteConst1 + 1);
            TestHelper.Assert((int)IntEnum.ienum5 == Constants.ShortConst1);
            TestHelper.Assert((int)IntEnum.ienum6 == Constants.ShortConst1 + 1);
            TestHelper.Assert((int)IntEnum.ienum7 == Constants.IntConst1);
            TestHelper.Assert((int)IntEnum.ienum8 == Constants.IntConst1 + 1);
            TestHelper.Assert((int)IntEnum.ienum9 == Constants.LongConst1);
            TestHelper.Assert((int)IntEnum.ienum10 == Constants.LongConst1 + 1);
            TestHelper.Assert((int)IntEnum.ienum11 == Constants.IntConst2);
            TestHelper.Assert((int)IntEnum.ienum12 == Constants.LongConst2);

            TestHelper.Assert((int)SimpleEnum.red == 0);
            TestHelper.Assert((int)SimpleEnum.green == 1);
            TestHelper.Assert((int)SimpleEnum.blue == 2);

            output.WriteLine("ok");

            output.Write("testing enum operations... ");
            output.Flush();
            {
                (ByteEnum r, ByteEnum o) = proxy.OpByte(ByteEnum.benum1);
                TestHelper.Assert(r == ByteEnum.benum1 && o == ByteEnum.benum1);
                (r, o) = proxy.OpByte(ByteEnum.benum11);
                TestHelper.Assert(r == ByteEnum.benum11 && o == ByteEnum.benum11);
            }

            {
                // 42 does not correspond to a ByteEnum enumerator, so we expect failure since ByteEnum is checked.
                try
                {
                    _ = proxy.OpByte((ByteEnum)42);
                    TestHelper.Assert(false);
                }
                catch (UnhandledException) // unhandled dispatch exception
                {
                    // expected
                }
            }

            {
                (ByteEnum? r, ByteEnum? o) = proxy.OpTaggedByte(ByteEnum.benum1);
                TestHelper.Assert(r == ByteEnum.benum1 && o == ByteEnum.benum1);
                (r, o) = proxy.OpTaggedByte(ByteEnum.benum11);
                TestHelper.Assert(r == ByteEnum.benum11 && o == ByteEnum.benum11);
                (r, o) = proxy.OpTaggedByte(null);
                TestHelper.Assert(r == null && o == null);
            }

            {
                try
                {
                    _ = proxy.OpTaggedByte((ByteEnum)42);
                    TestHelper.Assert(false);
                }
                catch (UnhandledException) // unhandled dispatch exception
                {
                    // expected
                }
            }

            {
                (ShortEnum r, ShortEnum o) = proxy.OpShort(ShortEnum.senum1);
                TestHelper.Assert(r == ShortEnum.senum1 && o == ShortEnum.senum1);
                (r, o) = proxy.OpShort(ShortEnum.senum11);
                TestHelper.Assert(r == ShortEnum.senum11 && o == ShortEnum.senum11);
            }

            {
                (IntEnum r, IntEnum o) = proxy.OpInt(IntEnum.ienum1);
                TestHelper.Assert(r == IntEnum.ienum1 && o == IntEnum.ienum1);
                (r, o) = proxy.OpInt(IntEnum.ienum11);
                TestHelper.Assert(r == IntEnum.ienum11 && o == IntEnum.ienum11);
                (r, o) = proxy.OpInt(IntEnum.ienum12);
                TestHelper.Assert(r == IntEnum.ienum12 && o == IntEnum.ienum12);
            }

            {
                (SimpleEnum r, SimpleEnum o) = proxy.OpSimple(SimpleEnum.green);
                TestHelper.Assert(r == SimpleEnum.green && o == SimpleEnum.green);
            }

            {
                (FLByteEnum r, FLByteEnum o) = proxy.OpFLByte(FLByteEnum.benum1);
                TestHelper.Assert(r == FLByteEnum.benum1 && o == FLByteEnum.benum1);
                (r, o) = proxy.OpFLByte(FLByteEnum.benum11);
                TestHelper.Assert(r == FLByteEnum.benum11 && o == FLByteEnum.benum11);
            }

            {
                (FLByteEnum? r, FLByteEnum? o) = proxy.OpTaggedFLByte(FLByteEnum.benum1);
                TestHelper.Assert(r == FLByteEnum.benum1 && o == FLByteEnum.benum1);
                (r, o) = proxy.OpTaggedFLByte(FLByteEnum.benum11);
                TestHelper.Assert(r == FLByteEnum.benum11 && o == FLByteEnum.benum11);
                (r, o) = proxy.OpTaggedFLByte(null);
                TestHelper.Assert(r == null && o == null);
            }

            {
                (FLShortEnum r, FLShortEnum o) = proxy.OpFLShort(FLShortEnum.senum1);
                TestHelper.Assert(r == FLShortEnum.senum1 && o == FLShortEnum.senum1);
                (r, o) = proxy.OpFLShort(FLShortEnum.senum11);
                TestHelper.Assert(r == FLShortEnum.senum11 && o == FLShortEnum.senum11);
            }

            {
                (FLUShortEnum r, FLUShortEnum o) = proxy.OpFLUShort(FLUShortEnum.senum1);
                TestHelper.Assert(r == FLUShortEnum.senum1 && o == FLUShortEnum.senum1);
                (r, o) = proxy.OpFLUShort(FLUShortEnum.senum11);
                TestHelper.Assert(r == FLUShortEnum.senum11 && o == FLUShortEnum.senum11);
            }

            {
                (FLIntEnum r, FLIntEnum o) = proxy.OpFLInt(FLIntEnum.ienum1);
                TestHelper.Assert(r == FLIntEnum.ienum1 && o == FLIntEnum.ienum1);
                (r, o) = proxy.OpFLInt(FLIntEnum.ienum11);
                TestHelper.Assert(r == FLIntEnum.ienum11 && o == FLIntEnum.ienum11);
                (r, o) = proxy.OpFLInt(FLIntEnum.ienum12);
                TestHelper.Assert(r == FLIntEnum.ienum12 && o == FLIntEnum.ienum12);
            }

            {
                (FLUIntEnum r, FLUIntEnum o) = proxy.OpFLUInt(FLUIntEnum.ienum1);
                TestHelper.Assert(r == FLUIntEnum.ienum1 && o == FLUIntEnum.ienum1);
                (r, o) = proxy.OpFLUInt(FLUIntEnum.ienum11);
                TestHelper.Assert(r == FLUIntEnum.ienum11 && o == FLUIntEnum.ienum11);
                (r, o) = proxy.OpFLUInt(FLUIntEnum.ienum12);
                TestHelper.Assert(r == FLUIntEnum.ienum12 && o == FLUIntEnum.ienum12);
            }

            {
                (FLSimpleEnum r, FLSimpleEnum o) = proxy.OpFLSimple(FLSimpleEnum.green);
                TestHelper.Assert(r == FLSimpleEnum.green && o == FLSimpleEnum.green);
            }

            output.WriteLine("ok");

            output.Write("testing enum sequences operations... ");
            output.Flush();

            {
                var b1 = new ByteEnum[11]
                {
                    ByteEnum.benum1,
                    ByteEnum.benum2,
                    ByteEnum.benum3,
                    ByteEnum.benum4,
                    ByteEnum.benum5,
                    ByteEnum.benum6,
                    ByteEnum.benum7,
                    ByteEnum.benum8,
                    ByteEnum.benum9,
                    ByteEnum.benum10,
                    ByteEnum.benum11
                };

                (ByteEnum[] b3, ByteEnum[] b2) = proxy.OpByteSeq(b1);
                TestHelper.Assert(b1.SequenceEqual(b2));
                TestHelper.Assert(b1.SequenceEqual(b3));
            }

            {
                var b1 = new ByteEnum[12]
                {
                    ByteEnum.benum1,
                    ByteEnum.benum2,
                    (ByteEnum)42,
                    ByteEnum.benum3,
                    ByteEnum.benum4,
                    ByteEnum.benum5,
                    ByteEnum.benum6,
                    ByteEnum.benum7,
                    ByteEnum.benum8,
                    ByteEnum.benum9,
                    ByteEnum.benum10,
                    ByteEnum.benum11
                };

                try
                {
                    _ = proxy.OpByteSeq(b1);
                    TestHelper.Assert(false);
                }
                catch (UnhandledException)
                {
                    // expected
                }
            }

            {
                var s1 = new ShortEnum[11]
                {
                    ShortEnum.senum1,
                    ShortEnum.senum2,
                    ShortEnum.senum3,
                    ShortEnum.senum4,
                    ShortEnum.senum5,
                    ShortEnum.senum6,
                    ShortEnum.senum7,
                    ShortEnum.senum8,
                    ShortEnum.senum9,
                    ShortEnum.senum10,
                    ShortEnum.senum11
                };

                (ShortEnum[] s3, ShortEnum[] s2) = proxy.OpShortSeq(s1);
                TestHelper.Assert(s1.SequenceEqual(s2));
                TestHelper.Assert(s1.SequenceEqual(s3));
            }

            {
                var i1 = new IntEnum[11]
                {
                    IntEnum.ienum1,
                    IntEnum.ienum2,
                    IntEnum.ienum3,
                    IntEnum.ienum4,
                    IntEnum.ienum5,
                    IntEnum.ienum6,
                    IntEnum.ienum7,
                    IntEnum.ienum8,
                    IntEnum.ienum9,
                    IntEnum.ienum10,
                    IntEnum.ienum11
                };

                (IntEnum[] i3, IntEnum[] i2) = proxy.OpIntSeq(i1);
                TestHelper.Assert(i1.SequenceEqual(i2));
                TestHelper.Assert(i1.SequenceEqual(i3));
            }

            {
                var s1 = new SimpleEnum[3]
                {
                    SimpleEnum.red,
                    SimpleEnum.green,
                    SimpleEnum.blue
                };

                (SimpleEnum[] s3, SimpleEnum[] s2) = proxy.OpSimpleSeq(s1);
                TestHelper.Assert(s1.SequenceEqual(s2));
                TestHelper.Assert(s1.SequenceEqual(s3));
            }

            {
                var b1 = new FLByteEnum[11]
                {
                    FLByteEnum.benum1,
                    FLByteEnum.benum2,
                    FLByteEnum.benum3,
                    FLByteEnum.benum4,
                    FLByteEnum.benum5,
                    FLByteEnum.benum6,
                    FLByteEnum.benum7,
                    FLByteEnum.benum8,
                    FLByteEnum.benum9,
                    FLByteEnum.benum10,
                    FLByteEnum.benum11
                };

                (FLByteEnum[] b3, FLByteEnum[] b2) = proxy.OpFLByteSeq(b1);
                TestHelper.Assert(b1.SequenceEqual(b2));
                TestHelper.Assert(b1.SequenceEqual(b3));
            }

            {
                var s1 = new FLShortEnum[11]
                {
                    FLShortEnum.senum1,
                    FLShortEnum.senum2,
                    FLShortEnum.senum3,
                    FLShortEnum.senum4,
                    FLShortEnum.senum5,
                    FLShortEnum.senum6,
                    FLShortEnum.senum7,
                    FLShortEnum.senum8,
                    FLShortEnum.senum9,
                    FLShortEnum.senum10,
                    FLShortEnum.senum11
                };

                (FLShortEnum[] s3, FLShortEnum[] s2) = proxy.OpFLShortSeq(s1);
                TestHelper.Assert(s1.SequenceEqual(s2));
                TestHelper.Assert(s1.SequenceEqual(s3));
            }

            {
                var s1 = new FLUShortEnum[11]
                {
                    FLUShortEnum.senum1,
                    FLUShortEnum.senum2,
                    FLUShortEnum.senum3,
                    FLUShortEnum.senum4,
                    FLUShortEnum.senum5,
                    FLUShortEnum.senum6,
                    FLUShortEnum.senum7,
                    FLUShortEnum.senum8,
                    FLUShortEnum.senum9,
                    FLUShortEnum.senum10,
                    FLUShortEnum.senum11
                };

                (FLUShortEnum[] s3, FLUShortEnum[] s2) = proxy.OpFLUShortSeq(s1);
                TestHelper.Assert(s1.SequenceEqual(s2));
                TestHelper.Assert(s1.SequenceEqual(s3));
            }

            {
                var i1 = new FLIntEnum[11]
                {
                    FLIntEnum.ienum1,
                    FLIntEnum.ienum2,
                    FLIntEnum.ienum3,
                    FLIntEnum.ienum4,
                    FLIntEnum.ienum5,
                    FLIntEnum.ienum6,
                    FLIntEnum.ienum7,
                    FLIntEnum.ienum8,
                    FLIntEnum.ienum9,
                    FLIntEnum.ienum10,
                    FLIntEnum.ienum11
                };

                (FLIntEnum[] i3, FLIntEnum[] i2) = proxy.OpFLIntSeq(i1);
                TestHelper.Assert(i1.SequenceEqual(i2));
                TestHelper.Assert(i1.SequenceEqual(i3));
            }

            {
                var i1 = new FLUIntEnum[11]
                {
                    FLUIntEnum.ienum1,
                    FLUIntEnum.ienum2,
                    FLUIntEnum.ienum3,
                    FLUIntEnum.ienum4,
                    FLUIntEnum.ienum5,
                    FLUIntEnum.ienum6,
                    FLUIntEnum.ienum7,
                    FLUIntEnum.ienum8,
                    FLUIntEnum.ienum9,
                    FLUIntEnum.ienum10,
                    FLUIntEnum.ienum11
                };

                (FLUIntEnum[] i3, FLUIntEnum[] i2) = proxy.OpFLUIntSeq(i1);
                TestHelper.Assert(i1.SequenceEqual(i2));
                TestHelper.Assert(i1.SequenceEqual(i3));
            }

            {
                var s1 = new FLSimpleEnum[3]
                {
                    FLSimpleEnum.red,
                    FLSimpleEnum.green,
                    FLSimpleEnum.blue
                };

                (FLSimpleEnum[] s3, FLSimpleEnum[] s2) = proxy.OpFLSimpleSeq(s1);
                TestHelper.Assert(s1.SequenceEqual(s2));
                TestHelper.Assert(s1.SequenceEqual(s3));
            }

            {
                var b1 = new ByteEnum[11]
                {
                    ByteEnum.benum1,
                    ByteEnum.benum2,
                    ByteEnum.benum3,
                    ByteEnum.benum4,
                    ByteEnum.benum5,
                    ByteEnum.benum6,
                    ByteEnum.benum7,
                    ByteEnum.benum8,
                    ByteEnum.benum9,
                    ByteEnum.benum10,
                    ByteEnum.benum11
                };

                (ByteEnum[]? b3, ByteEnum[]? b2) = proxy.OpTaggedByteSeq(b1);
                TestHelper.Assert(b2 != null && b3 != null);

                TestHelper.Assert(b1.SequenceEqual(b2));
                TestHelper.Assert(b1.SequenceEqual(b3));

                (b3, b2) = proxy.OpTaggedByteSeq(null);
                TestHelper.Assert(b2 == null && b3 == null);
            }

            {
                var b1 = new ByteEnum[12]
                {
                    ByteEnum.benum1,
                    ByteEnum.benum2,
                    ByteEnum.benum3,
                    ByteEnum.benum4,
                    ByteEnum.benum5,
                    ByteEnum.benum6,
                    ByteEnum.benum7,
                    ByteEnum.benum8,
                    (ByteEnum)42,
                    ByteEnum.benum9,
                    ByteEnum.benum10,
                    ByteEnum.benum11
                };

                try
                {
                    _ = proxy.OpTaggedByteSeq(b1);
                    TestHelper.Assert(false);
                }
                catch (UnhandledException)
                {
                    // expected
                }
            }

            {
                var b1 = new FLByteEnum[11]
                {
                    FLByteEnum.benum1,
                    FLByteEnum.benum2,
                    FLByteEnum.benum3,
                    FLByteEnum.benum4,
                    FLByteEnum.benum5,
                    FLByteEnum.benum6,
                    FLByteEnum.benum7,
                    FLByteEnum.benum8,
                    FLByteEnum.benum9,
                    FLByteEnum.benum10,
                    FLByteEnum.benum11
                };

                (FLByteEnum[]? b3, FLByteEnum[]? b2) = proxy.OpTaggedFLByteSeq(b1);
                TestHelper.Assert(b2 != null && b3 != null);

                TestHelper.Assert(b1.SequenceEqual(b2));
                TestHelper.Assert(b1.SequenceEqual(b3));

                (b3, b2) = proxy.OpTaggedFLByteSeq(null);
                TestHelper.Assert(b2 == null && b3 == null);
            }

            {
                var i1 = new FLIntEnum[11]
                {
                    FLIntEnum.ienum1,
                    FLIntEnum.ienum2,
                    FLIntEnum.ienum3,
                    FLIntEnum.ienum4,
                    FLIntEnum.ienum5,
                    FLIntEnum.ienum6,
                    FLIntEnum.ienum7,
                    FLIntEnum.ienum8,
                    FLIntEnum.ienum9,
                    FLIntEnum.ienum10,
                    FLIntEnum.ienum11
                };

                (FLIntEnum[]? i3, FLIntEnum[]? i2) = proxy.OpTaggedFLIntSeq(i1);
                TestHelper.Assert(i2 != null && i3 != null);

                TestHelper.Assert(i1.SequenceEqual(i2));
                TestHelper.Assert(i1.SequenceEqual(i3));

                (i3, i2) = proxy.OpTaggedFLIntSeq(null);
                TestHelper.Assert(i2 == null && i3 == null);
            }

            output.WriteLine("ok");

            output.Write("testing unchecked enums... ");
            output.Flush();
            {
                (MyFlags r, MyFlags f2) = proxy.OpMyFlags(MyFlags.E31);
                TestHelper.Assert(r == MyFlags.E31 && f2 == r);
                (r, f2) = proxy.OpMyFlags(MyFlags.E10 | MyFlags.E11);
                TestHelper.Assert(r == (MyFlags.E10 | MyFlags.E11) && f2 == r);
            }

            output.Flush();
            {
                (MyFlags? r, MyFlags? f2) = proxy.OpTaggedMyFlags(null);
                TestHelper.Assert(r == null && f2 == r);
                (r, f2) = proxy.OpTaggedMyFlags(MyFlags.E10 | MyFlags.E11);
                TestHelper.Assert(r == (MyFlags.E10 | MyFlags.E11) && f2 == r);
            }

            output.Flush();
            {
                var myFlagsSeq = new MyFlags[] { MyFlags.E10, MyFlags.E0, MyFlags.E5 | MyFlags.E6 };
                (MyFlags[] r, MyFlags[] f2) = proxy.OpMyFlagsSeq(myFlagsSeq);
                TestHelper.Assert(r.SequenceEqual(myFlagsSeq) && f2.SequenceEqual(myFlagsSeq));
            }

            output.Flush();
            {
                var myFlagsSeq = new MyFlags[] { MyFlags.E10, MyFlags.E0, MyFlags.E5 | MyFlags.E6 };
                (MyFlags[]? r, MyFlags[]? f2) = proxy.OpTaggedMyFlagsSeq(myFlagsSeq);
                TestHelper.Assert(r !.SequenceEqual(myFlagsSeq) && f2 !.SequenceEqual(myFlagsSeq));
            }

            output.WriteLine("ok");
            return(proxy);
        }