예제 #1
0
 ice_invoke(byte[] inParams, out byte[] outParams, Ice.Current current)
 {
     Ice.Communicator communicator = current.adapter.getCommunicator();
     Ice.InputStream  inS          = new Ice.InputStream(communicator, inParams);
     inS.startEncapsulation();
     Ice.OutputStream outS = new Ice.OutputStream(communicator);
     outS.startEncapsulation();
     if (current.operation.Equals("opOneway"))
     {
         outParams = new byte[0];
         return(true);
     }
     else if (current.operation.Equals("opString"))
     {
         string s = inS.readString();
         outS.writeString(s);
         outS.writeString(s);
         outS.endEncapsulation();
         outParams = outS.finished();
         return(true);
     }
     else if (current.operation.Equals("opException"))
     {
         Test.MyException ex = new Test.MyException();
         outS.writeException(ex);
         outS.endEncapsulation();
         outParams = outS.finished();
         return(false);
     }
     else if (current.operation.Equals("shutdown"))
     {
         communicator.shutdown();
         outParams = null;
         return(true);
     }
     else if (current.operation.Equals("ice_isA"))
     {
         string s = inS.readString();
         if (s.Equals("::Test::MyClass"))
         {
             outS.writeBool(true);
         }
         else
         {
             outS.writeBool(false);
         }
         outS.endEncapsulation();
         outParams = outS.finished();
         return(true);
     }
     else
     {
         Ice.OperationNotExistException ex = new Ice.OperationNotExistException();
         ex.id        = current.id;
         ex.facet     = current.facet;
         ex.operation = current.operation;
         throw ex;
     }
 }
예제 #2
0
 ice_invoke_async(Ice.AMD_Object_ice_invoke cb, byte[] inParams, Ice.Current current)
 {
     Ice.Communicator communicator = current.adapter.getCommunicator();
     Ice.InputStream  inS          = Ice.Util.createInputStream(communicator, inParams);
     inS.startEncapsulation();
     Ice.OutputStream outS = Ice.Util.createOutputStream(communicator);
     outS.startEncapsulation();
     if (current.operation.Equals("opOneway"))
     {
         cb.ice_response(true, new byte[0]);
     }
     else if (current.operation.Equals("opString"))
     {
         string s = inS.readString();
         outS.writeString(s);
         outS.writeString(s);
         outS.endEncapsulation();
         cb.ice_response(true, outS.finished());
     }
     else if (current.operation.Equals("opException"))
     {
         Test.MyException ex = new Test.MyException();
         outS.writeException(ex);
         outS.endEncapsulation();
         cb.ice_response(false, outS.finished());
     }
     else if (current.operation.Equals("shutdown"))
     {
         communicator.shutdown();
         cb.ice_response(true, null);
     }
     else if (current.operation.Equals("ice_isA"))
     {
         string s = inS.readString();
         if (s.Equals("::Test::MyClass"))
         {
             outS.writeBool(true);
         }
         else
         {
             outS.writeBool(false);
         }
         outS.endEncapsulation();
         cb.ice_response(true, outS.finished());
     }
     else
     {
         Ice.OperationNotExistException ex = new Ice.OperationNotExistException();
         ex.id        = current.id;
         ex.facet     = current.facet;
         ex.operation = current.operation;
         throw ex;
     }
 }
예제 #3
0
 public override Task<Ice.Object_Ice_invokeResult> ice_invokeAsync(byte[] inParams, Ice.Current current)
 {
     Ice.Communicator communicator = current.adapter.getCommunicator();
     Ice.InputStream inS = new Ice.InputStream(communicator, inParams);
     inS.startEncapsulation();
     Ice.OutputStream outS = new Ice.OutputStream(communicator);
     outS.startEncapsulation();
     if(current.operation.Equals("opOneway"))
     {
         return Task.FromResult<Ice.Object_Ice_invokeResult>(new Ice.Object_Ice_invokeResult(true, new byte[0]));
     }
     else if(current.operation.Equals("opString"))
     {
         string s = inS.readString();
         outS.writeString(s);
         outS.writeString(s);
         outS.endEncapsulation();
         return Task.FromResult<Ice.Object_Ice_invokeResult>(new Ice.Object_Ice_invokeResult(true, outS.finished()));
     }
     else if(current.operation.Equals("opException"))
     {
         Test.MyException ex = new Test.MyException();
         outS.writeException(ex);
         outS.endEncapsulation();
         return Task.FromResult<Ice.Object_Ice_invokeResult>(new Ice.Object_Ice_invokeResult(false, outS.finished()));
     }
     else if(current.operation.Equals("shutdown"))
     {
         communicator.shutdown();
         return Task.FromResult<Ice.Object_Ice_invokeResult>(new Ice.Object_Ice_invokeResult(true, null));
     }
     else if(current.operation.Equals("ice_isA"))
     {
         string s = inS.readString();
         if(s.Equals("::Test::MyClass"))
         {
             outS.writeBool(true);
         }
         else
         {
             outS.writeBool(false);
         }
         outS.endEncapsulation();
         return Task.FromResult<Ice.Object_Ice_invokeResult>(new Ice.Object_Ice_invokeResult(true, outS.finished()));
     }
     else
     {
         Ice.OperationNotExistException ex = new Ice.OperationNotExistException();
         ex.id = current.id;
         ex.facet = current.facet;
         ex.operation = current.operation;
         throw ex;
     }
 }
 public override bool ice_invoke(byte[] inParams, out byte[] outParams, Ice.Current current)
 {
     Ice.Communicator communicator = current.adapter.getCommunicator();
     Ice.OutputStream @out = new Ice.OutputStream(communicator);
     @out.startEncapsulation(current.encoding, Ice.FormatType.DefaultFormat);
     AlsoEmpty ae = new AlsoEmpty();
     @out.writeObject(ae);
     @out.writePendingObjects();
     @out.endEncapsulation();
     outParams = @out.finished();
     return true;
 }
예제 #5
0
            public override bool ice_invoke(byte[] inParams, out byte[] outParams, Ice.Current current)
            {
                var communicator = current.adapter.GetCommunicator();
                var @out         = new Ice.OutputStream(communicator);

                @out.startEncapsulation(current.encoding, FormatType.DefaultFormat);
                var ae = new Test.AlsoEmpty();

                @out.writeValue(ae);
                @out.writePendingValues();
                @out.endEncapsulation();
                outParams = @out.finished();
                return(true);
            }
예제 #6
0
파일: AllTests.cs 프로젝트: Crysty-Yui/ice
    public static TestIntfPrx allTests(Ice.Communicator communicator)
#endif
    {
        string sref = "test:default -p 12010";
        Ice.ObjectPrx obj = communicator.stringToProxy(sref);
        test(obj != null);
        TestIntfPrx proxy = TestIntfPrxHelper.uncheckedCast(obj);
        test(proxy != null);

        Console.Out.Write("testing enum values... ");
        Console.Out.Flush();

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

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

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

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

        Console.Out.WriteLine("ok");

        Console.Out.Write("testing enum streaming... ");
        Console.Out.Flush();

        Ice.OutputStream ostr;
        byte[] bytes;

        bool encoding_1_0 = communicator.getProperties().getProperty("Ice.Default.EncodingVersion").Equals("1.0");

        ostr = new Ice.OutputStream(communicator);
        ostr.writeEnum((int)ByteEnum.benum11, (int)ByteEnum.benum11);
        bytes = ostr.finished();
        test(bytes.Length == 1); // ByteEnum should require one byte

        ostr = new Ice.OutputStream(communicator);
        ostr.writeEnum((int)ShortEnum.senum11, (int)ShortEnum.senum11);
        bytes = ostr.finished();
        test(bytes.Length == (encoding_1_0 ? 2 : 5));

        ostr = new Ice.OutputStream(communicator);
        ostr.writeEnum((int)IntEnum.ienum11, (int)IntEnum.ienum12);
        bytes = ostr.finished();
        test(bytes.Length == (encoding_1_0 ? 4 : 5));

        ostr = new Ice.OutputStream(communicator);
        ostr.writeEnum((int)SimpleEnum.blue, (int)SimpleEnum.blue);
        bytes = ostr.finished();
        test(bytes.Length == 1); // SimpleEnum should require one byte

        Console.Out.WriteLine("ok");

        Console.Out.Write("testing enum operations... ");
        Console.Out.Flush();

        ByteEnum byteEnum;
        test(proxy.opByte(ByteEnum.benum1, out byteEnum) == ByteEnum.benum1);
        test(byteEnum == ByteEnum.benum1);
        test(proxy.opByte(ByteEnum.benum11, out byteEnum) == ByteEnum.benum11);
        test(byteEnum == ByteEnum.benum11);

        ShortEnum shortEnum;
        test(proxy.opShort(ShortEnum.senum1, out shortEnum) == ShortEnum.senum1);
        test(shortEnum == ShortEnum.senum1);
        test(proxy.opShort(ShortEnum.senum11, out shortEnum) == ShortEnum.senum11);
        test(shortEnum == ShortEnum.senum11);

        IntEnum intEnum;
        test(proxy.opInt(IntEnum.ienum1, out intEnum) == IntEnum.ienum1);
        test(intEnum == IntEnum.ienum1);
        test(proxy.opInt(IntEnum.ienum11, out intEnum) == IntEnum.ienum11);
        test(intEnum == IntEnum.ienum11);
        test(proxy.opInt(IntEnum.ienum12, out intEnum) == IntEnum.ienum12);
        test(intEnum == IntEnum.ienum12);

        SimpleEnum s;
        test(proxy.opSimple(SimpleEnum.green, out s) == SimpleEnum.green);
        test(s == SimpleEnum.green);

        Console.Out.WriteLine("ok");

        Console.Out.Write("testing enum sequences operations... ");
        Console.Out.Flush();

        {
            ByteEnum[] 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[] b2;
            ByteEnum[] b3 = proxy.opByteSeq(b1, out b2);

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

        {
            ShortEnum[] 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[] s2;
            ShortEnum[] s3 = proxy.opShortSeq(s1, out s2);

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

        {
            IntEnum[] 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[] i2;
            IntEnum[] i3 = proxy.opIntSeq(i1, out i2);

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

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

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

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

        Console.Out.WriteLine("ok");
#if SILVERLIGHT
        proxy.shutdown();
#else
        return proxy;
#endif
    }
예제 #7
0
파일: AllTests.cs 프로젝트: motuii/ice
            public static Test.TestIntfPrx allTests(global::Test.TestHelper helper)
            {
                Ice.Communicator communicator = helper.communicator();
                string           sref         = "test:" + helper.getTestEndpoint(0);
                var obj = IObjectPrx.Parse(sref, communicator);

                test(obj != null);
                var proxy = Test.TestIntfPrx.UncheckedCast(obj);

                test(proxy != null);

                var output = helper.getWriter();

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

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

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

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

                test((int)Test.SimpleEnum.red == 0);
                test((int)Test.SimpleEnum.green == 1);
                test((int)Test.SimpleEnum.blue == 2);

                output.WriteLine("ok");

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

                Ice.OutputStream ostr;
                byte[]           bytes;

                bool encoding_1_0 = communicator.getProperties().getProperty("Ice.Default.EncodingVersion").Equals("1.0");

                ostr = new Ice.OutputStream(communicator);
                ostr.writeEnum((int)Test.ByteEnum.benum11, (int)Test.ByteEnum.benum11);
                bytes = ostr.finished();
                test(bytes.Length == 1); // ByteEnum should require one byte

                ostr = new Ice.OutputStream(communicator);
                ostr.writeEnum((int)Test.ShortEnum.senum11, (int)Test.ShortEnum.senum11);
                bytes = ostr.finished();
                test(bytes.Length == (encoding_1_0 ? 2 : 5));

                ostr = new Ice.OutputStream(communicator);
                ostr.writeEnum((int)Test.IntEnum.ienum11, (int)Test.IntEnum.ienum12);
                bytes = ostr.finished();
                test(bytes.Length == (encoding_1_0 ? 4 : 5));

                ostr = new Ice.OutputStream(communicator);
                ostr.writeEnum((int)Test.SimpleEnum.blue, (int)Test.SimpleEnum.blue);
                bytes = ostr.finished();
                test(bytes.Length == 1); // SimpleEnum should require one byte

                output.WriteLine("ok");

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

                Test.ByteEnum byteEnum;
                test(proxy.opByte(Test.ByteEnum.benum1, out byteEnum) == Test.ByteEnum.benum1);
                test(byteEnum == Test.ByteEnum.benum1);
                test(proxy.opByte(Test.ByteEnum.benum11, out byteEnum) == Test.ByteEnum.benum11);
                test(byteEnum == Test.ByteEnum.benum11);

                Test.ShortEnum shortEnum;
                test(proxy.opShort(Test.ShortEnum.senum1, out shortEnum) == Test.ShortEnum.senum1);
                test(shortEnum == Test.ShortEnum.senum1);
                test(proxy.opShort(Test.ShortEnum.senum11, out shortEnum) == Test.ShortEnum.senum11);
                test(shortEnum == Test.ShortEnum.senum11);

                Test.IntEnum intEnum;
                test(proxy.opInt(Test.IntEnum.ienum1, out intEnum) == Test.IntEnum.ienum1);
                test(intEnum == Test.IntEnum.ienum1);
                test(proxy.opInt(Test.IntEnum.ienum11, out intEnum) == Test.IntEnum.ienum11);
                test(intEnum == Test.IntEnum.ienum11);
                test(proxy.opInt(Test.IntEnum.ienum12, out intEnum) == Test.IntEnum.ienum12);
                test(intEnum == Test.IntEnum.ienum12);

                Test.SimpleEnum s;
                test(proxy.opSimple(Test.SimpleEnum.green, out s) == Test.SimpleEnum.green);
                test(s == Test.SimpleEnum.green);

                output.WriteLine("ok");

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

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

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

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

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

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

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

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

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

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

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

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

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

                output.WriteLine("ok");
                return(proxy);
            }
예제 #8
0
            static public int allTests(global::Test.TestHelper helper)
            {
                var communicator = helper.communicator();

                Ice.InputStream  inS;
                Ice.OutputStream outS;

                var output = helper.getWriter();

                output.Write("testing primitive types... ");
                output.Flush();

                {
                    byte[] data = new byte[0];
                    inS = new Ice.InputStream(communicator, data);
                }

                {
                    outS = new Ice.OutputStream(communicator);
                    outS.startEncapsulation();
                    outS.writeBool(true);
                    outS.endEncapsulation();
                    var data = outS.finished();

                    inS = new Ice.InputStream(communicator, data);
                    inS.startEncapsulation();
                    test(inS.readBool());
                    inS.endEncapsulation();

                    inS = new Ice.InputStream(communicator, data);
                    inS.startEncapsulation();
                    test(inS.readBool());
                    inS.endEncapsulation();
                }

                {
                    var data = new byte[0];
                    inS = new Ice.InputStream(communicator, data);
                    try
                    {
                        inS.readBool();
                        test(false);
                    }
                    catch (Ice.UnmarshalOutOfBoundsException)
                    {
                    }
                }

                {
                    outS = new Ice.OutputStream(communicator);
                    outS.writeBool(true);
                    var data = outS.finished();
                    inS = new Ice.InputStream(communicator, data);
                    test(inS.readBool());
                }

                {
                    outS = new Ice.OutputStream(communicator);
                    outS.writeByte(1);
                    var data = outS.finished();
                    inS = new Ice.InputStream(communicator, data);
                    test(inS.readByte() == 1);
                }

                {
                    outS = new Ice.OutputStream(communicator);
                    outS.writeShort(2);
                    var data = outS.finished();
                    inS = new Ice.InputStream(communicator, data);
                    test(inS.readShort() == 2);
                }

                {
                    outS = new Ice.OutputStream(communicator);
                    outS.writeInt(3);
                    var data = outS.finished();
                    inS = new Ice.InputStream(communicator, data);
                    test(inS.readInt() == 3);
                }

                {
                    outS = new Ice.OutputStream(communicator);
                    outS.writeLong(4);
                    var data = outS.finished();
                    inS = new Ice.InputStream(communicator, data);
                    test(inS.readLong() == 4);
                }

                {
                    outS = new Ice.OutputStream(communicator);
                    outS.writeFloat((float)5.0);
                    var data = outS.finished();
                    inS = new Ice.InputStream(communicator, data);
                    test(inS.readFloat() == (float)5.0);
                }

                {
                    outS = new Ice.OutputStream(communicator);
                    outS.writeDouble(6.0);
                    var data = outS.finished();
                    inS = new Ice.InputStream(communicator, data);
                    test(inS.readDouble() == 6.0);
                }

                {
                    outS = new Ice.OutputStream(communicator);
                    outS.writeString("hello world");
                    var data = outS.finished();
                    inS = new Ice.InputStream(communicator, data);
                    test(inS.readString().Equals("hello world"));
                }

                output.WriteLine("ok");

                output.Write("testing constructed types... ");
                output.Flush();

                {
                    outS = new Ice.OutputStream(communicator);
                    Test.MyEnumHelper.write(outS, Test.MyEnum.enum3);
                    var data = outS.finished();
                    inS = new Ice.InputStream(communicator, data);
                    var e = Test.MyEnumHelper.read(inS);
                    test(e == Test.MyEnum.enum3);
                }

                {
                    outS = new Ice.OutputStream(communicator);
                    var s = new Test.SmallStruct();
                    s.bo  = true;
                    s.by  = 1;
                    s.sh  = 2;
                    s.i   = 3;
                    s.l   = 4;
                    s.f   = 5.0f;
                    s.d   = 6.0;
                    s.str = "7";
                    s.e   = Test.MyEnum.enum2;
                    s.p   = Test.MyInterfacePrx.Parse("test:default", communicator);
                    Test.SmallStruct.ice_write(outS, s);
                    var data = outS.finished();
                    var s2   = Test.SmallStruct.ice_read(new Ice.InputStream(communicator, data));
                    test(s2.Equals(s));
                }

                {
                    outS = new Ice.OutputStream(communicator);
                    var o = new Test.OptionalClass();
                    o.bo = true;
                    o.by = 5;
                    o.sh = 4;
                    o.i  = 3;
                    outS.writeValue(o);
                    outS.writePendingValues();
                    var data = outS.finished();
                    inS = new Ice.InputStream(communicator, data);
                    TestReadValueCallback cb = new TestReadValueCallback();
                    inS.readValue(cb.invoke);
                    inS.readPendingValues();
                    var o2 = (Test.OptionalClass)cb.obj;
                    test(o2.bo == o.bo);
                    test(o2.by == o.by);
                    if (communicator.getProperties().getProperty("Ice.Default.EncodingVersion").Equals("1.0"))
                    {
                        test(!o2.sh.HasValue);
                        test(!o2.i.HasValue);
                    }
                    else
                    {
                        test(o2.sh.Value == o.sh.Value);
                        test(o2.i.Value == o.i.Value);
                    }
                }

                {
                    outS = new Ice.OutputStream(communicator, Ice.Util.Encoding_1_0);
                    var o = new Test.OptionalClass();
                    o.bo = true;
                    o.by = 5;
                    o.sh = 4;
                    o.i  = 3;
                    outS.writeValue(o);
                    outS.writePendingValues();
                    byte[] data = outS.finished();
                    inS = new Ice.InputStream(communicator, Ice.Util.Encoding_1_0, data);
                    var cb = new TestReadValueCallback();
                    inS.readValue(cb.invoke);
                    inS.readPendingValues();
                    var o2 = (Test.OptionalClass)cb.obj;
                    test(o2.bo == o.bo);
                    test(o2.by == o.by);
                    test(!o2.sh.HasValue);
                    test(!o2.i.HasValue);
                }

                {
                    bool[] arr = { true, false, true, false };
                    outS = new Ice.OutputStream(communicator);
                    Ice.BoolSeqHelper.write(outS, arr);
                    var data = outS.finished();
                    inS = new Ice.InputStream(communicator, data);
                    var arr2 = Ice.BoolSeqHelper.read(inS);
                    test(Compare(arr2, arr));

                    bool[][] arrS = { arr, new bool[0], arr };
                    outS = new Ice.OutputStream(communicator);
                    Test.BoolSSHelper.write(outS, arrS);
                    data = outS.finished();
                    inS  = new Ice.InputStream(communicator, data);
                    var arr2S = Test.BoolSSHelper.read(inS);
                    test(Compare(arr2S, arrS));
                }

                {
                    byte[] arr = { 0x01, 0x11, 0x12, 0x22 };
                    outS = new Ice.OutputStream(communicator);
                    Ice.ByteSeqHelper.write(outS, arr);
                    var data = outS.finished();
                    inS = new Ice.InputStream(communicator, data);
                    var arr2 = Ice.ByteSeqHelper.read(inS);
                    test(Compare(arr2, arr));

                    byte[][] arrS = { arr, new byte[0], arr };
                    outS = new Ice.OutputStream(communicator);
                    Test.ByteSSHelper.write(outS, arrS);
                    data = outS.finished();
                    inS  = new Ice.InputStream(communicator, data);
                    var arr2S = Test.ByteSSHelper.read(inS);
                    test(Compare(arr2S, arrS));
                }

                {
                    Serialize.Small small = new Serialize.Small();
                    small.i = 99;
                    outS    = new Ice.OutputStream(communicator);
                    outS.writeSerializable(small);
                    var data = outS.finished();
                    inS = new Ice.InputStream(communicator, data);
                    var small2 = (Serialize.Small)inS.readSerializable();
                    test(small2.i == 99);
                }

                {
                    short[] arr = { 0x01, 0x11, 0x12, 0x22 };
                    outS = new Ice.OutputStream(communicator);
                    Ice.ShortSeqHelper.write(outS, arr);
                    var data = outS.finished();
                    inS = new Ice.InputStream(communicator, data);
                    var arr2 = Ice.ShortSeqHelper.read(inS);
                    test(Compare(arr2, arr));

                    short[][] arrS = { arr, new short[0], arr };
                    outS = new Ice.OutputStream(communicator);
                    Test.ShortSSHelper.write(outS, arrS);
                    data = outS.finished();
                    inS  = new Ice.InputStream(communicator, data);
                    var arr2S = Test.ShortSSHelper.read(inS);
                    test(Compare(arr2S, arrS));
                }

                {
                    int[] arr = { 0x01, 0x11, 0x12, 0x22 };
                    outS = new Ice.OutputStream(communicator);
                    Ice.IntSeqHelper.write(outS, arr);
                    var data = outS.finished();
                    inS = new Ice.InputStream(communicator, data);
                    var arr2 = Ice.IntSeqHelper.read(inS);
                    test(Compare(arr2, arr));

                    int[][] arrS = { arr, new int[0], arr };
                    outS = new Ice.OutputStream(communicator);
                    Test.IntSSHelper.write(outS, arrS);
                    data = outS.finished();
                    inS  = new Ice.InputStream(communicator, data);
                    var arr2S = Test.IntSSHelper.read(inS);
                    test(Compare(arr2S, arrS));
                }

                {
                    long[] arr = { 0x01, 0x11, 0x12, 0x22 };
                    outS = new Ice.OutputStream(communicator);
                    Ice.LongSeqHelper.write(outS, arr);
                    var data = outS.finished();
                    inS = new Ice.InputStream(communicator, data);
                    var arr2 = Ice.LongSeqHelper.read(inS);
                    test(Compare(arr2, arr));

                    long[][] arrS = { arr, new long[0], arr };
                    outS = new Ice.OutputStream(communicator);
                    Test.LongSSHelper.write(outS, arrS);
                    data = outS.finished();
                    inS  = new Ice.InputStream(communicator, data);
                    var arr2S = Test.LongSSHelper.read(inS);
                    test(Compare(arr2S, arrS));
                }

                {
                    float[] arr = { 1, 2, 3, 4 };
                    outS = new Ice.OutputStream(communicator);
                    Ice.FloatSeqHelper.write(outS, arr);
                    byte[] data = outS.finished();
                    inS = new Ice.InputStream(communicator, data);
                    float[] arr2 = Ice.FloatSeqHelper.read(inS);
                    test(Compare(arr2, arr));

                    float[][] arrS = { arr, new float[0], arr };
                    outS = new Ice.OutputStream(communicator);
                    Test.FloatSSHelper.write(outS, arrS);
                    data = outS.finished();
                    inS  = new Ice.InputStream(communicator, data);
                    var arr2S = Test.FloatSSHelper.read(inS);
                    test(Compare(arr2S, arrS));
                }

                {
                    double[] arr =
                    {
                        1,
                        2,
                        3,
                        4
                    };
                    outS = new Ice.OutputStream(communicator);
                    Ice.DoubleSeqHelper.write(outS, arr);
                    var data = outS.finished();
                    inS = new Ice.InputStream(communicator, data);
                    var arr2 = Ice.DoubleSeqHelper.read(inS);
                    test(Compare(arr2, arr));

                    double[][] arrS = { arr, new double[0], arr };
                    outS = new Ice.OutputStream(communicator);
                    Test.DoubleSSHelper.write(outS, arrS);
                    data = outS.finished();
                    inS  = new Ice.InputStream(communicator, data);
                    var arr2S = Test.DoubleSSHelper.read(inS);
                    test(Compare(arr2S, arrS));
                }

                {
                    string[] arr = { "string1", "string2", "string3", "string4" };
                    outS = new Ice.OutputStream(communicator);
                    Ice.StringSeqHelper.write(outS, arr);
                    var data = outS.finished();
                    inS = new Ice.InputStream(communicator, data);
                    var arr2 = Ice.StringSeqHelper.read(inS);
                    test(Compare(arr2, arr));

                    string[][] arrS = { arr, new string[0], arr };
                    outS = new Ice.OutputStream(communicator);
                    Test.StringSSHelper.write(outS, arrS);
                    data = outS.finished();
                    inS  = new Ice.InputStream(communicator, data);
                    var arr2S = Test.StringSSHelper.read(inS);
                    test(Compare(arr2S, arrS));
                }

                {
                    Test.MyEnum[] arr =
                    {
                        Test.MyEnum.enum3,
                        Test.MyEnum.enum2,
                        Test.MyEnum.enum1,
                        Test.MyEnum.enum2
                    };
                    outS = new Ice.OutputStream(communicator);
                    Test.MyEnumSHelper.write(outS, arr);
                    var data = outS.finished();
                    inS = new Ice.InputStream(communicator, data);
                    var arr2 = Test.MyEnumSHelper.read(inS);
                    test(Compare(arr2, arr));

                    Test.MyEnum[][] arrS = { arr, new Test.MyEnum[0], arr };
                    outS = new Ice.OutputStream(communicator);
                    Test.MyEnumSSHelper.write(outS, arrS);
                    data = outS.finished();
                    inS  = new Ice.InputStream(communicator, data);
                    var arr2S = Test.MyEnumSSHelper.read(inS);
                    test(Compare(arr2S, arrS));
                }

                var smallStructArray = new Test.SmallStruct[3];

                for (int i = 0; i < smallStructArray.Length; ++i)
                {
                    smallStructArray[i]     = new Test.SmallStruct();
                    smallStructArray[i].bo  = true;
                    smallStructArray[i].by  = 1;
                    smallStructArray[i].sh  = 2;
                    smallStructArray[i].i   = 3;
                    smallStructArray[i].l   = 4;
                    smallStructArray[i].f   = 5.0f;
                    smallStructArray[i].d   = 6.0;
                    smallStructArray[i].str = "7";
                    smallStructArray[i].e   = Test.MyEnum.enum2;
                    smallStructArray[i].p   = Test.MyInterfacePrx.Parse("test:default", communicator);
                }

                var myClassArray = new Test.MyClass[4];

                for (int i = 0; i < myClassArray.Length; ++i)
                {
                    myClassArray[i]         = new Test.MyClass();
                    myClassArray[i].c       = myClassArray[i];
                    myClassArray[i].o       = myClassArray[i];
                    myClassArray[i].s       = new Test.SmallStruct();
                    myClassArray[i].s.e     = Test.MyEnum.enum2;
                    myClassArray[i].seq1    = new bool[] { true, false, true, false };
                    myClassArray[i].seq2    = new byte[] { 1, 2, 3, 4 };
                    myClassArray[i].seq3    = new short[] { 1, 2, 3, 4 };
                    myClassArray[i].seq4    = new int[] { 1, 2, 3, 4 };
                    myClassArray[i].seq5    = new long[] { 1, 2, 3, 4 };
                    myClassArray[i].seq6    = new float[] { 1, 2, 3, 4 };
                    myClassArray[i].seq7    = new double[] { 1, 2, 3, 4 };
                    myClassArray[i].seq8    = new string[] { "string1", "string2", "string3", "string4" };
                    myClassArray[i].seq9    = new Test.MyEnum[] { Test.MyEnum.enum3, Test.MyEnum.enum2, Test.MyEnum.enum1 };
                    myClassArray[i].seq10   = new Test.MyClass[4]; // null elements.
                    myClassArray[i].d       = new Dictionary <string, Test.MyClass>();
                    myClassArray[i].d["hi"] = myClassArray[i];
                }

                {
                    outS = new Ice.OutputStream(communicator);
                    Test.MyClassSHelper.write(outS, myClassArray);
                    outS.writePendingValues();
                    var data = outS.finished();
                    inS = new Ice.InputStream(communicator, data);
                    var arr2 = Test.MyClassSHelper.read(inS);
                    inS.readPendingValues();
                    test(arr2.Length == myClassArray.Length);
                    for (int i = 0; i < arr2.Length; ++i)
                    {
                        test(arr2[i] != null);
                        test(arr2[i].c == arr2[i]);
                        test(arr2[i].o == arr2[i]);
                        test(arr2[i].s.e == Test.MyEnum.enum2);
                        test(Compare(arr2[i].seq1, myClassArray[i].seq1));
                        test(Compare(arr2[i].seq2, myClassArray[i].seq2));
                        test(Compare(arr2[i].seq3, myClassArray[i].seq3));
                        test(Compare(arr2[i].seq4, myClassArray[i].seq4));
                        test(Compare(arr2[i].seq5, myClassArray[i].seq5));
                        test(Compare(arr2[i].seq6, myClassArray[i].seq6));
                        test(Compare(arr2[i].seq7, myClassArray[i].seq7));
                        test(Compare(arr2[i].seq8, myClassArray[i].seq8));
                        test(Compare(arr2[i].seq9, myClassArray[i].seq9));
                        test(arr2[i].d["hi"].Equals(arr2[i]));
                    }

                    Test.MyClass[][] arrS = { myClassArray, new Test.MyClass[0], myClassArray };
                    outS = new Ice.OutputStream(communicator);
                    Test.MyClassSSHelper.write(outS, arrS);
                    outS.writePendingValues();
                    data = outS.finished();
                    inS  = new Ice.InputStream(communicator, data);
                    var arr2S = Test.MyClassSSHelper.read(inS);
                    inS.readPendingValues();
                    test(arr2S.Length == arrS.Length);
                    test(arr2S[0].Length == arrS[0].Length);
                    test(arr2S[1].Length == arrS[1].Length);
                    test(arr2S[2].Length == arrS[2].Length);

                    for (int j = 0; j < arr2S.Length; ++j)
                    {
                        for (int k = 0; k < arr2S[j].Length; ++k)
                        {
                            test(arr2S[j][k].c == arr2S[j][k]);
                            test(arr2S[j][k].o == arr2S[j][k]);
                            test(arr2S[j][k].s.e == Test.MyEnum.enum2);
                            test(Compare(arr2S[j][k].seq1, myClassArray[k].seq1));
                            test(Compare(arr2S[j][k].seq2, myClassArray[k].seq2));
                            test(Compare(arr2S[j][k].seq3, myClassArray[k].seq3));
                            test(Compare(arr2S[j][k].seq4, myClassArray[k].seq4));
                            test(Compare(arr2S[j][k].seq5, myClassArray[k].seq5));
                            test(Compare(arr2S[j][k].seq6, myClassArray[k].seq6));
                            test(Compare(arr2S[j][k].seq7, myClassArray[k].seq7));
                            test(Compare(arr2S[j][k].seq8, myClassArray[k].seq8));
                            test(Compare(arr2S[j][k].seq9, myClassArray[k].seq9));
                            test(arr2S[j][k].d["hi"].Equals(arr2S[j][k]));
                        }
                    }
                }

                {
                    outS = new Ice.OutputStream(communicator);
                    var obj = new Test.MyClass();
                    obj.s   = new Test.SmallStruct();
                    obj.s.e = Test.MyEnum.enum2;
                    var writer = new TestValueWriter(obj);
                    outS.writeValue(writer);
                    outS.writePendingValues();
                    var data = outS.finished();
                    test(writer.called);
                    inS = new Ice.InputStream(communicator, data);
                    var cb = new TestReadValueCallback();
                    inS.readValue(cb.invoke);
                    inS.readPendingValues();
                    test(cb.obj != null);
                    test(cb.obj is Test.MyClass);
                    var robj = (Test.MyClass)cb.obj;
                    test(robj != null);
                    test(robj.s.e == Test.MyEnum.enum2);
                }

                {
                    outS = new Ice.OutputStream(communicator);
                    var ex = new Test.MyException();

                    var c = new Test.MyClass();
                    c.c     = c;
                    c.o     = c;
                    c.s     = new Test.SmallStruct();
                    c.s.e   = Test.MyEnum.enum2;
                    c.seq1  = new bool[] { true, false, true, false };
                    c.seq2  = new byte[] { 1, 2, 3, 4 };
                    c.seq3  = new short[] { 1, 2, 3, 4 };
                    c.seq4  = new int[] { 1, 2, 3, 4 };
                    c.seq5  = new long[] { 1, 2, 3, 4 };
                    c.seq6  = new float[] { 1, 2, 3, 4 };
                    c.seq7  = new double[] { 1, 2, 3, 4 };
                    c.seq8  = new string[] { "string1", "string2", "string3", "string4" };
                    c.seq9  = new Test.MyEnum[] { Test.MyEnum.enum3, Test.MyEnum.enum2, Test.MyEnum.enum1 };
                    c.seq10 = new Test.MyClass[4]; // null elements.
                    c.d     = new Dictionary <string, Test.MyClass>();
                    c.d.Add("hi", c);

                    ex.c = c;

                    outS.writeException(ex);
                    var data = outS.finished();

                    inS = new Ice.InputStream(communicator, data);
                    try
                    {
                        inS.throwException();
                        test(false);
                    }
                    catch (Test.MyException ex1)
                    {
                        test(ex1.c.s.e == c.s.e);
                        test(Compare(ex1.c.seq1, c.seq1));
                        test(Compare(ex1.c.seq2, c.seq2));
                        test(Compare(ex1.c.seq3, c.seq3));
                        test(Compare(ex1.c.seq4, c.seq4));
                        test(Compare(ex1.c.seq5, c.seq5));
                        test(Compare(ex1.c.seq6, c.seq6));
                        test(Compare(ex1.c.seq7, c.seq7));
                        test(Compare(ex1.c.seq8, c.seq8));
                        test(Compare(ex1.c.seq9, c.seq9));
                    }
                    catch (Ice.UserException)
                    {
                        test(false);
                    }
                }

                {
                    var dict = new Dictionary <byte, bool>();
                    dict.Add(4, true);
                    dict.Add(1, false);
                    outS = new Ice.OutputStream(communicator);
                    Test.ByteBoolDHelper.write(outS, dict);
                    var data = outS.finished();
                    inS = new Ice.InputStream(communicator, data);
                    var dict2 = Test.ByteBoolDHelper.read(inS);
                    test(Ice.CollectionComparer.Equals(dict2, dict));
                }

                {
                    var dict = new Dictionary <short, int>();
                    dict.Add(1, 9);
                    dict.Add(4, 8);
                    outS = new Ice.OutputStream(communicator);
                    Test.ShortIntDHelper.write(outS, dict);
                    var data = outS.finished();
                    inS = new Ice.InputStream(communicator, data);
                    var dict2 = Test.ShortIntDHelper.read(inS);
                    test(Ice.CollectionComparer.Equals(dict2, dict));
                }

                {
                    var dict = new Dictionary <long, float>();
                    dict.Add(123809828, 0.51f);
                    dict.Add(123809829, 0.56f);
                    outS = new Ice.OutputStream(communicator);
                    Test.LongFloatDHelper.write(outS, dict);
                    var data = outS.finished();
                    inS = new Ice.InputStream(communicator, data);
                    var dict2 = Test.LongFloatDHelper.read(inS);
                    test(Ice.CollectionComparer.Equals(dict2, dict));
                }

                {
                    var dict = new Dictionary <string, string>();
                    dict.Add("key1", "value1");
                    dict.Add("key2", "value2");
                    outS = new Ice.OutputStream(communicator);
                    Test.StringStringDHelper.write(outS, dict);
                    var data = outS.finished();
                    inS = new Ice.InputStream(communicator, data);
                    var dict2 = Test.StringStringDHelper.read(inS);
                    test(Ice.CollectionComparer.Equals(dict2, dict));
                }

                {
                    var dict = new Dictionary <string, Test.MyClass>();
                    var c    = new Test.MyClass();
                    c.s   = new Test.SmallStruct();
                    c.s.e = Test.MyEnum.enum2;
                    dict.Add("key1", c);
                    c     = new Test.MyClass();
                    c.s   = new Test.SmallStruct();
                    c.s.e = Test.MyEnum.enum3;
                    dict.Add("key2", c);
                    outS = new Ice.OutputStream(communicator);
                    Test.StringMyClassDHelper.write(outS, dict);
                    outS.writePendingValues();
                    var data = outS.finished();
                    inS = new Ice.InputStream(communicator, data);
                    var dict2 = Test.StringMyClassDHelper.read(inS);
                    inS.readPendingValues();
                    test(dict2.Count == dict.Count);
                    test(dict2["key1"].s.e == Test.MyEnum.enum2);
                    test(dict2["key2"].s.e == Test.MyEnum.enum3);
                }

                {
                    bool[] arr = { true, false, true, false };
                    outS = new Ice.OutputStream(communicator);
                    var l = new List <bool>(arr);
                    Test.BoolListHelper.write(outS, l);
                    var data = outS.finished();
                    inS = new Ice.InputStream(communicator, data);
                    var l2 = Test.BoolListHelper.read(inS);
                    test(Compare(l, l2));
                }

                {
                    byte[] arr = { 0x01, 0x11, 0x12, 0x22 };
                    outS = new Ice.OutputStream(communicator);
                    var l = new List <byte>(arr);
                    Test.ByteListHelper.write(outS, l);
                    var data = outS.finished();
                    inS = new Ice.InputStream(communicator, data);
                    var l2 = Test.ByteListHelper.read(inS);
                    test(Compare(l2, l));
                }

                {
                    Test.MyEnum[] arr = { Test.MyEnum.enum3, Test.MyEnum.enum2, Test.MyEnum.enum1, Test.MyEnum.enum2 };
                    outS = new Ice.OutputStream(communicator);
                    var l = new List <Test.MyEnum>(arr);
                    Test.MyEnumListHelper.write(outS, l);
                    var data = outS.finished();
                    inS = new Ice.InputStream(communicator, data);
                    var l2 = Test.MyEnumListHelper.read(inS);
                    test(Compare(l2, l));
                }

                {
                    outS = new Ice.OutputStream(communicator);
                    var l = new List <Test.SmallStruct>(smallStructArray);
                    Test.SmallStructListHelper.write(outS, l);
                    var data = outS.finished();
                    inS = new Ice.InputStream(communicator, data);
                    var l2 = Test.SmallStructListHelper.read(inS);
                    test(l2.Count == l.Count);
                    for (int i = 0; i < l2.Count; ++i)
                    {
                        test(l2[i].Equals(smallStructArray[i]));
                    }
                }

                {
                    outS = new Ice.OutputStream(communicator);
                    var l = new List <Test.MyClass>(myClassArray);
                    Test.MyClassListHelper.write(outS, l);
                    outS.writePendingValues();
                    var data = outS.finished();
                    inS = new Ice.InputStream(communicator, data);
                    var l2 = Test.MyClassListHelper.read(inS);
                    inS.readPendingValues();
                    test(l2.Count == l.Count);
                    for (int i = 0; i < l2.Count; ++i)
                    {
                        test(l2[i] != null);
                        test(l2[i].c == l2[i]);
                        test(l2[i].o == l2[i]);
                        test(l2[i].s.e == Test.MyEnum.enum2);
                        test(Compare(l2[i].seq1, l[i].seq1));
                        test(Compare(l2[i].seq2, l[i].seq2));
                        test(Compare(l2[i].seq3, l[i].seq3));
                        test(Compare(l2[i].seq4, l[i].seq4));
                        test(Compare(l2[i].seq5, l[i].seq5));
                        test(Compare(l2[i].seq6, l[i].seq6));
                        test(Compare(l2[i].seq7, l[i].seq7));
                        test(Compare(l2[i].seq8, l[i].seq8));
                        test(Compare(l2[i].seq9, l[i].seq9));
                        test(l2[i].d["hi"].Equals(l2[i]));
                    }
                }

                {
                    var arr = new IObjectPrx[2];
                    arr[0] = IObjectPrx.Parse("zero", communicator);
                    arr[1] = IObjectPrx.Parse("one", communicator);
                    outS   = new Ice.OutputStream(communicator);
                    var l = new List <Ice.IObjectPrx>(arr);
                    Test.MyClassProxyListHelper.write(outS, l);
                    byte[] data = outS.finished();
                    inS = new Ice.InputStream(communicator, data);
                    var l2 = Test.MyClassProxyListHelper.read(inS);
                    test(Compare(l2, l));
                }

                {
                    var arr = new Test.MyInterfacePrx[2];
                    arr[0] = Test.MyInterfacePrx.Parse("zero", communicator);
                    arr[1] = Test.MyInterfacePrx.Parse("one", communicator);
                    outS   = new Ice.OutputStream(communicator);
                    var l = new List <Test.MyInterfacePrx>(arr);
                    Test.MyInterfaceProxyListHelper.write(outS, l);
                    byte[] data = outS.finished();
                    inS = new Ice.InputStream(communicator, data);
                    var l2 = Test.MyInterfaceProxyListHelper.read(inS);
                    test(Compare(l2, l));
                }

                {
                    short[] arr = { 0x01, 0x11, 0x12, 0x22 };
                    outS = new Ice.OutputStream(communicator);
                    var l = new LinkedList <short>(arr);
                    Test.ShortLinkedListHelper.write(outS, l);
                    var data = outS.finished();
                    inS = new Ice.InputStream(communicator, data);
                    var l2 = Test.ShortLinkedListHelper.read(inS);
                    test(Compare(l2, l));
                }

                {
                    int[] arr = { 0x01, 0x11, 0x12, 0x22 };
                    outS = new Ice.OutputStream(communicator);
                    LinkedList <int> l = new LinkedList <int>(arr);
                    Test.IntLinkedListHelper.write(outS, l);
                    byte[] data = outS.finished();
                    inS = new Ice.InputStream(communicator, data);
                    LinkedList <int> l2 = Test.IntLinkedListHelper.read(inS);
                    test(Compare(l2, l));
                }

                {
                    Test.MyEnum[] arr = { Test.MyEnum.enum3, Test.MyEnum.enum2, Test.MyEnum.enum1, Test.MyEnum.enum2 };
                    outS = new Ice.OutputStream(communicator);
                    LinkedList <Test.MyEnum> l = new LinkedList <Test.MyEnum>(arr);
                    Test.MyEnumLinkedListHelper.write(outS, l);
                    byte[] data = outS.finished();
                    inS = new Ice.InputStream(communicator, data);
                    LinkedList <Test.MyEnum> l2 = Test.MyEnumLinkedListHelper.read(inS);
                    test(Compare(l2, l));
                }

                {
                    outS = new Ice.OutputStream(communicator);
                    var l = new LinkedList <Test.SmallStruct>(smallStructArray);
                    Test.SmallStructLinkedListHelper.write(outS, l);
                    var data = outS.finished();
                    inS = new Ice.InputStream(communicator, data);
                    var l2 = Test.SmallStructLinkedListHelper.read(inS);
                    test(l2.Count == l.Count);
                    var e  = l.GetEnumerator();
                    var e2 = l2.GetEnumerator();
                    while (e.MoveNext() && e2.MoveNext())
                    {
                        test(e.Current.Equals(e2.Current));
                    }
                }

                {
                    long[] arr = { 0x01, 0x11, 0x12, 0x22 };
                    outS = new Ice.OutputStream(communicator);
                    var l = new Stack <long>(arr);
                    Test.LongStackHelper.write(outS, l);
                    var data = outS.finished();
                    inS = new Ice.InputStream(communicator, data);
                    var l2 = Test.LongStackHelper.read(inS);
                    test(Compare(l2, l));
                }

                {
                    float[] arr = { 1, 2, 3, 4 };
                    outS = new Ice.OutputStream(communicator);
                    var l = new Stack <float>(arr);
                    Test.FloatStackHelper.write(outS, l);
                    byte[] data = outS.finished();
                    inS = new Ice.InputStream(communicator, data);
                    var l2 = Test.FloatStackHelper.read(inS);
                    test(Compare(l2, l));
                }

                {
                    outS = new Ice.OutputStream(communicator);
                    var l = new Stack <Test.SmallStruct>(smallStructArray);
                    Test.SmallStructStackHelper.write(outS, l);
                    byte[] data = outS.finished();
                    inS = new Ice.InputStream(communicator, data);
                    var l2 = Test.SmallStructStackHelper.read(inS);
                    test(l2.Count == l.Count);
                    var e  = l.GetEnumerator();
                    var e2 = l2.GetEnumerator();
                    while (e.MoveNext() && e2.MoveNext())
                    {
                        test(e.Current.Equals(e2.Current));
                    }
                }

                {
                    var arr = new IObjectPrx[2];
                    arr[0] = IObjectPrx.Parse("zero", communicator);
                    arr[1] = IObjectPrx.Parse("one", communicator);
                    outS   = new Ice.OutputStream(communicator);
                    var l = new Stack <Ice.IObjectPrx>(arr);
                    Test.MyClassProxyStackHelper.write(outS, l);
                    var data = outS.finished();
                    inS = new Ice.InputStream(communicator, data);
                    var l2 = Test.MyClassProxyStackHelper.read(inS);
                    test(Compare(l2, l));
                }

                {
                    var arr = new Test.MyInterfacePrx[2];
                    arr[0] = Test.MyInterfacePrx.Parse("zero", communicator);
                    arr[1] = Test.MyInterfacePrx.Parse("one", communicator);
                    outS   = new Ice.OutputStream(communicator);
                    var l = new Stack <Test.MyInterfacePrx>(arr);
                    Test.MyInterfaceProxyStackHelper.write(outS, l);
                    var data = outS.finished();
                    inS = new Ice.InputStream(communicator, data);
                    var l2 = Test.MyInterfaceProxyStackHelper.read(inS);
                    test(Compare(l2, l));
                }

                {
                    double[] arr = { 1, 2, 3, 4 };
                    outS = new Ice.OutputStream(communicator);
                    var l = new Queue <double>(arr);
                    Test.DoubleQueueHelper.write(outS, l);
                    var data = outS.finished();
                    inS = new Ice.InputStream(communicator, data);
                    var l2 = Test.DoubleQueueHelper.read(inS);
                    test(Compare(l2, l));
                }

                {
                    string[] arr = { "string1", "string2", "string3", "string4" };
                    outS = new Ice.OutputStream(communicator);
                    var l = new Queue <string>(arr);
                    Test.StringQueueHelper.write(outS, l);
                    var data = outS.finished();
                    inS = new Ice.InputStream(communicator, data);
                    var l2 = Test.StringQueueHelper.read(inS);
                    test(Compare(l2, l));
                }

                {
                    outS = new Ice.OutputStream(communicator);
                    var l = new Queue <Test.SmallStruct>(smallStructArray);
                    Test.SmallStructQueueHelper.write(outS, l);
                    var data = outS.finished();
                    inS = new Ice.InputStream(communicator, data);
                    var l2 = Test.SmallStructQueueHelper.read(inS);
                    test(l2.Count == l.Count);
                    var e  = l.GetEnumerator();
                    var e2 = l2.GetEnumerator();
                    while (e.MoveNext() && e2.MoveNext())
                    {
                        test(e.Current.Equals(e2.Current));
                    }
                }

                {
                    string[]   arr  = { "string1", "string2", "string3", "string4" };
                    string[][] arrS = { arr, new string[0], arr };
                    outS = new Ice.OutputStream(communicator);
                    var l = new List <string[]>(arrS);
                    Test.StringSListHelper.write(outS, l);
                    byte[] data = outS.finished();
                    inS = new Ice.InputStream(communicator, data);
                    var l2 = Test.StringSListHelper.read(inS);
                    test(Compare(l2, l));
                }

                {
                    string[]   arr  = { "string1", "string2", "string3", "string4" };
                    string[][] arrS = { arr, new string[0], arr };
                    outS = new Ice.OutputStream(communicator);
                    var l = new Stack <string[]>(arrS);
                    Test.StringSStackHelper.write(outS, l);
                    var data = outS.finished();
                    inS = new Ice.InputStream(communicator, data);
                    var l2 = Test.StringSStackHelper.read(inS);
                    test(Compare(l2, l));
                }

                {
                    var dict = new SortedDictionary <string, string>();
                    dict.Add("key1", "value1");
                    dict.Add("key2", "value2");
                    outS = new Ice.OutputStream(communicator);
                    Test.SortedStringStringDHelper.write(outS, dict);
                    var data = outS.finished();
                    inS = new Ice.InputStream(communicator, data);
                    var dict2 = Test.SortedStringStringDHelper.read(inS);
                    test(Ice.CollectionComparer.Equals(dict2, dict));
                }

                output.WriteLine("ok");
                return(0);
            }
예제 #9
0
파일: AllTests.cs 프로젝트: externl/ice
    public static int run(Ice.Communicator communicator)
    {
        MyClassFactoryWrapper factoryWrapper = new MyClassFactoryWrapper();

        communicator.getValueFactoryManager().add(factoryWrapper.create, Test.MyClass.ice_staticId());
        communicator.getValueFactoryManager().add(MyInterfaceFactory, Test.MyInterfaceDisp_.ice_staticId());

        Ice.InputStream @in;
        Ice.OutputStream @out;

        Write("testing primitive types... ");
        Flush();

        {
            byte[] data = new byte[0];
            @in = new Ice.InputStream(communicator, data);
        }

        {
            @out = new Ice.OutputStream(communicator);
            @out.startEncapsulation();
            @out.writeBool(true);
            @out.endEncapsulation();
            byte[] data = @out.finished();

            @in = new Ice.InputStream(communicator, data);
            @in.startEncapsulation();
            test(@in.readBool());
            @in.endEncapsulation();

            @in = new Ice.InputStream(communicator, data);
            @in.startEncapsulation();
            test(@in.readBool());
            @in.endEncapsulation();
        }

        {
            byte[] data = new byte[0];
            @in = new Ice.InputStream(communicator, data);
            try
            {
                @in.readBool();
                test(false);
            }
            catch (Ice.UnmarshalOutOfBoundsException)
            {
            }
        }

        {
            @out = new Ice.OutputStream(communicator);
            @out.writeBool(true);
            byte[] data = @out.finished();
            @in = new Ice.InputStream(communicator, data);
            test(@in.readBool());
        }

        {
            @out = new Ice.OutputStream(communicator);
            @out.writeByte((byte)1);
            byte[] data = @out.finished();
            @in = new Ice.InputStream(communicator, data);
            test(@in.readByte() == (byte)1);
        }

        {
            @out = new Ice.OutputStream(communicator);
            @out.writeShort((short)2);
            byte[] data = @out.finished();
            @in = new Ice.InputStream(communicator, data);
            test(@in.readShort() == (short)2);
        }

        {
            @out = new Ice.OutputStream(communicator);
            @out.writeInt(3);
            byte[] data = @out.finished();
            @in = new Ice.InputStream(communicator, data);
            test(@in.readInt() == 3);
        }

        {
            @out = new Ice.OutputStream(communicator);
            @out.writeLong(4);
            byte[] data = @out.finished();
            @in = new Ice.InputStream(communicator, data);
            test(@in.readLong() == 4);
        }

        {
            @out = new Ice.OutputStream(communicator);
            @out.writeFloat((float)5.0);
            byte[] data = @out.finished();
            @in = new Ice.InputStream(communicator, data);
            test(@in.readFloat() == (float)5.0);
        }

        {
            @out = new Ice.OutputStream(communicator);
            @out.writeDouble(6.0);
            byte[] data = @out.finished();
            @in = new Ice.InputStream(communicator, data);
            test(@in.readDouble() == 6.0);
        }

        {
            @out = new Ice.OutputStream(communicator);
            @out.writeString("hello world");
            byte[] data = @out.finished();
            @in = new Ice.InputStream(communicator, data);
            test(@in.readString().Equals("hello world"));
        }

        WriteLine("ok");

        Write("testing constructed types... ");
        Flush();

        {
            @out = new Ice.OutputStream(communicator);
            Test.MyEnumHelper.write(@out, Test.MyEnum.enum3);
            byte[] data = @out.finished();
            @in = new Ice.InputStream(communicator, data);
            Test.MyEnum e = Test.MyEnumHelper.read(@in);
            test(e == Test.MyEnum.enum3);
        }

        {
            @out = new Ice.OutputStream(communicator);
            Test.SmallStruct s = new Test.SmallStruct();
            s.bo = true;
            s.by = (byte)1;
            s.sh = (short)2;
            s.i = 3;
            s.l = 4;
            s.f = (float)5.0;
            s.d = 6.0;
            s.str = "7";
            s.e = Test.MyEnum.enum2;
            s.p = Test.MyClassPrxHelper.uncheckedCast(communicator.stringToProxy("test:default"));
            s.write__(@out);
            byte[] data = @out.finished();
            @in = new Ice.InputStream(communicator, data);
            Test.SmallStruct s2 = new Test.SmallStruct();
            s2.read__(@in);
            test(s2.Equals(s));
        }

        {
            @out = new Ice.OutputStream(communicator);
            OptionalClass o = new OptionalClass();
            o.bo = true;
            o.by = (byte)5;
            o.sh = 4;
            o.i = 3;
            @out.writeValue(o);
            @out.writePendingValues();
            byte[] data = @out.finished();
            @in = new Ice.InputStream(communicator, data);
            TestReadValueCallback cb = new TestReadValueCallback();
            @in.readValue(cb.invoke);
            @in.readPendingValues();
            OptionalClass o2 = (OptionalClass)cb.obj;
            test(o2.bo == o.bo);
            test(o2.by == o.by);
            if(communicator.getProperties().getProperty("Ice.Default.EncodingVersion").Equals("1.0"))
            {
                test(!o2.sh.HasValue);
                test(!o2.i.HasValue);
            }
            else
            {
                test(o2.sh.Value == o.sh.Value);
                test(o2.i.Value == o.i.Value);
            }
        }

        {
            @out = new Ice.OutputStream(communicator, Ice.Util.Encoding_1_0);
            OptionalClass o = new OptionalClass();
            o.bo = true;
            o.by = 5;
            o.sh = 4;
            o.i = 3;
            @out.writeValue(o);
            @out.writePendingValues();
            byte[] data = @out.finished();
            @in = new Ice.InputStream(communicator, Ice.Util.Encoding_1_0, data);
            TestReadValueCallback cb = new TestReadValueCallback();
            @in.readValue(cb.invoke);
            @in.readPendingValues();
            OptionalClass o2 = (OptionalClass)cb.obj;
            test(o2.bo == o.bo);
            test(o2.by == o.by);
            test(!o2.sh.HasValue);
            test(!o2.i.HasValue);
        }

        {
            bool[] arr =
            {
                true,
                false,
                true,
                false
            };
            @out = new Ice.OutputStream(communicator);
            Ice.BoolSeqHelper.write(@out, arr);
            byte[] data = @out.finished();
            @in = new Ice.InputStream(communicator, data);
            bool[] arr2 = Ice.BoolSeqHelper.read(@in);
            test(Compare(arr2, arr));

            bool[][] arrS =
            {
                arr,
                new bool[0],
                arr
            };
            @out = new Ice.OutputStream(communicator);
            Test.BoolSSHelper.write(@out, arrS);
            data = @out.finished();
            @in = new Ice.InputStream(communicator, data);
            bool[][] arr2S = Test.BoolSSHelper.read(@in);
            test(Compare(arr2S, arrS));
        }

        {
            byte[] arr =
            {
                (byte)0x01,
                (byte)0x11,
                (byte)0x12,
                (byte)0x22
            };
            @out = new Ice.OutputStream(communicator);
            Ice.ByteSeqHelper.write(@out, arr);
            byte[] data = @out.finished();
            @in = new Ice.InputStream(communicator, data);
            byte[] arr2 = Ice.ByteSeqHelper.read(@in);
            test(Compare(arr2, arr));

            byte[][] arrS =
            {
                arr,
                new byte[0],
                arr
            };
            @out = new Ice.OutputStream(communicator);
            Test.ByteSSHelper.write(@out, arrS);
            data = @out.finished();
            @in = new Ice.InputStream(communicator, data);
            byte[][] arr2S = Test.ByteSSHelper.read(@in);
            test(Compare(arr2S, arrS));
        }

        {
            Serialize.Small small = new Serialize.Small();
            small.i = 99;
            @out = new Ice.OutputStream(communicator);
            @out.writeSerializable(small);
            byte[] data = @out.finished();
            @in = new Ice.InputStream(communicator, data);
            Serialize.Small small2 = (Serialize.Small)@in.readSerializable();
            test(small2.i == 99);
        }

        {
            short[] arr =
            {
                (short)0x01,
                (short)0x11,
                (short)0x12,
                (short)0x22
            };
            @out = new Ice.OutputStream(communicator);
            Ice.ShortSeqHelper.write(@out, arr);
            byte[] data = @out.finished();
            @in = new Ice.InputStream(communicator, data);
            short[] arr2 = Ice.ShortSeqHelper.read(@in);
            test(Compare(arr2, arr));

            short[][] arrS =
            {
                arr,
                new short[0],
                arr
            };
            @out = new Ice.OutputStream(communicator);
            Test.ShortSSHelper.write(@out, arrS);
            data = @out.finished();
            @in = new Ice.InputStream(communicator, data);
            short[][] arr2S = Test.ShortSSHelper.read(@in);
            test(Compare(arr2S, arrS));
        }

        {
            int[] arr =
            {
                0x01,
                0x11,
                0x12,
                0x22
            };
            @out = new Ice.OutputStream(communicator);
            Ice.IntSeqHelper.write(@out, arr);
            byte[] data = @out.finished();
            @in = new Ice.InputStream(communicator, data);
            int[] arr2 = Ice.IntSeqHelper.read(@in);
            test(Compare(arr2, arr));

            int[][] arrS =
            {
                arr,
                new int[0],
                arr
            };
            @out = new Ice.OutputStream(communicator);
            Test.IntSSHelper.write(@out, arrS);
            data = @out.finished();
            @in = new Ice.InputStream(communicator, data);
            int[][] arr2S = Test.IntSSHelper.read(@in);
            test(Compare(arr2S, arrS));
        }

        {
            long[] arr =
            {
                0x01,
                0x11,
                0x12,
                0x22
            };
            @out = new Ice.OutputStream(communicator);
            Ice.LongSeqHelper.write(@out, arr);
            byte[] data = @out.finished();
            @in = new Ice.InputStream(communicator, data);
            long[] arr2 = Ice.LongSeqHelper.read(@in);
            test(Compare(arr2, arr));

            long[][] arrS =
            {
                arr,
                new long[0],
                arr
            };
            @out = new Ice.OutputStream(communicator);
            Test.LongSSHelper.write(@out, arrS);
            data = @out.finished();
            @in = new Ice.InputStream(communicator, data);
            long[][] arr2S = Test.LongSSHelper.read(@in);
            test(Compare(arr2S, arrS));
        }

        {
            float[] arr =
            {
                (float)1,
                (float)2,
                (float)3,
                (float)4
            };
            @out = new Ice.OutputStream(communicator);
            Ice.FloatSeqHelper.write(@out, arr);
            byte[] data = @out.finished();
            @in = new Ice.InputStream(communicator, data);
            float[] arr2 = Ice.FloatSeqHelper.read(@in);
            test(Compare(arr2, arr));

            float[][] arrS =
            {
                arr,
                new float[0],
                arr
            };
            @out = new Ice.OutputStream(communicator);
            Test.FloatSSHelper.write(@out, arrS);
            data = @out.finished();
            @in = new Ice.InputStream(communicator, data);
            float[][] arr2S = Test.FloatSSHelper.read(@in);
            test(Compare(arr2S, arrS));
        }

        {
            double[] arr =
            {
                (double)1,
                (double)2,
                (double)3,
                (double)4
            };
            @out = new Ice.OutputStream(communicator);
            Ice.DoubleSeqHelper.write(@out, arr);
            byte[] data = @out.finished();
            @in = new Ice.InputStream(communicator, data);
            double[] arr2 = Ice.DoubleSeqHelper.read(@in);
            test(Compare(arr2, arr));

            double[][] arrS =
            {
                arr,
                new double[0],
                arr
            };
            @out = new Ice.OutputStream(communicator);
            Test.DoubleSSHelper.write(@out, arrS);
            data = @out.finished();
            @in = new Ice.InputStream(communicator, data);
            double[][] arr2S = Test.DoubleSSHelper.read(@in);
            test(Compare(arr2S, arrS));
        }

        {
            string[] arr =
            {
                "string1",
                "string2",
                "string3",
                "string4"
            };
            @out = new Ice.OutputStream(communicator);
            Ice.StringSeqHelper.write(@out, arr);
            byte[] data = @out.finished();
            @in = new Ice.InputStream(communicator, data);
            string[] arr2 = Ice.StringSeqHelper.read(@in);
            test(Compare(arr2, arr));

            string[][] arrS =
            {
                arr,
                new string[0],
                arr
            };
            @out = new Ice.OutputStream(communicator);
            Test.StringSSHelper.write(@out, arrS);
            data = @out.finished();
            @in = new Ice.InputStream(communicator, data);
            string[][] arr2S = Test.StringSSHelper.read(@in);
            test(Compare(arr2S, arrS));
        }

        {
            Test.MyEnum[] arr =
            {
                Test.MyEnum.enum3,
                Test.MyEnum.enum2,
                Test.MyEnum.enum1,
                Test.MyEnum.enum2
            };
            @out = new Ice.OutputStream(communicator);
            Test.MyEnumSHelper.write(@out, arr);
            byte[] data = @out.finished();
            @in = new Ice.InputStream(communicator, data);
            Test.MyEnum[] arr2 = Test.MyEnumSHelper.read(@in);
            test(Compare(arr2, arr));

            Test.MyEnum[][] arrS =
            {
                arr,
                new Test.MyEnum[0],
                arr
            };
            @out = new Ice.OutputStream(communicator);
            Test.MyEnumSSHelper.write(@out, arrS);
            data = @out.finished();
            @in = new Ice.InputStream(communicator, data);
            Test.MyEnum[][] arr2S = Test.MyEnumSSHelper.read(@in);
            test(Compare(arr2S, arrS));
        }

        Test.SmallStruct[] smallStructArray = new Test.SmallStruct[3];
        for (int i = 0; i < smallStructArray.Length; ++i)
        {
            smallStructArray[i] = new Test.SmallStruct();
            smallStructArray[i].bo = true;
            smallStructArray[i].by = (byte)1;
            smallStructArray[i].sh = (short)2;
            smallStructArray[i].i = 3;
            smallStructArray[i].l = 4;
            smallStructArray[i].f = (float)5.0;
            smallStructArray[i].d = 6.0;
            smallStructArray[i].str = "7";
            smallStructArray[i].e = Test.MyEnum.enum2;
            smallStructArray[i].p = Test.MyClassPrxHelper.uncheckedCast(communicator.stringToProxy("test:default"));
        }

        Test.MyClass[] myClassArray = new Test.MyClass[4];
        for (int i = 0; i < myClassArray.Length; ++i)
        {
            myClassArray[i] = new Test.MyClass();
            myClassArray[i].c = myClassArray[i];
            myClassArray[i].o = myClassArray[i];
            myClassArray[i].s = new Test.SmallStruct();
            myClassArray[i].s.e = Test.MyEnum.enum2;
            myClassArray[i].seq1 = new bool[] { true, false, true, false };
            myClassArray[i].seq2 = new byte[] { (byte)1, (byte)2, (byte)3, (byte)4 };
            myClassArray[i].seq3 = new short[] { (short)1, (short)2, (short)3, (short)4 };
            myClassArray[i].seq4 = new int[] { 1, 2, 3, 4 };
            myClassArray[i].seq5 = new long[] { 1, 2, 3, 4 };
            myClassArray[i].seq6 = new float[] { (float)1, (float)2, (float)3, (float)4 };
            myClassArray[i].seq7 = new double[] { (double)1, (double)2, (double)3, (double)4 };
            myClassArray[i].seq8 = new string[] { "string1", "string2", "string3", "string4" };
            myClassArray[i].seq9 = new Test.MyEnum[] { Test.MyEnum.enum3, Test.MyEnum.enum2, Test.MyEnum.enum1 };
            myClassArray[i].seq10 = new Test.MyClass[4]; // null elements.
            myClassArray[i].d = new System.Collections.Generic.Dictionary<string, Test.MyClass>();
            myClassArray[i].d["hi"] = myClassArray[i];
        }

        {
            @out = new Ice.OutputStream(communicator);
            Test.MyClassSHelper.write(@out, myClassArray);
            @out.writePendingValues();
            byte[] data = @out.finished();
            @in = new Ice.InputStream(communicator, data);
            Test.MyClass[] arr2 = Test.MyClassSHelper.read(@in);
            @in.readPendingValues();
            test(arr2.Length == myClassArray.Length);
            for (int i = 0; i < arr2.Length; ++i)
            {
                test(arr2[i] != null);
                test(arr2[i].c == arr2[i]);
                test(arr2[i].o == arr2[i]);
                test(arr2[i].s.e == Test.MyEnum.enum2);
                test(Compare(arr2[i].seq1, myClassArray[i].seq1));
                test(Compare(arr2[i].seq2, myClassArray[i].seq2));
                test(Compare(arr2[i].seq3, myClassArray[i].seq3));
                test(Compare(arr2[i].seq4, myClassArray[i].seq4));
                test(Compare(arr2[i].seq5, myClassArray[i].seq5));
                test(Compare(arr2[i].seq6, myClassArray[i].seq6));
                test(Compare(arr2[i].seq7, myClassArray[i].seq7));
                test(Compare(arr2[i].seq8, myClassArray[i].seq8));
                test(Compare(arr2[i].seq9, myClassArray[i].seq9));
                test(arr2[i].d["hi"].Equals(arr2[i]));
            }

            Test.MyClass[][] arrS =
            {
                myClassArray,
                new Test.MyClass[0],
                myClassArray
            };
            @out = new Ice.OutputStream(communicator);
            Test.MyClassSSHelper.write(@out, arrS);
            data = @out.finished();
            @in = new Ice.InputStream(communicator, data);
            Test.MyClass[][] arr2S = Test.MyClassSSHelper.read(@in);
            test(arr2S.Length == arrS.Length);
            test(arr2S[0].Length == arrS[0].Length);
            test(arr2S[1].Length == arrS[1].Length);
            test(arr2S[2].Length == arrS[2].Length);
        }

        {
            Test.MyInterface i = new MyInterfaceI();
            @out = new Ice.OutputStream(communicator);
            @out.writeValue(i);
            @out.writePendingValues();
            byte[] data = @out.finished();
            @in = new Ice.InputStream(communicator, data);
            TestReadValueCallback cb = new TestReadValueCallback();
            @in.readValue(cb.invoke);
            @in.readPendingValues();
            test(cb.obj != null);
        }

        {
            @out = new Ice.OutputStream(communicator);
            Test.MyClass obj = new Test.MyClass();
            obj.s = new Test.SmallStruct();
            obj.s.e = Test.MyEnum.enum2;
            TestValueWriter writer = new TestValueWriter(obj);
            @out.writeValue(writer);
            @out.writePendingValues();
            byte[] data = @out.finished();
            test(writer.called);
            factoryWrapper.setFactory(TestObjectFactory);
            @in = new Ice.InputStream(communicator, data);
            TestReadValueCallback cb = new TestReadValueCallback();
            @in.readValue(cb.invoke);
            @in.readPendingValues();
            test(cb.obj != null);
            test(cb.obj is TestValueReader);
            TestValueReader reader = (TestValueReader)cb.obj;
            test(reader.called);
            test(reader.obj != null);
            test(reader.obj.s.e == Test.MyEnum.enum2);
            factoryWrapper.setFactory(null);
        }

        {
            @out = new Ice.OutputStream(communicator);
            Test.MyException ex = new Test.MyException();

            Test.MyClass c = new Test.MyClass();
            c.c = c;
            c.o = c;
            c.s = new Test.SmallStruct();
            c.s.e = Test.MyEnum.enum2;
            c.seq1 = new bool[] { true, false, true, false };
            c.seq2 = new byte[] { (byte)1, (byte)2, (byte)3, (byte)4 };
            c.seq3 = new short[] { (short)1, (short)2, (short)3, (short)4 };
            c.seq4 = new int[] { 1, 2, 3, 4 };
            c.seq5 = new long[] { 1, 2, 3, 4 };
            c.seq6 = new float[] { (float)1, (float)2, (float)3, (float)4 };
            c.seq7 = new double[] { (double)1, (double)2, (double)3, (double)4 };
            c.seq8 = new string[] { "string1", "string2", "string3", "string4" };
            c.seq9 = new Test.MyEnum[] { Test.MyEnum.enum3, Test.MyEnum.enum2, Test.MyEnum.enum1 };
            c.seq10 = new Test.MyClass[4]; // null elements.
            c.d = new Dictionary<string, Test.MyClass>();
            c.d.Add("hi", c);

            ex.c = c;

            @out.writeException(ex);
            byte[] data = @out.finished();

            @in = new Ice.InputStream(communicator, data);
            try
            {
                @in.throwException();
                test(false);
            }
            catch (Test.MyException ex1)
            {
                test(ex1.c.s.e == c.s.e);
                test(Compare(ex1.c.seq1, c.seq1));
                test(Compare(ex1.c.seq2, c.seq2));
                test(Compare(ex1.c.seq3, c.seq3));
                test(Compare(ex1.c.seq4, c.seq4));
                test(Compare(ex1.c.seq5, c.seq5));
                test(Compare(ex1.c.seq6, c.seq6));
                test(Compare(ex1.c.seq7, c.seq7));
                test(Compare(ex1.c.seq8, c.seq8));
                test(Compare(ex1.c.seq9, c.seq9));
            }
            catch (Ice.UserException)
            {
                test(false);
            }
        }

        {
            Dictionary<byte, bool> dict = new Dictionary<byte, bool>();
            dict.Add((byte)4, true);
            dict.Add((byte)1, false);
            @out = new Ice.OutputStream(communicator);
            Test.ByteBoolDHelper.write(@out, dict);
            byte[] data = @out.finished();
            @in = new Ice.InputStream(communicator, data);
            Dictionary<byte, bool> dict2 = Test.ByteBoolDHelper.read(@in);
            test(Ice.CollectionComparer.Equals(dict2, dict));
        }

        {
            Dictionary<short, int> dict = new Dictionary<short, int>();
            dict.Add((short)1, 9);
            dict.Add((short)4, 8);
            @out = new Ice.OutputStream(communicator);
            Test.ShortIntDHelper.write(@out, dict);
            byte[] data = @out.finished();
            @in = new Ice.InputStream(communicator, data);
            Dictionary<short, int> dict2 = Test.ShortIntDHelper.read(@in);
            test(Ice.CollectionComparer.Equals(dict2, dict));
        }

        {
            Dictionary<long, float> dict = new Dictionary<long, float>();
            dict.Add((long)123809828, (float)0.51f);
            dict.Add((long)123809829, (float)0.56f);
            @out = new Ice.OutputStream(communicator);
            Test.LongFloatDHelper.write(@out, dict);
            byte[] data = @out.finished();
            @in = new Ice.InputStream(communicator, data);
            Dictionary<long, float> dict2 = Test.LongFloatDHelper.read(@in);
            test(Ice.CollectionComparer.Equals(dict2, dict));
        }

        {
            Dictionary<string, string> dict = new Dictionary<string, string>();
            dict.Add("key1", "value1");
            dict.Add("key2", "value2");
            @out = new Ice.OutputStream(communicator);
            Test.StringStringDHelper.write(@out, dict);
            byte[] data = @out.finished();
            @in = new Ice.InputStream(communicator, data);
            Dictionary<string, string> dict2 = Test.StringStringDHelper.read(@in);
            test(Ice.CollectionComparer.Equals(dict2, dict));
        }

        {
            Dictionary<string, Test.MyClass> dict = new Dictionary<string, Test.MyClass>();
            Test.MyClass c;
            c = new Test.MyClass();
            c.s = new Test.SmallStruct();
            c.s.e = Test.MyEnum.enum2;
            dict.Add("key1", c);
            c = new Test.MyClass();
            c.s = new Test.SmallStruct();
            c.s.e = Test.MyEnum.enum3;
            dict.Add("key2", c);
            @out = new Ice.OutputStream(communicator);
            Test.StringMyClassDHelper.write(@out, dict);
            @out.writePendingValues();
            byte[] data = @out.finished();
            @in = new Ice.InputStream(communicator, data);
            Dictionary<string, Test.MyClass> dict2 = Test.StringMyClassDHelper.read(@in);
            @in.readPendingValues();
            test(dict2.Count == dict.Count);
            test(dict2["key1"].s.e == Test.MyEnum.enum2);
            test(dict2["key2"].s.e == Test.MyEnum.enum3);
        }

        {
            bool[] arr =
            {
                true,
                false,
                true,
                false
            };
            @out = new Ice.OutputStream(communicator);
            List<bool> l = new List<bool>(arr);
            Test.BoolListHelper.write(@out, l);
            byte[] data = @out.finished();
            @in = new Ice.InputStream(communicator, data);
            List<bool> l2 = Test.BoolListHelper.read(@in);
            test(Compare(l, l2));
        }

        {
            byte[] arr =
            {
                (byte)0x01,
                (byte)0x11,
                (byte)0x12,
                (byte)0x22
            };
            @out = new Ice.OutputStream(communicator);
            List<byte> l = new List<byte>(arr);
            Test.ByteListHelper.write(@out, l);
            byte[] data = @out.finished();
            @in = new Ice.InputStream(communicator, data);
            List<byte> l2 = Test.ByteListHelper.read(@in);
            test(Compare(l2, l));
        }

        {
            Test.MyEnum[] arr =
            {
                Test.MyEnum.enum3,
                Test.MyEnum.enum2,
                Test.MyEnum.enum1,
                Test.MyEnum.enum2
            };
            @out = new Ice.OutputStream(communicator);
            List<Test.MyEnum> l = new List<Test.MyEnum>(arr);
            Test.MyEnumListHelper.write(@out, l);
            byte[] data = @out.finished();
            @in = new Ice.InputStream(communicator, data);
            List<Test.MyEnum> l2 = Test.MyEnumListHelper.read(@in);
            test(Compare(l2, l));
        }

        {
            @out = new Ice.OutputStream(communicator);
            List<Test.SmallStruct> l = new List<Test.SmallStruct>(smallStructArray);
            Test.SmallStructListHelper.write(@out, l);
            byte[] data = @out.finished();
            @in = new Ice.InputStream(communicator, data);
            List<Test.SmallStruct> l2 = Test.SmallStructListHelper.read(@in);
            test(l2.Count == l.Count);
            for (int i = 0; i < l2.Count; ++i)
            {
                test(l2[i].Equals(smallStructArray[i]));
            }
        }

        {
            @out = new Ice.OutputStream(communicator);
            List<Test.MyClass> l = new List<Test.MyClass>(myClassArray);
            Test.MyClassListHelper.write(@out, l);
            @out.writePendingValues();
            byte[] data = @out.finished();
            @in = new Ice.InputStream(communicator, data);
            List<Test.MyClass> l2 = Test.MyClassListHelper.read(@in);
            @in.readPendingValues();
            test(l2.Count == l.Count);
            for (int i = 0; i < l2.Count; ++i)
            {
                test(l2[i] != null);
                test(l2[i].c == l2[i]);
                test(l2[i].o == l2[i]);
                test(l2[i].s.e == Test.MyEnum.enum2);
                test(Compare(l2[i].seq1, l[i].seq1));
                test(Compare(l2[i].seq2, l[i].seq2));
                test(Compare(l2[i].seq3, l[i].seq3));
                test(Compare(l2[i].seq4, l[i].seq4));
                test(Compare(l2[i].seq5, l[i].seq5));
                test(Compare(l2[i].seq6, l[i].seq6));
                test(Compare(l2[i].seq7, l[i].seq7));
                test(Compare(l2[i].seq8, l[i].seq8));
                test(Compare(l2[i].seq9, l[i].seq9));
                test(l2[i].d["hi"].Equals(l2[i]));
            }
        }

        {
            Test.MyClassPrx[] arr = new Test.MyClassPrx[2];
            arr[0] = Test.MyClassPrxHelper.uncheckedCast(communicator.stringToProxy("zero"));
            arr[1] = Test.MyClassPrxHelper.uncheckedCast(communicator.stringToProxy("one"));
            @out = new Ice.OutputStream(communicator);
            List<Test.MyClassPrx> l = new List<Test.MyClassPrx>(arr);
            Test.MyClassProxyListHelper.write(@out, l);
            byte[] data = @out.finished();
            @in = new Ice.InputStream(communicator, data);
            List<Test.MyClassPrx> l2 = Test.MyClassProxyListHelper.read(@in);
            test(Compare(l2, l));
        }

        {
            short[] arr =
            {
                (short)0x01,
                (short)0x11,
                (short)0x12,
                (short)0x22
            };
            @out = new Ice.OutputStream(communicator);
            LinkedList<short> l = new LinkedList<short>(arr);
            Test.ShortLinkedListHelper.write(@out, l);
            byte[] data = @out.finished();
            @in = new Ice.InputStream(communicator, data);
            LinkedList<short> l2 = Test.ShortLinkedListHelper.read(@in);
            test(Compare(l2, l));
        }

        {
            int[] arr =
            {
                0x01,
                0x11,
                0x12,
                0x22
            };
            @out = new Ice.OutputStream(communicator);
            LinkedList<int> l = new LinkedList<int>(arr);
            Test.IntLinkedListHelper.write(@out, l);
            byte[] data = @out.finished();
            @in = new Ice.InputStream(communicator, data);
            LinkedList<int> l2 = Test.IntLinkedListHelper.read(@in);
            test(Compare(l2, l));
        }

        {
            Test.MyEnum[] arr =
            {
                Test.MyEnum.enum3,
                Test.MyEnum.enum2,
                Test.MyEnum.enum1,
                Test.MyEnum.enum2
            };
            @out = new Ice.OutputStream(communicator);
            LinkedList<Test.MyEnum> l = new LinkedList<Test.MyEnum>(arr);
            Test.MyEnumLinkedListHelper.write(@out, l);
            byte[] data = @out.finished();
            @in = new Ice.InputStream(communicator, data);
            LinkedList<Test.MyEnum> l2 = Test.MyEnumLinkedListHelper.read(@in);
            test(Compare(l2, l));
        }

        {
            @out = new Ice.OutputStream(communicator);
            LinkedList<Test.SmallStruct> l = new LinkedList<Test.SmallStruct>(smallStructArray);
            Test.SmallStructLinkedListHelper.write(@out, l);
            byte[] data = @out.finished();
            @in = new Ice.InputStream(communicator, data);
            LinkedList<Test.SmallStruct> l2 = Test.SmallStructLinkedListHelper.read(@in);
            test(l2.Count == l.Count);
            IEnumerator<Test.SmallStruct> e = l.GetEnumerator();
            IEnumerator<Test.SmallStruct> e2 = l2.GetEnumerator();
            while (e.MoveNext() && e2.MoveNext())
            {
                test(e.Current.Equals(e2.Current));
            }
        }

        {
            long[] arr =
            {
                0x01,
                0x11,
                0x12,
                0x22
            };
            @out = new Ice.OutputStream(communicator);
            Stack<long> l = new Stack<long>(arr);
            Test.LongStackHelper.write(@out, l);
            byte[] data = @out.finished();
            @in = new Ice.InputStream(communicator, data);
            Stack<long> l2 = Test.LongStackHelper.read(@in);
            test(Compare(l2, l));
        }

        {
            float[] arr =
            {
                (float)1,
                (float)2,
                (float)3,
                (float)4
            };
            @out = new Ice.OutputStream(communicator);
            Stack<float> l = new Stack<float>(arr);
            Test.FloatStackHelper.write(@out, l);
            byte[] data = @out.finished();
            @in = new Ice.InputStream(communicator, data);
            Stack<float> l2 = Test.FloatStackHelper.read(@in);
            test(Compare(l2, l));
        }

        {
            @out = new Ice.OutputStream(communicator);
            Stack<Test.SmallStruct> l = new Stack<Test.SmallStruct>(smallStructArray);
            Test.SmallStructStackHelper.write(@out, l);
            byte[] data = @out.finished();
            @in = new Ice.InputStream(communicator, data);
            Stack<Test.SmallStruct> l2 = Test.SmallStructStackHelper.read(@in);
            test(l2.Count == l.Count);
            IEnumerator<Test.SmallStruct> e = l.GetEnumerator();
            IEnumerator<Test.SmallStruct> e2 = l2.GetEnumerator();
            while (e.MoveNext() && e2.MoveNext())
            {
                test(e.Current.Equals(e2.Current));
            }
        }

        {
            Test.MyClassPrx[] arr = new Test.MyClassPrx[2];
            arr[0] = Test.MyClassPrxHelper.uncheckedCast(communicator.stringToProxy("zero"));
            arr[1] = Test.MyClassPrxHelper.uncheckedCast(communicator.stringToProxy("one"));
            @out = new Ice.OutputStream(communicator);
            Stack<Test.MyClassPrx> l = new Stack<Test.MyClassPrx>(arr);
            Test.MyClassProxyStackHelper.write(@out, l);
            byte[] data = @out.finished();
            @in = new Ice.InputStream(communicator, data);
            Stack<Test.MyClassPrx> l2 = Test.MyClassProxyStackHelper.read(@in);
            test(Compare(l2, l));
        }

        {
            double[] arr =
            {
                (double)1,
                (double)2,
                (double)3,
                (double)4
            };
            @out = new Ice.OutputStream(communicator);
            Queue<double> l = new Queue<double>(arr);
            Test.DoubleQueueHelper.write(@out, l);
            byte[] data = @out.finished();
            @in = new Ice.InputStream(communicator, data);
            Queue<double> l2 = Test.DoubleQueueHelper.read(@in);
            test(Compare(l2, l));
        }

        {
            string[] arr =
            {
                "string1",
                "string2",
                "string3",
                "string4"
            };
            @out = new Ice.OutputStream(communicator);
            Queue<string> l = new Queue<string>(arr);
            Test.StringQueueHelper.write(@out, l);
            byte[] data = @out.finished();
            @in = new Ice.InputStream(communicator, data);
            Queue<string> l2 = Test.StringQueueHelper.read(@in);
            test(Compare(l2, l));
        }

        {
            @out = new Ice.OutputStream(communicator);
            Queue<Test.SmallStruct> l = new Queue<Test.SmallStruct>(smallStructArray);
            Test.SmallStructQueueHelper.write(@out, l);
            byte[] data = @out.finished();
            @in = new Ice.InputStream(communicator, data);
            Queue<Test.SmallStruct> l2 = Test.SmallStructQueueHelper.read(@in);
            test(l2.Count == l.Count);
            IEnumerator<Test.SmallStruct> e = l.GetEnumerator();
            IEnumerator<Test.SmallStruct> e2 = l2.GetEnumerator();
            while (e.MoveNext() && e2.MoveNext())
            {
                test(e.Current.Equals(e2.Current));
            }
        }

        {
            string[] arr =
            {
                "string1",
                "string2",
                "string3",
                "string4"
            };
            string[][] arrS =
            {
                arr,
                new string[0],
                arr
            };
            @out = new Ice.OutputStream(communicator);
            List<string[]> l = new List<string[]>(arrS);
            Test.StringSListHelper.write(@out, l);
            byte[] data = @out.finished();
            @in = new Ice.InputStream(communicator, data);
            List<string[]> l2 = Test.StringSListHelper.read(@in);
            test(Compare(l2, l));
        }

        {
            string[] arr =
            {
                "string1",
                "string2",
                "string3",
                "string4"
            };
            string[][] arrS =
            {
                arr,
                new string[0],
                arr
            };
            @out = new Ice.OutputStream(communicator);
            Stack<string[]> l = new Stack<string[]>(arrS);
            Test.StringSStackHelper.write(@out, l);
            byte[] data = @out.finished();
            @in = new Ice.InputStream(communicator, data);
            Stack<string[]> l2 = Test.StringSStackHelper.read(@in);
            test(Compare(l2, l));
        }

        {
            SortedDictionary<string, string> dict = new SortedDictionary<string, string>();
            dict.Add("key1", "value1");
            dict.Add("key2", "value2");
            @out = new Ice.OutputStream(communicator);
            Test.SortedStringStringDHelper.write(@out, dict);
            byte[] data = @out.finished();
            @in = new Ice.InputStream(communicator, data);
            IDictionary<string, string> dict2 = Test.SortedStringStringDHelper.read(@in);
            test(Ice.CollectionComparer.Equals(dict2, dict));
        }

        WriteLine("ok");
        return 0;
    }
예제 #10
0
파일: AllTests.cs 프로젝트: Crysty-Yui/ice
    public static Test.MyClassPrx allTests(Ice.Communicator communicator)
#endif
    {
        Ice.ObjectPrx baseProxy = communicator.stringToProxy("test:default -p 12010");
        Test.MyClassPrx cl = Test.MyClassPrxHelper.checkedCast(baseProxy);
        Test.MyClassPrx oneway = Test.MyClassPrxHelper.uncheckedCast(cl.ice_oneway());
        Test.MyClassPrx batchOneway = Test.MyClassPrxHelper.uncheckedCast(cl.ice_batchOneway());

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

        {
            byte[] inEncaps, outEncaps;
            if(!oneway.ice_invoke("opOneway", Ice.OperationMode.Normal, null, out outEncaps))
            {
                test(false);
            }

            test(batchOneway.ice_invoke("opOneway", Ice.OperationMode.Normal, null, out outEncaps));
            test(batchOneway.ice_invoke("opOneway", Ice.OperationMode.Normal, null, out outEncaps));
            test(batchOneway.ice_invoke("opOneway", Ice.OperationMode.Normal, null, out outEncaps));
            test(batchOneway.ice_invoke("opOneway", Ice.OperationMode.Normal, null, out outEncaps));
            batchOneway.ice_flushBatchRequests();

            Ice.OutputStream outS = new Ice.OutputStream(communicator);
            outS.startEncapsulation();
            outS.writeString(testString);
            outS.endEncapsulation();
            inEncaps = outS.finished();

            if(cl.ice_invoke("opString", Ice.OperationMode.Normal, inEncaps, out outEncaps))
            {
                Ice.InputStream inS = new Ice.InputStream(communicator, outEncaps);
                inS.startEncapsulation();
                string s = inS.readString();
                test(s.Equals(testString));
                s = inS.readString();
                inS.endEncapsulation();
                test(s.Equals(testString));
            }
            else
            {
                test(false);
            }
        }

        {
            byte[] outEncaps;
            if(cl.ice_invoke("opException", Ice.OperationMode.Normal, null, out outEncaps))
            {
                test(false);
            }
            else
            {
                Ice.InputStream inS = new Ice.InputStream(communicator, outEncaps);
                inS.startEncapsulation();
                try
                {
                    inS.throwException();
                }
                catch(Test.MyException)
                {
                    inS.endEncapsulation();
                }
                catch(System.Exception)
                {
                    test(false);
                }
            }
        }

        WriteLine("ok");

        Write("testing asynchronous ice_invoke... ");
        Flush();

        {
            byte[] inEncaps, outEncaps;
            Ice.AsyncResult result = oneway.begin_ice_invoke("opOneway", Ice.OperationMode.Normal, null);
            if(!oneway.end_ice_invoke(out outEncaps, result))
            {
                test(false);
            }

            Ice.OutputStream outS = new Ice.OutputStream(communicator);
            outS.startEncapsulation();
            outS.writeString(testString);
            outS.endEncapsulation();
            inEncaps = outS.finished();

            // begin_ice_invoke with no callback
            result = cl.begin_ice_invoke("opString", Ice.OperationMode.Normal, inEncaps);
            if(cl.end_ice_invoke(out outEncaps, result))
            {
                Ice.InputStream inS = new Ice.InputStream(communicator, outEncaps);
                inS.startEncapsulation();
                string s = inS.readString();
                test(s.Equals(testString));
                s = inS.readString();
                inS.endEncapsulation();
                test(s.Equals(testString));
            }
            else
            {
                test(false);
            }

            // begin_ice_invoke with Callback
            Callback cb = new Callback(communicator, false);
            cl.begin_ice_invoke("opString", Ice.OperationMode.Normal, inEncaps, cb.opString, null);
            cb.check();

            // begin_ice_invoke with Callback with cookie
            cb = new Callback(communicator, true);
            cl.begin_ice_invoke("opString", Ice.OperationMode.Normal, inEncaps, cb.opString, new Cookie());
            cb.check();

            // begin_ice_invoke with Callback_Object_ice_invoke
            cb = new Callback(communicator, true);
            cl.begin_ice_invoke("opString", Ice.OperationMode.Normal, inEncaps).whenCompleted(cb.opStringNC, null);
            cb.check();
        }

        {
            // begin_ice_invoke with no callback
            Ice.AsyncResult result = cl.begin_ice_invoke("opException", Ice.OperationMode.Normal, null);
            byte[] outEncaps;
            if(cl.end_ice_invoke(out outEncaps, result))
            {
                test(false);
            }
            else
            {
                Ice.InputStream inS = new Ice.InputStream(communicator, outEncaps);
                inS.startEncapsulation();
                try
                {
                    inS.throwException();
                }
                catch(Test.MyException)
                {
                    inS.endEncapsulation();
                }
                catch(System.Exception)
                {
                    test(false);
                }
            }

            // begin_ice_invoke with Callback
            Callback cb = new Callback(communicator, false);
            cl.begin_ice_invoke("opException", Ice.OperationMode.Normal, null, cb.opException, null);
            cb.check();

            // begin_ice_invoke with Callback with cookie
            cb = new Callback(communicator, true);
            cl.begin_ice_invoke("opException", Ice.OperationMode.Normal, null, cb.opException, new Cookie());
            cb.check();

            // begin_ice_invoke with Callback_Object_ice_invoke
            cb = new Callback(communicator, true);
            cl.begin_ice_invoke("opException", Ice.OperationMode.Normal, null).whenCompleted(cb.opExceptionNC, null);
            cb.check();
        }

        WriteLine("ok");

#if SILVERLIGHT
        cl.shutdown();
#else
        return cl;
#endif
    }
예제 #11
0
    public static Test.MyClassPrx allTests(Ice.Communicator communicator)
    {
        Write("testing stringToProxy... ");
        Flush();
        string rf = "test:default -p 12010";
        Ice.ObjectPrx baseProxy = communicator.stringToProxy(rf);
        test(baseProxy != null);

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        WriteLine("ok");

        Write("testing propertyToProxy... ");
        Flush();
        Ice.Properties prop = communicator.getProperties();
        String propertyPrefix = "Foo.Proxy";
        prop.setProperty(propertyPrefix, "test:default -p 12010");
        b1 = communicator.propertyToProxy(propertyPrefix);
        test(b1.ice_getIdentity().name.Equals("test") && b1.ice_getIdentity().category.Length == 0 &&
             b1.ice_getAdapterId().Length == 0 && b1.ice_getFacet().Length == 0);

        string property;

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

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

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

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

        prop.setProperty(propertyPrefix, "test:default -p 12010");

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

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

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

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

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

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

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

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

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

        WriteLine("ok");

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

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

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

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

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

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

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

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

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

        WriteLine("ok");

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

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

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

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

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

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

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

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

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

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

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

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

        WriteLine("ok");

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        string ref10 = "test -e 1.0:default -p 12010";
        Test.MyClassPrx cl10 = Test.MyClassPrxHelper.uncheckedCast(communicator.stringToProxy(ref10));
        cl10.ice_ping();
        cl10.ice_encodingVersion(Ice.Util.Encoding_1_0).ice_ping();
        cl.ice_encodingVersion(Ice.Util.Encoding_1_0).ice_ping();

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

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

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

        WriteLine("ok");

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

        ref10 = "test -p 1.0:default -p 12010";
        cl10 = Test.MyClassPrxHelper.uncheckedCast(communicator.stringToProxy(ref10));
        cl10.ice_ping();

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        WriteLine("ok");
        return cl;
    }
예제 #12
0
        public override int run(string[] args)
        {
            if(args.Length > 0)
            {
                Console.Error.WriteLine(appName() + ": too many arguments");
                return 1;
            }

            var obj = communicator().propertyToProxy("Printer.Proxy");

            menu();

            string line = null;
            do
            {
                try
                {
                    Console.Write("==> ");
                    Console.Out.Flush();
                    line = Console.In.ReadLine();
                    if(line == null)
                    {
                        break;
                    }

                    byte[] outParams;

                    if(line.Equals("1"))
                    {
                        //
                        // Marshal the in parameter.
                        //
                        var outStream = new Ice.OutputStream(communicator());
                        outStream.startEncapsulation();
                        outStream.writeString("The streaming API works!");
                        outStream.endEncapsulation();

                        //
                        // Invoke operation.
                        //
                        if(!obj.ice_invoke("printString", Ice.OperationMode.Normal, outStream.finished(),
                                           out outParams))
                        {
                            Console.Error.WriteLine("Unknown user exception");
                        }
                    }
                    else if(line.Equals("2"))
                    {
                        //
                        // Marshal the in parameter.
                        //
                        var outStream = new Ice.OutputStream(communicator());
                        outStream.startEncapsulation();
                        string[] arr = { "The", "streaming", "API", "works!" };
                        StringSeqHelper.write(outStream, arr);
                        outStream.endEncapsulation();

                        //
                        // Invoke operation.
                        //
                        if(!obj.ice_invoke("printStringSequence", Ice.OperationMode.Normal, outStream.finished(),
                                           out outParams))
                        {
                            Console.Error.WriteLine("Unknown user exception");
                        }
                    }
                    else if(line.Equals("3"))
                    {
                        //
                        // Marshal the in parameter.
                        //
                        var outStream = new Ice.OutputStream(communicator());
                        outStream.startEncapsulation();
                        var dict = new Dictionary<string, string>()
                            {
                                { "The", "streaming" },
                                { "API", "works!"}
                            };
                        StringDictHelper.write(outStream, dict);
                        outStream.endEncapsulation();

                        //
                        // Invoke operation.
                        //
                        if(!obj.ice_invoke("printDictionary", Ice.OperationMode.Normal, outStream.finished(),
                                           out outParams))
                        {
                            Console.Error.WriteLine("Unknown user exception");
                        }
                    }
                    else if(line.Equals("4"))
                    {
                        //
                        // Marshal the in parameter.
                        //
                        var outStream = new Ice.OutputStream(communicator());
                        outStream.startEncapsulation();
                        ColorHelper.write(outStream, Color.green);
                        outStream.endEncapsulation();

                        //
                        // Invoke operation.
                        //
                        if(!obj.ice_invoke("printEnum", Ice.OperationMode.Normal, outStream.finished(), out outParams))
                        {
                            Console.Error.WriteLine("Unknown user exception");
                        }
                    }
                    else if(line.Equals("5"))
                    {
                        //
                        // Marshal the in parameter.
                        //
                        var outStream = new Ice.OutputStream(communicator());
                        outStream.startEncapsulation();
                        var s = new Structure("read", Color.red);
                        Structure.write(outStream, s);
                        outStream.endEncapsulation();

                        //
                        // Invoke operation.
                        //
                        if(!obj.ice_invoke("printStruct", Ice.OperationMode.Normal, outStream.finished(),
                                           out outParams))
                        {
                            Console.Error.WriteLine("Unknown user exception");
                        }
                    }
                    else if(line.Equals("6"))
                    {
                        //
                        // Marshal the in parameter.
                        //
                        var outStream = new Ice.OutputStream(communicator());
                        outStream.startEncapsulation();
                        Structure[] arr =
                            {
                                new Structure("red", Color.red),
                                new Structure("green", Color.green),
                                new Structure("blue", Color.blue)
                            };
                        StructureSeqHelper.write(outStream, arr);
                        outStream.endEncapsulation();

                        //
                        // Invoke operation.
                        //
                        if(!obj.ice_invoke("printStructSequence", Ice.OperationMode.Normal, outStream.finished(),
                                           out outParams))
                        {
                            Console.Error.WriteLine("Unknown user exception");
                        }
                    }
                    else if(line.Equals("7"))
                    {
                        //
                        // Marshal the in parameter.
                        //
                        Ice.OutputStream outStream = new Ice.OutputStream(communicator());
                        outStream.startEncapsulation();
                        var c = new C(new Structure("blue", Color.blue));
                        outStream.writeValue(c);
                        outStream.writePendingValues();
                        outStream.endEncapsulation();

                        //
                        // Invoke operation.
                        //
                        if(!obj.ice_invoke("printClass", Ice.OperationMode.Normal, outStream.finished(), out outParams))
                        {
                            Console.Error.WriteLine("Unknown user exception");
                        }
                    }
                    else if(line.Equals("8"))
                    {
                        //
                        // Invoke operation.
                        //
                        if(!obj.ice_invoke("getValues", Ice.OperationMode.Normal, null, out outParams))
                        {
                            Console.Error.WriteLine("Unknown user exception");
                            continue;
                        }

                        //
                        // Unmarshal the results.
                        //
                        var inStream = new Ice.InputStream(communicator(), outParams);
                        inStream.startEncapsulation();
                        var cb = new ReadValueCallback();
                        inStream.readValue(cb.invoke);
                        var str = inStream.readString();
                        inStream.readPendingValues();
                        var c = cb.obj as C;
                        Console.Error.WriteLine("Got string `" + str + "' and class: s.name=" + c.s.name +
                                                ", s.value=" + c.s.value);
                    }
                    else if(line.Equals("9"))
                    {
                        //
                        // Invoke operation.
                        //
                        if(obj.ice_invoke("throwPrintFailure", Ice.OperationMode.Normal, null, out outParams))
                        {
                            Console.Error.WriteLine("Expected exception");
                            continue;
                        }

                        var inStream = new Ice.InputStream(communicator(), outParams);
                        inStream.startEncapsulation();
                        try
                        {
                            inStream.throwException();
                        }
                        catch(PrintFailure)
                        {
                            // Expected.
                        }
                        catch(Ice.UserException)
                        {
                            Console.Error.WriteLine("Unknown user exception");
                        }
                        inStream.endEncapsulation();
                    }
                    else if(line.Equals("s"))
                    {
                        obj.ice_invoke("shutdown", Ice.OperationMode.Normal, null, out outParams);
                    }
                    else if(line.Equals("x"))
                    {
                        // Nothing to do.
                    }
                    else if(line.Equals("?"))
                    {
                        menu();
                    }
                    else
                    {
                        Console.Error.WriteLine("unknown command `" + line + "'");
                        menu();
                    }
                }
                catch(Ice.LocalException ex)
                {
                    Console.Error.WriteLine(ex);
                }
            }
            while(!line.Equals("x"));

            return 0;
        }
예제 #13
0
 public override bool ice_invoke(byte[] inParams, out byte[] outParams, Ice.Current current)
 {
     Ice.Communicator communicator = current.adapter.getCommunicator();
     Ice.InputStream inS = new Ice.InputStream(communicator, inParams);
     inS.startEncapsulation();
     Ice.OutputStream outS = new Ice.OutputStream(communicator);
     outS.startEncapsulation();
     if(current.operation.Equals("opOneway"))
     {
         outParams = new byte[0];
         return true;
     }
     else if(current.operation.Equals("opString"))
     {
         string s = inS.readString();
         outS.writeString(s);
         outS.writeString(s);
         outS.endEncapsulation();
         outParams = outS.finished();
         return true;
     }
     else if(current.operation.Equals("opException"))
     {
         if(current.ctx.ContainsKey("raise"))
         {
             throw new Test.MyException();
         }
         Test.MyException ex = new Test.MyException();
         outS.writeException(ex);
         outS.endEncapsulation();
         outParams = outS.finished();
         return false;
     }
     else if(current.operation.Equals("shutdown"))
     {
         communicator.shutdown();
         outParams = null;
         return true;
     }
     else if(current.operation.Equals("ice_isA"))
     {
         string s = inS.readString();
         if(s.Equals("::Test::MyClass"))
         {
             outS.writeBool(true);
         }
         else
         {
             outS.writeBool(false);
         }
         outS.endEncapsulation();
         outParams = outS.finished();
         return true;
     }
     else
     {
         Ice.OperationNotExistException ex = new Ice.OperationNotExistException();
         ex.id = current.id;
         ex.facet = current.facet;
         ex.operation = current.operation;
         throw ex;
     }
 }
예제 #14
0
    public static Test.MyClassPrx allTests(Ice.Communicator communicator)
    {
        Ice.ObjectPrx baseProxy = communicator.stringToProxy("test:default -p 12010");
        Test.MyClassPrx cl = Test.MyClassPrxHelper.checkedCast(baseProxy);
        Test.MyClassPrx oneway = Test.MyClassPrxHelper.uncheckedCast(cl.ice_oneway());
        Test.MyClassPrx batchOneway = Test.MyClassPrxHelper.uncheckedCast(cl.ice_batchOneway());

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

        {
            byte[] inEncaps, outEncaps;
            if(!oneway.ice_invoke("opOneway", Ice.OperationMode.Normal, null, out outEncaps))
            {
                test(false);
            }

            test(batchOneway.ice_invoke("opOneway", Ice.OperationMode.Normal, null, out outEncaps));
            test(batchOneway.ice_invoke("opOneway", Ice.OperationMode.Normal, null, out outEncaps));
            test(batchOneway.ice_invoke("opOneway", Ice.OperationMode.Normal, null, out outEncaps));
            test(batchOneway.ice_invoke("opOneway", Ice.OperationMode.Normal, null, out outEncaps));
            batchOneway.ice_flushBatchRequests();

            Ice.OutputStream outS = new Ice.OutputStream(communicator);
            outS.startEncapsulation();
            outS.writeString(testString);
            outS.endEncapsulation();
            inEncaps = outS.finished();

            if(cl.ice_invoke("opString", Ice.OperationMode.Normal, inEncaps, out outEncaps))
            {
                Ice.InputStream inS = new Ice.InputStream(communicator, outEncaps);
                inS.startEncapsulation();
                string s = inS.readString();
                test(s.Equals(testString));
                s = inS.readString();
                inS.endEncapsulation();
                test(s.Equals(testString));
            }
            else
            {
                test(false);
            }
        }

        for(int i = 0; i < 2; ++i)
        {
            byte[] outEncaps;
            Dictionary<string, string> ctx = null;
            if(i == 1)
            {
                ctx = new Dictionary<string, string>();
                ctx["raise"] = "";
            }

            if(cl.ice_invoke("opException", Ice.OperationMode.Normal, null, out outEncaps, ctx))
            {
                test(false);
            }
            else
            {
                Ice.InputStream inS = new Ice.InputStream(communicator, outEncaps);
                inS.startEncapsulation();
                try
                {
                    inS.throwException();
                }
                catch(Test.MyException)
                {
                    inS.endEncapsulation();
                }
                catch(Exception)
                {
                    test(false);
                }
            }
        }

        WriteLine("ok");

        Write("testing asynchronous ice_invoke with Async Task API... ");
        Flush();

        {
            try
            {
                oneway.ice_invokeAsync("opOneway", Ice.OperationMode.Normal, null).Wait();
            }
            catch(Exception)
            {
                test(false);
            }

            Ice.OutputStream outS = new Ice.OutputStream(communicator);
            outS.startEncapsulation();
            outS.writeString(testString);
            outS.endEncapsulation();
            byte[] inEncaps = outS.finished();

            // begin_ice_invoke with no callback
            var result = cl.ice_invokeAsync("opString", Ice.OperationMode.Normal, inEncaps).Result;
            if(result.returnValue)
            {
                Ice.InputStream inS = new Ice.InputStream(communicator, result.outEncaps);
                inS.startEncapsulation();
                string s = inS.readString();
                test(s.Equals(testString));
                s = inS.readString();
                inS.endEncapsulation();
                test(s.Equals(testString));
            }
            else
            {
                test(false);
            }
        }

        {
            var result = cl.ice_invokeAsync("opException", Ice.OperationMode.Normal, null).Result;
            if(result.returnValue)
            {
                test(false);
            }
            else
            {
                Ice.InputStream inS = new Ice.InputStream(communicator, result.outEncaps);
                inS.startEncapsulation();
                try
                {
                    inS.throwException();
                }
                catch(Test.MyException)
                {
                    inS.endEncapsulation();
                }
                catch(Exception)
                {
                    test(false);
                }
            }
        }

        WriteLine("ok");

        Write("testing asynchronous ice_invoke with AsyncResult API... ");
        Flush();

        {
            byte[] inEncaps, outEncaps;
            Ice.AsyncResult result = oneway.begin_ice_invoke("opOneway", Ice.OperationMode.Normal, null);
            if(!oneway.end_ice_invoke(out outEncaps, result))
            {
                test(false);
            }

            Ice.OutputStream outS = new Ice.OutputStream(communicator);
            outS.startEncapsulation();
            outS.writeString(testString);
            outS.endEncapsulation();
            inEncaps = outS.finished();

            // begin_ice_invoke with no callback
            result = cl.begin_ice_invoke("opString", Ice.OperationMode.Normal, inEncaps);
            if(cl.end_ice_invoke(out outEncaps, result))
            {
                Ice.InputStream inS = new Ice.InputStream(communicator, outEncaps);
                inS.startEncapsulation();
                string s = inS.readString();
                test(s.Equals(testString));
                s = inS.readString();
                inS.endEncapsulation();
                test(s.Equals(testString));
            }
            else
            {
                test(false);
            }

            // begin_ice_invoke with Callback
            Callback cb = new Callback(communicator, false);
            cl.begin_ice_invoke("opString", Ice.OperationMode.Normal, inEncaps, cb.opString, null);
            cb.check();

            // begin_ice_invoke with Callback with cookie
            cb = new Callback(communicator, true);
            cl.begin_ice_invoke("opString", Ice.OperationMode.Normal, inEncaps, cb.opString, new Cookie());
            cb.check();

            // begin_ice_invoke with Callback_Object_ice_invoke
            cb = new Callback(communicator, true);
            cl.begin_ice_invoke("opString", Ice.OperationMode.Normal, inEncaps).whenCompleted(cb.opStringNC, null);
            cb.check();
        }

        {
            // begin_ice_invoke with no callback
            Ice.AsyncResult result = cl.begin_ice_invoke("opException", Ice.OperationMode.Normal, null);
            byte[] outEncaps;
            if(cl.end_ice_invoke(out outEncaps, result))
            {
                test(false);
            }
            else
            {
                Ice.InputStream inS = new Ice.InputStream(communicator, outEncaps);
                inS.startEncapsulation();
                try
                {
                    inS.throwException();
                }
                catch(Test.MyException)
                {
                    inS.endEncapsulation();
                }
                catch(Exception)
                {
                    test(false);
                }
            }

            // begin_ice_invoke with Callback
            Callback cb = new Callback(communicator, false);
            cl.begin_ice_invoke("opException", Ice.OperationMode.Normal, null, cb.opException, null);
            cb.check();

            // begin_ice_invoke with Callback with cookie
            cb = new Callback(communicator, true);
            cl.begin_ice_invoke("opException", Ice.OperationMode.Normal, null, cb.opException, new Cookie());
            cb.check();

            // begin_ice_invoke with Callback_Object_ice_invoke
            cb = new Callback(communicator, true);
            cl.begin_ice_invoke("opException", Ice.OperationMode.Normal, null).whenCompleted(cb.opExceptionNC, null);
            cb.check();
        }

        WriteLine("ok");
        return cl;
    }
예제 #15
0
파일: AllTests.cs 프로젝트: chuanqingli/ice
            public static Test.MyClassPrx allTests(global::Test.TestHelper helper)
            {
                Ice.Communicator communicator = helper.communicator();
                Ice.ObjectPrx    baseProxy    = communicator.stringToProxy("test:" + helper.getTestEndpoint(0));
                var cl          = Test.MyClassPrxHelper.checkedCast(baseProxy);
                var oneway      = Test.MyClassPrxHelper.uncheckedCast(cl.ice_oneway());
                var batchOneway = Test.MyClassPrxHelper.uncheckedCast(cl.ice_batchOneway());

                var output = helper.getWriter();

                output.Write("testing ice_invoke... ");
                output.Flush();

                {
                    byte[] inEncaps, outEncaps;
                    if (!oneway.ice_invoke("opOneway", Ice.OperationMode.Normal, null, out outEncaps))
                    {
                        test(false);
                    }

                    test(batchOneway.ice_invoke("opOneway", Ice.OperationMode.Normal, null, out outEncaps));
                    test(batchOneway.ice_invoke("opOneway", Ice.OperationMode.Normal, null, out outEncaps));
                    test(batchOneway.ice_invoke("opOneway", Ice.OperationMode.Normal, null, out outEncaps));
                    test(batchOneway.ice_invoke("opOneway", Ice.OperationMode.Normal, null, out outEncaps));
                    batchOneway.ice_flushBatchRequests();

                    Ice.OutputStream outS = new Ice.OutputStream(communicator);
                    outS.startEncapsulation();
                    outS.writeString(testString);
                    outS.endEncapsulation();
                    inEncaps = outS.finished();

                    if (cl.ice_invoke("opString", Ice.OperationMode.Normal, inEncaps, out outEncaps))
                    {
                        Ice.InputStream inS = new Ice.InputStream(communicator, outEncaps);
                        inS.startEncapsulation();
                        string s = inS.readString();
                        test(s.Equals(testString));
                        s = inS.readString();
                        inS.endEncapsulation();
                        test(s.Equals(testString));
                    }
                    else
                    {
                        test(false);
                    }
                }

                for (int i = 0; i < 2; ++i)
                {
                    byte[] outEncaps;
                    Dictionary <string, string> ctx = null;
                    if (i == 1)
                    {
                        ctx          = new Dictionary <string, string>();
                        ctx["raise"] = "";
                    }

                    if (cl.ice_invoke("opException", Ice.OperationMode.Normal, null, out outEncaps, ctx))
                    {
                        test(false);
                    }
                    else
                    {
                        Ice.InputStream inS = new Ice.InputStream(communicator, outEncaps);
                        inS.startEncapsulation();

                        try
                        {
                            inS.throwException();
                        }
                        catch (Test.MyException)
                        {
                            inS.endEncapsulation();
                        }
                        catch (Exception)
                        {
                            test(false);
                        }
                    }
                }

                output.WriteLine("ok");

                output.Write("testing asynchronous ice_invoke with Async Task API... ");
                output.Flush();

                {
                    try
                    {
                        oneway.ice_invokeAsync("opOneway", Ice.OperationMode.Normal, null).Wait();
                    }
                    catch (Exception)
                    {
                        test(false);
                    }

                    Ice.OutputStream outS = new Ice.OutputStream(communicator);
                    outS.startEncapsulation();
                    outS.writeString(testString);
                    outS.endEncapsulation();
                    byte[] inEncaps = outS.finished();

                    // begin_ice_invoke with no callback
                    var result = cl.ice_invokeAsync("opString", Ice.OperationMode.Normal, inEncaps).Result;
                    if (result.returnValue)
                    {
                        Ice.InputStream inS = new Ice.InputStream(communicator, result.outEncaps);
                        inS.startEncapsulation();
                        string s = inS.readString();
                        test(s.Equals(testString));
                        s = inS.readString();
                        inS.endEncapsulation();
                        test(s.Equals(testString));
                    }
                    else
                    {
                        test(false);
                    }
                }

                {
                    var result = cl.ice_invokeAsync("opException", Ice.OperationMode.Normal, null).Result;
                    if (result.returnValue)
                    {
                        test(false);
                    }
                    else
                    {
                        Ice.InputStream inS = new Ice.InputStream(communicator, result.outEncaps);
                        inS.startEncapsulation();
                        try
                        {
                            inS.throwException();
                        }
                        catch (Test.MyException)
                        {
                            inS.endEncapsulation();
                        }
                        catch (Exception)
                        {
                            test(false);
                        }
                    }
                }

                output.WriteLine("ok");

                output.Write("testing asynchronous ice_invoke with AsyncResult API... ");
                output.Flush();

                {
                    byte[]          inEncaps, outEncaps;
                    Ice.AsyncResult result = oneway.begin_ice_invoke("opOneway", Ice.OperationMode.Normal, null);
                    if (!oneway.end_ice_invoke(out outEncaps, result))
                    {
                        test(false);
                    }

                    Ice.OutputStream outS = new Ice.OutputStream(communicator);
                    outS.startEncapsulation();
                    outS.writeString(testString);
                    outS.endEncapsulation();
                    inEncaps = outS.finished();

                    // begin_ice_invoke with no callback
                    result = cl.begin_ice_invoke("opString", Ice.OperationMode.Normal, inEncaps);
                    if (cl.end_ice_invoke(out outEncaps, result))
                    {
                        Ice.InputStream inS = new Ice.InputStream(communicator, outEncaps);
                        inS.startEncapsulation();
                        string s = inS.readString();
                        test(s.Equals(testString));
                        s = inS.readString();
                        inS.endEncapsulation();
                        test(s.Equals(testString));
                    }
                    else
                    {
                        test(false);
                    }

                    // begin_ice_invoke with Callback
                    Callback cb = new Callback(communicator, false);
                    cl.begin_ice_invoke("opString", Ice.OperationMode.Normal, inEncaps, cb.opString, null);
                    cb.check();

                    // begin_ice_invoke with Callback with cookie
                    cb = new Callback(communicator, true);
                    cl.begin_ice_invoke("opString", Ice.OperationMode.Normal, inEncaps, cb.opString, new Cookie());
                    cb.check();

                    // begin_ice_invoke with Callback_Object_ice_invoke
                    cb = new Callback(communicator, true);
                    cl.begin_ice_invoke("opString", Ice.OperationMode.Normal, inEncaps).whenCompleted(cb.opStringNC, null);
                    cb.check();
                }

                {
                    // begin_ice_invoke with no callback
                    Ice.AsyncResult result = cl.begin_ice_invoke("opException", Ice.OperationMode.Normal, null);
                    byte[]          outEncaps;
                    if (cl.end_ice_invoke(out outEncaps, result))
                    {
                        test(false);
                    }
                    else
                    {
                        Ice.InputStream inS = new Ice.InputStream(communicator, outEncaps);
                        inS.startEncapsulation();
                        try
                        {
                            inS.throwException();
                        }
                        catch (Test.MyException)
                        {
                            inS.endEncapsulation();
                        }
                        catch (Exception)
                        {
                            test(false);
                        }
                    }

                    // begin_ice_invoke with Callback
                    Callback cb = new Callback(communicator, false);
                    cl.begin_ice_invoke("opException", Ice.OperationMode.Normal, null, cb.opException, null);
                    cb.check();

                    // begin_ice_invoke with Callback with cookie
                    cb = new Callback(communicator, true);
                    cl.begin_ice_invoke("opException", Ice.OperationMode.Normal, null, cb.opException, new Cookie());
                    cb.check();

                    // begin_ice_invoke with Callback_Object_ice_invoke
                    cb = new Callback(communicator, true);
                    cl.begin_ice_invoke("opException", Ice.OperationMode.Normal, null).whenCompleted(cb.opExceptionNC, null);
                    cb.check();
                }

                output.WriteLine("ok");
                return(cl);
            }
예제 #16
0
    public override bool ice_invoke(byte[] inParams, out byte[] outParams, Ice.Current current)
    {
        outParams = null;

        var communicator = current.adapter.getCommunicator();

        Ice.InputStream inStream = null;
        if(inParams.Length > 0)
        {
            inStream = new Ice.InputStream(communicator, inParams);
            inStream.startEncapsulation();
        }

        if(current.operation.Equals("printString"))
        {
            var message = inStream.readString();
            inStream.endEncapsulation();
            Console.WriteLine("Printing string `" + message + "'");
            return true;
        }
        else if(current.operation.Equals("printStringSequence"))
        {
            var seq = StringSeqHelper.read(inStream);
            inStream.endEncapsulation();
            Console.Write("Printing string sequence {");
            for(int i = 0; i < seq.Length; ++i)
            {
                if(i > 0)
                {
                    Console.Write(", ");
                }
                Console.Write("'" + seq[i] + "'");
            }
            Console.WriteLine("}");
            return true;
        }
        else if(current.operation.Equals("printDictionary"))
        {
            var dict = StringDictHelper.read(inStream);
            inStream.endEncapsulation();
            Console.Write("Printing dictionary {");
            bool first = true;
            foreach(var e in dict)
            {
                if(!first)
                {
                    Console.Write(", ");
                }
                first = false;
                Console.Write(e.Key + "=" + e.Value);
            }
            Console.WriteLine("}");
            return true;
        }
        else if(current.operation.Equals("printEnum"))
        {
            var c = ColorHelper.read(inStream);
            inStream.endEncapsulation();
            Console.WriteLine("Printing enum " + c);
            return true;
        }
        else if(current.operation.Equals("printStruct"))
        {
            var s = Structure.read(inStream);
            inStream.endEncapsulation();
            Console.WriteLine("Printing struct: name=" + s.name + ", value=" + s.value);
            return true;
        }
        else if(current.operation.Equals("printStructSequence"))
        {
            var seq = StructureSeqHelper.read(inStream);
            inStream.endEncapsulation();
            Console.Write("Printing struct sequence: {");
            for(int i = 0; i < seq.Length; ++i)
            {
                if(i > 0)
                {
                    Console.Write(", ");
                }
                Console.Write(seq[i].name + "=" + seq[i].value);
            }
            Console.WriteLine("}");
            return true;
        }
        else if(current.operation.Equals("printClass"))
        {
            var cb = new ReadValueCallback();
            inStream.readValue(cb.invoke);
            inStream.readPendingValues();
            inStream.endEncapsulation();
            var c = cb.obj as C;
            Console.WriteLine("Printing class: s.name=" + c.s.name + ", s.value=" + c.s.value);
            return true;
        }
        else if(current.operation.Equals("getValues"))
        {
            var c = new C(new Structure("green", Color.green));
            var outStream = new Ice.OutputStream(communicator);
            outStream.startEncapsulation();
            outStream.writeValue(c);
            outStream.writeString("hello");
            outStream.writePendingValues();
            outStream.endEncapsulation();
            outParams = outStream.finished();
            return true;
        }
        else if(current.operation.Equals("throwPrintFailure"))
        {
            Console.WriteLine("Throwing PrintFailure");
            var ex = new PrintFailure("paper tray empty");
            var outStream = new Ice.OutputStream(communicator);
            outStream.startEncapsulation();
            outStream.writeException(ex);
            outStream.endEncapsulation();
            outParams = outStream.finished();
            return false;
        }
        else if(current.operation.Equals("shutdown"))
        {
            current.adapter.getCommunicator().shutdown();
            return true;
        }
        else
        {
            throw new Ice.OperationNotExistException(current.id, current.facet, current.operation);
        }
    }