Exemple #1
0
        public void TestInheritedInterfaces()
        {
            var factory = new AdaptiveFactory <Base>();

            factory.ImplementMethods().UsingSharedExecuter("Init", "Exec");

            Type ibase    = factory.Implement(typeof(IBase));
            Type iderived = factory.Implement(typeof(IDerived));

            Assert.AreNotSame(ibase, iderived);
            Assert.IsTrue(typeof(IDisposable).IsAssignableFrom(ibase));
            Assert.IsTrue(typeof(IBase).IsAssignableFrom(ibase));
            Assert.IsTrue(typeof(IBase).IsAssignableFrom(iderived));
            Assert.IsTrue(typeof(IDerived).IsAssignableFrom(iderived));

            using (IBase b = (IBase)Activator.CreateInstance(ibase))
            {
                Assert.IsNotNull(b.DoSomething());
                Assert.AreEqual("DoSomething", b.DoSomething().Name);
            }
            using (IDerived d = (IDerived)Activator.CreateInstance(iderived))
            {
                Assert.AreEqual("DoSomething", d.DoSomething().Name);
                Assert.AreEqual("DoMore", d.DoMore().Name);
            }
        }
Exemple #2
0
    static void Main()
    {
        var      funky = new FunkyImpl();
        IBase    b     = funky;
        IDerived d     = funky;

        b.Process();
        d.Process();
    }
Exemple #3
0
        private Game( GameState gameState )
        {
            this.gameState = gameState;

            currentPlayer = Cell.Derived( DeriveCurrentPlayer );
            board = new Grid<Square>( gameState.Board.Width, gameState.Board.Height, p => new Square( this, p ) );
            stoneCounts = new IDerived<int>[] { Cell.Derived( () => gameState.StoneCount( Player.ONE ) ), Cell.Derived( () => gameState.StoneCount( Player.TWO ) ) };
            isGameOver = Cell.Derived( () => gameState.IsGameOver );
            playerWithMostStones = Cell.Derived( () => gameState.PlayerWithMostStones );
        }
        public void Should_BeAbleTo_Create_NullObjectOf_DerivedInterface_With_BaseMembers()
        {
            IDerived testDerivedInterface = Null.Of <IDerived>();

            Assert.True(testDerivedInterface is IDerived, "Wrong interface generated.");

            testDerivedInterface.String  = "Test";
            testDerivedInterface.Integer = default(int);
            testDerivedInterface.Test();
        }
Exemple #5
0
        static void Main(string[] args)
        {
            var      a = new MyClass();
            IDerived b = a;

            b.Dima();
            ////
            ///
            var d       = new DateTimeProp();
            var newDate = d.MyProperty.AddDays(2.0);

            Console.WriteLine(d.MyProperty + " old date");
            Console.WriteLine(newDate + " new date");
        }
Exemple #6
0
                public static Test.InitialPrx allTests(global::Test.TestHelper helper)
                {
                    Ice.Communicator communicator = helper.communicator();
                    communicator.getValueFactoryManager().add(MyValueFactory, "::Test::B");
                    communicator.getValueFactoryManager().add(MyValueFactory, "::Test::C");
                    communicator.getValueFactoryManager().add(MyValueFactory, "::Test::D");
                    communicator.getValueFactoryManager().add(MyValueFactory, "::Test::E");
                    communicator.getValueFactoryManager().add(MyValueFactory, "::Test::F");
                    communicator.getValueFactoryManager().add(MyValueFactory, "::Test::I");
                    communicator.getValueFactoryManager().add(MyValueFactory, "::Test::J");
                    communicator.getValueFactoryManager().add(MyValueFactory, "::Test::H");

                    // Disable Obsolete warning/error
#pragma warning disable 612, 618
                    communicator.addObjectFactory(new MyObjectFactory(), "TestOF");
#pragma warning restore 612, 618

                    var output = helper.getWriter();

                    output.Write("testing stringToProxy... ");
                    output.Flush();
                    String        @ref  = "initial:" + helper.getTestEndpoint(0);
                    Ice.ObjectPrx @base = communicator.stringToProxy(@ref);
                    test(@base != null);
                    output.WriteLine("ok");

                    output.Write("testing checked cast... ");
                    output.Flush();
                    var initial = Test.InitialPrxHelper.checkedCast(@base);
                    test(initial != null);
                    test(initial.Equals(@base));
                    output.WriteLine("ok");

                    output.Write("getting B1... ");
                    output.Flush();
                    B b1 = initial.getB1();
                    test(b1 != null);
                    output.WriteLine("ok");

                    output.Write("getting B2... ");
                    output.Flush();
                    B b2 = initial.getB2();
                    test(b2 != null);
                    output.WriteLine("ok");

                    output.Write("getting C... ");
                    output.Flush();
                    C c = initial.getC();
                    test(c != null);
                    output.WriteLine("ok");

                    output.Write("getting D... ");
                    output.Flush();
                    D d = initial.getD();
                    test(d != null);
                    output.WriteLine("ok");

                    output.Write("checking consistency... ");
                    output.Flush();
                    test(b1 != b2);
                    //test(b1 != c);
                    //test(b1 != d);
                    //test(b2 != c);
                    //test(b2 != d);
                    //test(c != d);
                    test(b1.theB == b1);
                    test(b1.theC == null);
                    test(b1.theA is B);
                    test(((B)b1.theA).theA == b1.theA);
                    test(((B)b1.theA).theB == b1);
                    //test(((B)b1.theA).theC is C); // Redundant -- theC is always of type C
                    test(((C)(((B)b1.theA).theC)).theB == b1.theA);
                    test(b1.preMarshalInvoked);
                    test(b1.postUnmarshalInvoked);
                    test(b1.theA.preMarshalInvoked);
                    test(b1.theA.postUnmarshalInvoked);
                    test(((B)b1.theA).theC.preMarshalInvoked);
                    test(((B)b1.theA).theC.postUnmarshalInvoked);

                    // More tests possible for b2 and d, but I think this is already
                    // sufficient.
                    test(b2.theA == b2);
                    test(d.theC == null);
                    output.WriteLine("ok");

                    output.Write("getting B1, B2, C, and D all at once... ");
                    output.Flush();
                    B b1out;
                    B b2out;
                    C cout;
                    D dout;
                    initial.getAll(out b1out, out b2out, out cout, out dout);
                    test(b1out != null);
                    test(b2out != null);
                    test(cout != null);
                    test(dout != null);
                    output.WriteLine("ok");

                    output.Write("checking consistency... ");
                    output.Flush();
                    test(b1out != b2out);
                    test(b1out.theA == b2out);
                    test(b1out.theB == b1out);
                    test(b1out.theC == null);
                    test(b2out.theA == b2out);
                    test(b2out.theB == b1out);
                    test(b2out.theC == cout);
                    test(cout.theB == b2out);
                    test(dout.theA == b1out);
                    test(dout.theB == b2out);
                    test(dout.theC == null);
                    test(dout.preMarshalInvoked);
                    test(dout.postUnmarshalInvoked);
                    test(dout.theA.preMarshalInvoked);
                    test(dout.theA.postUnmarshalInvoked);
                    test(dout.theB.preMarshalInvoked);
                    test(dout.theB.postUnmarshalInvoked);
                    test(dout.theB.theC.preMarshalInvoked);
                    test(dout.theB.theC.postUnmarshalInvoked);

                    output.WriteLine("ok");

                    output.Write("testing protected members... ");
                    output.Flush();
                    EI e = (EI)initial.getE();
                    test(e != null && e.checkValues());
                    System.Reflection.BindingFlags flags = System.Reflection.BindingFlags.NonPublic |
                                                           System.Reflection.BindingFlags.Public |
                                                           System.Reflection.BindingFlags.Instance;
                    test(!typeof(E).GetField("i", flags).IsPublic&& !typeof(E).GetField("i", flags).IsPrivate);
                    test(!typeof(E).GetField("s", flags).IsPublic&& !typeof(E).GetField("s", flags).IsPrivate);
                    FI f = (FI)initial.getF();
                    test(f.checkValues());
                    test(((EI)f.e2).checkValues());
                    test(!typeof(F).GetField("e1", flags).IsPublic&& !typeof(F).GetField("e1", flags).IsPrivate);
                    test(typeof(F).GetField("e2", flags).IsPublic&& !typeof(F).GetField("e2", flags).IsPrivate);
                    output.WriteLine("ok");

                    output.Write("getting I, J and H... ");
                    output.Flush();
                    var i = initial.getI();
                    test(i != null);
                    var j = initial.getJ();
                    test(j != null);
                    var h = initial.getH();
                    test(h != null);
                    output.WriteLine("ok");

                    output.Write("getting K... ");
                    {
                        output.Flush();
                        var k = initial.getK();
                        var l = k.value as L;
                        test(l != null);
                        test(l.data.Equals("l"));
                    }
                    output.WriteLine("ok");

                    output.Write("testing Value as parameter... ");
                    output.Flush();
                    {
                        Ice.Value v1 = new L("l");
                        Ice.Value v2;
                        Ice.Value v3 = initial.opValue(v1, out v2);
                        test(((L)v2).data.Equals("l"));
                        test(((L)v3).data.Equals("l"));
                    }
                    {
                        L           l  = new L("l");
                        Ice.Value[] v1 = new Ice.Value[] { l };
                        Ice.Value[] v2;
                        Ice.Value[] v3 = initial.opValueSeq(v1, out v2);
                        test(((L)v2[0]).data.Equals("l"));
                        test(((L)v3[0]).data.Equals("l"));
                    }
                    {
                        L l = new L("l");
                        Dictionary <string, Ice.Value> v1 = new Dictionary <string, Ice.Value> {
                            { "l", l }
                        };
                        Dictionary <string, Ice.Value> v2;
                        Dictionary <string, Ice.Value> v3 = initial.opValueMap(v1, out v2);
                        test(((L)v2["l"]).data.Equals("l"));
                        test(((L)v3["l"]).data.Equals("l"));
                    }
                    output.WriteLine("ok");

                    output.Write("getting D1... ");
                    output.Flush();
                    D1 d1 = new D1(new A1("a1"), new A1("a2"), new A1("a3"), new A1("a4"));
                    d1 = initial.getD1(d1);
                    test(d1.a1.name.Equals("a1"));
                    test(d1.a2.name.Equals("a2"));
                    test(d1.a3.name.Equals("a3"));
                    test(d1.a4.name.Equals("a4"));
                    output.WriteLine("ok");

                    output.Write("throw EDerived... ");
                    output.Flush();
                    try
                    {
                        initial.throwEDerived();
                        test(false);
                    }
                    catch (EDerived ederived)
                    {
                        test(ederived.a1.name.Equals("a1"));
                        test(ederived.a2.name.Equals("a2"));
                        test(ederived.a3.name.Equals("a3"));
                        test(ederived.a4.name.Equals("a4"));
                    }
                    output.WriteLine("ok");

                    output.Write("setting G... ");
                    output.Flush();
                    try
                    {
                        initial.setG(new G(new S("hello"), "g"));
                    }
                    catch (Ice.OperationNotExistException)
                    {
                    }
                    output.WriteLine("ok");

                    output.Write("setting I... ");
                    output.Flush();
                    initial.setI(i);
                    initial.setI(j);
                    initial.setI(h);
                    output.WriteLine("ok");

                    output.Write("testing sequences...");
                    output.Flush();
                    try
                    {
                        Base[] inS = new Test.Base[0];
                        Base[] outS;
                        Base[] retS;
                        retS = initial.opBaseSeq(inS, out outS);

                        inS    = new Test.Base[1];
                        inS[0] = new Test.Base(new S(), "");
                        retS   = initial.opBaseSeq(inS, out outS);
                        test(retS.Length == 1 && outS.Length == 1);
                    }
                    catch (Ice.OperationNotExistException)
                    {
                    }
                    output.WriteLine("ok");

                    output.Write("testing recursive type... ");
                    output.Flush();
                    var top   = new Test.Recursive();
                    var p     = top;
                    int depth = 0;
                    try
                    {
                        for (; depth <= 1000; ++depth)
                        {
                            p.v = new Test.Recursive();
                            p   = p.v;
                            if ((depth < 10 && (depth % 10) == 0) ||
                                (depth < 1000 && (depth % 100) == 0) ||
                                (depth < 10000 && (depth % 1000) == 0) ||
                                (depth % 10000) == 0)
                            {
                                initial.setRecursive(top);
                            }
                        }
                        test(!initial.supportsClassGraphDepthMax());
                    }
                    catch (Ice.UnknownLocalException)
                    {
                        // Expected marshal exception from the server(max class graph depth reached)
                    }
                    catch (Ice.UnknownException)
                    {
                        // Expected stack overflow from the server(Java only)
                    }
                    initial.setRecursive(new Test.Recursive());
                    output.WriteLine("ok");

                    output.Write("testing compact ID...");
                    output.Flush();
                    try
                    {
                        test(initial.getCompact() != null);
                    }
                    catch (Ice.OperationNotExistException)
                    {
                    }
                    output.WriteLine("ok");

                    output.Write("testing marshaled results...");
                    output.Flush();
                    b1 = initial.getMB();
                    test(b1 != null && b1.theB == b1);
                    b1 = initial.getAMDMBAsync().Result;
                    test(b1 != null && b1.theB == b1);
                    output.WriteLine("ok");

                    output.Write("testing UnexpectedObjectException...");
                    output.Flush();
                    @ref  = "uoet:" + helper.getTestEndpoint(0);
                    @base = communicator.stringToProxy(@ref);
                    test(@base != null);
                    var uoet = Test.UnexpectedObjectExceptionTestPrxHelper.uncheckedCast(@base);
                    test(uoet != null);
                    try
                    {
                        uoet.op();
                        test(false);
                    }
                    catch (Ice.UnexpectedObjectException ex)
                    {
                        test(ex.type.Equals("::Test::AlsoEmpty"));
                        test(ex.expectedType.Equals("::Test::Empty"));
                    }
                    catch (System.Exception ex)
                    {
                        output.WriteLine(ex.ToString());
                        test(false);
                    }
                    output.WriteLine("ok");

                    // Disable Obsolete warning/error
#pragma warning disable 612, 618
                    output.Write("testing getting ObjectFactory...");
                    output.Flush();
                    test(communicator.findObjectFactory("TestOF") != null);
                    output.WriteLine("ok");
                    output.Write("testing getting ObjectFactory as ValueFactory...");
                    output.Flush();
                    test(communicator.getValueFactoryManager().find("TestOF") != null);
                    output.WriteLine("ok");
#pragma warning restore 612, 618

                    output.Write("testing partial ice_initialize...");
                    output.Flush();
                    var ib1 = new IBase();
                    test(ib1.id.Equals("My id"));
                    var id1 = new IDerived();
                    test(id1.id.Equals("My id"));
                    test(id1.name.Equals("My name"));

                    var id2 = new Test.IDerived2();
                    test(id2.id.Equals("My id"));
                    var i2 = new I2();
                    test(i2.called);

                    var s1 = new S1();
                    // The struct default constructor do not call ice_initialize
                    test(s1.id == 0);
                    s1 = new S1(2);
                    // The id should have the value set by ice_initialize and not 2
                    test(s1.id == 1);

                    var sc1 = new SC1();
                    test(sc1.id.Equals("My id"));
                    output.WriteLine("ok");

                    output.Write("testing class containing complex dictionary... ");
                    output.Flush();
                    {
                        var m = new Test.M();
                        m.v = new Dictionary <StructKey, L>();
                        var k1 = new StructKey(1, "1");
                        m.v[k1] = new L("one");
                        var k2 = new StructKey(2, "2");
                        m.v[k2] = new L("two");
                        Test.M m1;
                        var    m2 = initial.opM(m, out m1);
                        test(m1.v.Count == 2);
                        test(m2.v.Count == 2);

                        test(m1.v[k1].data.Equals("one"));
                        test(m2.v[k1].data.Equals("one"));

                        test(m1.v[k2].data.Equals("two"));
                        test(m2.v[k2].data.Equals("two"));
                    }
                    output.WriteLine("ok");

                    output.Write("testing forward declared types... ");
                    output.Flush();
                    {
                        F1 f12;
                        F1 f11 = initial.opF1(new F1("F11"), out f12);
                        test(f11.name.Equals("F11"));
                        test(f12.name.Equals("F12"));

                        F2Prx f22;
                        F2Prx f21 = initial.opF2(
                            F2PrxHelper.uncheckedCast(communicator.stringToProxy("F21:" + helper.getTestEndpoint())),
                            out f22);
                        test(f21.ice_getIdentity().name.Equals("F21"));
                        f21.op();
                        test(f22.ice_getIdentity().name.Equals("F22"));

                        if (initial.hasF3())
                        {
                            F3 f32;
                            F3 f31 = initial.opF3(new F3(new F1("F11"),
                                                         F2PrxHelper.uncheckedCast(communicator.stringToProxy("F21"))),
                                                  out f32);

                            test(f31.f1.name.Equals("F11"));
                            test(f31.f2.ice_getIdentity().name.Equals("F21"));

                            test(f32.f1.name.Equals("F12"));
                            test(f32.f2.ice_getIdentity().name.Equals("F22"));
                        }
                    }
                    output.WriteLine("ok");

                    output.Write("testing sending class cycle... ");
                    output.Flush();
                    {
                        var rec = new Test.Recursive();
                        rec.v = rec;
                        var acceptsCycles = initial.acceptsClassCycles();
                        try
                        {
                            initial.setCycle(rec);
                            test(acceptsCycles);
                        }
                        catch (Ice.UnknownLocalException)
                        {
                            test(!acceptsCycles);
                        }
                    }
                    output.WriteLine("ok");

                    return(initial);
                }
Exemple #7
0
    public static InitialPrx allTests(TestCommon.Application app)
    {
        Ice.Communicator communicator = app.communicator();
        communicator.getValueFactoryManager().add(MyValueFactory, "::Test::B");
        communicator.getValueFactoryManager().add(MyValueFactory, "::Test::C");
        communicator.getValueFactoryManager().add(MyValueFactory, "::Test::D");
        communicator.getValueFactoryManager().add(MyValueFactory, "::Test::E");
        communicator.getValueFactoryManager().add(MyValueFactory, "::Test::F");
        communicator.getValueFactoryManager().add(MyValueFactory, "::Test::I");
        communicator.getValueFactoryManager().add(MyValueFactory, "::Test::J");
        communicator.getValueFactoryManager().add(MyValueFactory, "::Test::H");

// Disable Obsolete warning/error
#pragma warning disable 612, 618
        communicator.addObjectFactory(new MyObjectFactory(), "TestOF");
#pragma warning restore 612, 618

        Write("testing stringToProxy... ");
        Flush();
        String        @ref  = "initial:" + app.getTestEndpoint(0);
        Ice.ObjectPrx @base = communicator.stringToProxy(@ref);
        test(@base != null);
        WriteLine("ok");

        Write("testing checked cast... ");
        Flush();
        InitialPrx initial = InitialPrxHelper.checkedCast(@base);
        test(initial != null);
        test(initial.Equals(@base));
        WriteLine("ok");

        Write("getting B1... ");
        Flush();
        B b1 = initial.getB1();
        test(b1 != null);
        WriteLine("ok");

        Write("getting B2... ");
        Flush();
        B b2 = initial.getB2();
        test(b2 != null);
        WriteLine("ok");

        Write("getting C... ");
        Flush();
        C c = initial.getC();
        test(c != null);
        WriteLine("ok");

        Write("getting D... ");
        Flush();
        D d = initial.getD();
        test(d != null);
        WriteLine("ok");

        Write("checking consistency... ");
        Flush();
        test(b1 != b2);
        //test(b1 != c);
        //test(b1 != d);
        //test(b2 != c);
        //test(b2 != d);
        //test(c != d);
        test(b1.theB == b1);
        test(b1.theC == null);
        test(b1.theA is B);
        test(((B)b1.theA).theA == b1.theA);
        test(((B)b1.theA).theB == b1);
        //test(((B)b1.theA).theC is C); // Redundant -- theC is always of type C
        test(((C)(((B)b1.theA).theC)).theB == b1.theA);
        test(b1.preMarshalInvoked);
        test(b1.postUnmarshalInvoked);
        test(b1.theA.preMarshalInvoked);
        test(b1.theA.postUnmarshalInvoked);
        test(((B)b1.theA).theC.preMarshalInvoked);
        test(((B)b1.theA).theC.postUnmarshalInvoked);

        // More tests possible for b2 and d, but I think this is already
        // sufficient.
        test(b2.theA == b2);
        test(d.theC == null);
        WriteLine("ok");

        Write("getting B1, B2, C, and D all at once... ");
        Flush();
        B b1out;
        B b2out;
        C cout;
        D dout;
        initial.getAll(out b1out, out b2out, out cout, out dout);
        test(b1out != null);
        test(b2out != null);
        test(cout != null);
        test(dout != null);
        WriteLine("ok");

        Write("checking consistency... ");
        Flush();
        test(b1out != b2out);
        test(b1out.theA == b2out);
        test(b1out.theB == b1out);
        test(b1out.theC == null);
        test(b2out.theA == b2out);
        test(b2out.theB == b1out);
        test(b2out.theC == cout);
        test(cout.theB == b2out);
        test(dout.theA == b1out);
        test(dout.theB == b2out);
        test(dout.theC == null);
        test(dout.preMarshalInvoked);
        test(dout.postUnmarshalInvoked);
        test(dout.theA.preMarshalInvoked);
        test(dout.theA.postUnmarshalInvoked);
        test(dout.theB.preMarshalInvoked);
        test(dout.theB.postUnmarshalInvoked);
        test(dout.theB.theC.preMarshalInvoked);
        test(dout.theB.theC.postUnmarshalInvoked);

        WriteLine("ok");

        Write("testing protected members... ");
        Flush();
        EI e = (EI)initial.getE();
        test(e != null && e.checkValues());
        System.Reflection.BindingFlags flags = System.Reflection.BindingFlags.NonPublic |
                                               System.Reflection.BindingFlags.Public |
                                               System.Reflection.BindingFlags.Instance;
        test(!typeof(E).GetField("i", flags).IsPublic&& !typeof(E).GetField("i", flags).IsPrivate);
        test(!typeof(E).GetField("s", flags).IsPublic&& !typeof(E).GetField("s", flags).IsPrivate);
        FI f = (FI)initial.getF();
        test(f.checkValues());
        test(((EI)f.e2).checkValues());
        test(!typeof(F).GetField("e1", flags).IsPublic&& !typeof(F).GetField("e1", flags).IsPrivate);
        test(typeof(F).GetField("e2", flags).IsPublic&& !typeof(F).GetField("e2", flags).IsPrivate);
        WriteLine("ok");

        Write("getting I, J and H... ");
        Flush();
        var i = initial.getI();
        test(i != null);
        var j = initial.getJ();
        test(j != null);
        var h = initial.getH();
        test(h != null);
        WriteLine("ok");

        Write("getting D1... ");
        Flush();
        D1 d1 = new D1(new A1("a1"), new A1("a2"), new A1("a3"), new A1("a4"));
        d1 = initial.getD1(d1);
        test(d1.a1.name.Equals("a1"));
        test(d1.a2.name.Equals("a2"));
        test(d1.a3.name.Equals("a3"));
        test(d1.a4.name.Equals("a4"));
        WriteLine("ok");

        Write("throw EDerived... ");
        Flush();
        try
        {
            initial.throwEDerived();
            test(false);
        }
        catch (EDerived ederived)
        {
            test(ederived.a1.name.Equals("a1"));
            test(ederived.a2.name.Equals("a2"));
            test(ederived.a3.name.Equals("a3"));
            test(ederived.a4.name.Equals("a4"));
        }
        WriteLine("ok");

        Write("setting G... ");
        Flush();
        try
        {
            initial.setG(new G(new S("hello"), "g"));
        }
        catch (Ice.OperationNotExistException)
        {
        }
        WriteLine("ok");

        Write("setting I... ");
        Flush();
        initial.setI(i);
        initial.setI(j);
        initial.setI(h);
        WriteLine("ok");

        Write("testing sequences...");
        Flush();
        try
        {
            Base[] inS = new Base[0];
            Base[] outS;
            Base[] retS;
            retS = initial.opBaseSeq(inS, out outS);

            inS    = new Base[1];
            inS[0] = new Base(new S(), "");
            retS   = initial.opBaseSeq(inS, out outS);
            test(retS.Length == 1 && outS.Length == 1);
        }
        catch (Ice.OperationNotExistException)
        {
        }
        WriteLine("ok");

        Write("testing recursive type... ");
        Flush();
        Recursive top   = new Recursive();
        Recursive p     = top;
        int       depth = 0;
        try
        {
            for (; depth <= 1000; ++depth)
            {
                p.v = new Recursive();
                p   = p.v;
                if ((depth < 10 && (depth % 10) == 0) ||
                    (depth < 1000 && (depth % 100) == 0) ||
                    (depth < 10000 && (depth % 1000) == 0) ||
                    (depth % 10000) == 0)
                {
                    initial.setRecursive(top);
                }
            }
            test(!initial.supportsClassGraphDepthMax());
        }
        catch (Ice.UnknownLocalException)
        {
            // Expected marshal exception from the server (max class graph depth reached)
        }
        catch (Ice.UnknownException)
        {
            // Expected stack overflow from the server (Java only)
        }
        initial.setRecursive(new Recursive());
        WriteLine("ok");

        Write("testing compact ID...");
        Flush();
        try
        {
            test(initial.getCompact() != null);
        }
        catch (Ice.OperationNotExistException)
        {
        }
        WriteLine("ok");

        Write("testing marshaled results...");
        Flush();
        b1 = initial.getMB();
        test(b1 != null && b1.theB == b1);
        b1 = initial.getAMDMBAsync().Result;
        test(b1 != null && b1.theB == b1);
        WriteLine("ok");

        Write("testing UnexpectedObjectException...");
        Flush();
        @ref  = "uoet:" + app.getTestEndpoint(0);
        @base = communicator.stringToProxy(@ref);
        test(@base != null);
        UnexpectedObjectExceptionTestPrx uoet = UnexpectedObjectExceptionTestPrxHelper.uncheckedCast(@base);
        test(uoet != null);
        try
        {
            uoet.op();
            test(false);
        }
        catch (Ice.UnexpectedObjectException ex)
        {
            test(ex.type.Equals("::Test::AlsoEmpty"));
            test(ex.expectedType.Equals("::Test::Empty"));
        }
        catch (System.Exception ex)
        {
            WriteLine(ex.ToString());
            test(false);
        }
        WriteLine("ok");

// Disable Obsolete warning/error
#pragma warning disable 612, 618
        Write("testing getting ObjectFactory...");
        Flush();
        test(communicator.findObjectFactory("TestOF") != null);
        WriteLine("ok");
        Write("testing getting ObjectFactory as ValueFactory...");
        Flush();
        test(communicator.getValueFactoryManager().find("TestOF") != null);
        WriteLine("ok");
#pragma warning restore 612, 618

        Write("testing partial ice_initialize...");
        Flush();
        var ib1 = new IBase();
        test(ib1.id.Equals("My id"));
        var id1 = new IDerived();
        test(id1.id.Equals("My id"));
        test(id1.name.Equals("My name"));

        var id2 = new IDerived2();
        test(id2.id.Equals("My id"));
        var i2 = new I2();
        test(i2.called);

        var s1 = new S1();
        // The struct default constructor do not call ice_initialize
        test(s1.id == 0);
        s1 = new S1(2);
        // The id should have the value set by ice_initialize and not 2
        test(s1.id == 1);

        var sc1 = new SC1();
        test(sc1.id.Equals("My id"));
        WriteLine("ok");
        return(initial);
    }
Exemple #8
0
                public static Test.IInitialPrx allTests(global::Test.TestHelper helper)
                {
                    Ice.Communicator communicator = helper.communicator();

                    var output = helper.getWriter();

                    var initial = IInitialPrx.Parse($"initial:{helper.getTestEndpoint(0)}", communicator);

                    output.Write("getting B1... ");
                    output.Flush();
                    B b1 = initial.getB1();

                    test(b1 != null);
                    output.WriteLine("ok");

                    output.Write("getting B2... ");
                    output.Flush();
                    B b2 = initial.getB2();

                    test(b2 != null);
                    output.WriteLine("ok");

                    output.Write("getting C... ");
                    output.Flush();
                    C c = initial.getC();

                    test(c != null);
                    output.WriteLine("ok");

                    output.Write("getting D... ");
                    output.Flush();
                    D d = initial.getD();

                    test(d != null);
                    output.WriteLine("ok");

                    output.Write("checking consistency... ");
                    output.Flush();
                    test(b1 != b2);
                    //test(b1 != c);
                    //test(b1 != d);
                    //test(b2 != c);
                    //test(b2 != d);
                    //test(c != d);
                    test(b1.theB == b1);
                    test(b1.theC == null);
                    test(b1.theA is B);
                    test(((B)b1.theA).theA == b1.theA);
                    test(((B)b1.theA).theB == b1);
                    //test(((B)b1.theA).theC is C); // Redundant -- theC is always of type C
                    test(((C)(((B)b1.theA).theC)).theB == b1.theA);

                    // More tests possible for b2 and d, but I think this is already
                    // sufficient.
                    test(b2.theA == b2);
                    test(d.theC == null);
                    output.WriteLine("ok");

                    output.Write("getting B1, B2, C, and D all at once... ");
                    output.Flush();
                    var(b1out, b2out, cout, dout) = initial.getAll();
                    test(b1out != null);
                    test(b2out != null);
                    test(cout != null);
                    test(dout != null);
                    output.WriteLine("ok");

                    output.Write("checking consistency... ");
                    output.Flush();
                    test(b1out != b2out);
                    test(b1out.theA == b2out);
                    test(b1out.theB == b1out);
                    test(b1out.theC == null);
                    test(b2out.theA == b2out);
                    test(b2out.theB == b1out);
                    test(b2out.theC == cout);
                    test(cout.theB == b2out);
                    test(dout.theA == b1out);
                    test(dout.theB == b2out);
                    test(dout.theC == null);

                    output.WriteLine("ok");

                    output.Write("getting K... ");
                    {
                        output.Flush();
                        var k = initial.getK();
                        var l = k.value as L;
                        test(l != null);
                        test(l.data.Equals("l"));
                    }
                    output.WriteLine("ok");

                    output.Write("testing AnyClass as parameter... ");
                    output.Flush();
                    {
                        AnyClass v1 = new L("l");
                        var(v3, v2) = initial.opClass(v1);
                        test(((L)v2).data.Equals("l"));
                        test(((L)v3).data.Equals("l"));
                    }
                    {
                        L          l  = new L("l");
                        AnyClass[] v1 = new AnyClass[] { l };
                        var(v3, v2) = initial.opClassSeq(v1);
                        test(((L)v2[0]).data.Equals("l"));
                        test(((L)v3[0]).data.Equals("l"));
                    }
                    {
                        L l = new L("l");
                        Dictionary <string, AnyClass> v1 = new Dictionary <string, AnyClass> {
                            { "l", l }
                        };
                        var(v3, v2) = initial.opClassMap(v1);
                        test(((L)v2["l"]).data.Equals("l"));
                        test(((L)v3["l"]).data.Equals("l"));
                    }
                    output.WriteLine("ok");

                    output.Write("getting D1... ");
                    output.Flush();
                    D1 d1 = new D1(new A1("a1"), new A1("a2"), new A1("a3"), new A1("a4"));

                    d1 = initial.getD1(d1);
                    test(d1.a1.name.Equals("a1"));
                    test(d1.a2.name.Equals("a2"));
                    test(d1.a3.name.Equals("a3"));
                    test(d1.a4.name.Equals("a4"));
                    output.WriteLine("ok");

                    output.Write("throw EDerived... ");
                    output.Flush();
                    try
                    {
                        initial.throwEDerived();
                        test(false);
                    }
                    catch (EDerived ederived)
                    {
                        test(ederived.a1.name.Equals("a1"));
                        test(ederived.a2.name.Equals("a2"));
                        test(ederived.a3.name.Equals("a3"));
                        test(ederived.a4.name.Equals("a4"));
                    }
                    output.WriteLine("ok");

                    output.Write("setting G... ");
                    output.Flush();
                    try
                    {
                        initial.setG(new G(new S("hello"), "g"));
                    }
                    catch (Ice.OperationNotExistException)
                    {
                    }
                    output.WriteLine("ok");

                    output.Write("testing sequences...");
                    output.Flush();
                    try
                    {
                        Base[] inS = new Base[0];
                        var(retS, outS) = initial.opBaseSeq(inS);

                        inS          = new Base[1];
                        inS[0]       = new Base(new S(""), "");
                        (retS, outS) = initial.opBaseSeq(inS);
                        test(retS.Length == 1 && outS.Length == 1);
                    }
                    catch (Ice.OperationNotExistException)
                    {
                    }
                    output.WriteLine("ok");

                    output.Write("testing recursive type... ");
                    output.Flush();
                    var top   = new Test.Recursive();
                    var p     = top;
                    int depth = 0;

                    try
                    {
                        for (; depth <= 1000; ++depth)
                        {
                            p.v = new Test.Recursive();
                            p   = p.v;
                            if ((depth < 10 && (depth % 10) == 0) ||
                                (depth < 1000 && (depth % 100) == 0) ||
                                (depth < 10000 && (depth % 1000) == 0) ||
                                (depth % 10000) == 0)
                            {
                                initial.setRecursive(top);
                            }
                        }
                        test(!initial.supportsClassGraphDepthMax());
                    }
                    catch (Ice.UnknownLocalException)
                    {
                        // Expected marshal exception from the server(max class graph depth reached)
                    }
                    catch (Ice.UnknownException)
                    {
                        // Expected stack overflow from the server(Java only)
                    }
                    initial.setRecursive(new Test.Recursive());
                    output.WriteLine("ok");

                    output.Write("testing compact ID...");
                    output.Flush();
                    try
                    {
                        test(initial.getCompact() != null);
                    }
                    catch (Ice.OperationNotExistException)
                    {
                    }
                    output.WriteLine("ok");

                    output.Write("testing marshaled results...");
                    output.Flush();
                    b1 = initial.getMB();
                    test(b1 != null && b1.theB == b1);
                    b1 = initial.getAMDMBAsync().Result;
                    test(b1 != null && b1.theB == b1);
                    output.WriteLine("ok");

                    output.Write("testing UnexpectedObjectException...");
                    output.Flush();
                    var uoet = IUnexpectedObjectExceptionTestPrx.Parse($"uoet:{helper.getTestEndpoint(0)}", communicator);

                    try
                    {
                        uoet.op();
                        test(false);
                    }
                    catch (UnexpectedObjectException ex)
                    {
                        test(ex.Type.Equals("::Test::AlsoEmpty"));
                        test(ex.ExpectedType.Equals("::Test::Empty"));
                    }
                    catch (System.Exception ex)
                    {
                        output.WriteLine(ex.ToString());
                        test(false);
                    }
                    output.WriteLine("ok");

                    output.Write("testing partial ice_initialize...");
                    output.Flush();
                    var ib1 = new IBase();

                    test(ib1.id.Equals("My id"));
                    var id1 = new IDerived();

                    test(id1.id.Equals("My id"));
                    test(id1.name.Equals("My name"));

                    var id2 = new Test.IDerived2();

                    test(id2.id.Equals("My id"));
                    var i2 = new I2();

                    test(i2.called);

                    var s1 = new S1();

                    // The struct default constructor do not call ice_initialize
                    test(s1.id == 0);
                    s1 = new S1(2);
                    // The id should have the value set by ice_initialize and not 2
                    test(s1.id == 1);

                    output.WriteLine("ok");

                    output.Write("testing class containing complex dictionary... ");
                    output.Flush();
                    {
                        var m = new Test.M();
                        m.v = new Dictionary <StructKey, L>();
                        var k1 = new StructKey(1, "1");
                        m.v[k1] = new L("one");
                        var k2 = new StructKey(2, "2");
                        m.v[k2]     = new L("two");
                        var(m2, m1) = initial.opM(m);
                        test(m1.v.Count == 2);
                        test(m2.v.Count == 2);

                        test(m1.v[k1].data.Equals("one"));
                        test(m2.v[k1].data.Equals("one"));

                        test(m1.v[k2].data.Equals("two"));
                        test(m2.v[k2].data.Equals("two"));
                    }
                    output.WriteLine("ok");

                    output.Write("testing forward declared types... ");
                    output.Flush();
                    {
                        var(f11, f12) = initial.opF1(new F1("F11"));
                        test(f11.name.Equals("F11"));
                        test(f12.name.Equals("F12"));

                        var(f21, f22) = initial.opF2(IF2Prx.Parse($"F21:{helper.getTestEndpoint()}", communicator));
                        test(f21.Identity.Name.Equals("F21"));
                        f21.op();
                        test(f22.Identity.Name.Equals("F22"));

                        if (initial.hasF3())
                        {
                            var(f31, f32) = initial.opF3(new F3(new F1("F11"), IF2Prx.Parse("F21", communicator)));

                            test(f31.f1.name.Equals("F11"));
                            test(f31.f2.Identity.Name.Equals("F21"));

                            test(f32.f1.name.Equals("F12"));
                            test(f32.f2.Identity.Name.Equals("F22"));
                        }
                    }
                    output.WriteLine("ok");

                    return(initial);
                }
Exemple #9
0
        public static void TestUniversalGenericThatDerivesFromBaseInstantiatedOverArray()
        {
            string s = null;

            // Root derived types (these types cause the virtual methods to not be in the sealed vtable)
            new OtherDerivedType <string>().BaseMethod(new string[] { "s" }, ref s);
            new OtherDerivedType <string>().MiddleMethod("s", ref s);
            new OtherDerivedTypeLeadingToNonSharedGenerics <short>().BaseMethod(123, ref s);
            new OtherDerivedTypeLeadingToNonSharedGenerics <short>().MiddleMethod(123, ref s);
            new OtherDerivedTypeWithTwoArgs <string, string>().BaseMethod(new string[] { "s" }, ref s);
            new OtherDerivedTypeWithTwoArgs <string, string>().MiddleMethod("s", ref s);
            new OtherDerivedTypeWithTwoArgsLeadingToPartialAndNonShared <string, string>().BaseMethod(11, ref s);
            new OtherDerivedTypeWithTwoArgsLeadingToPartialAndNonShared <string, string>().MiddleMethod("s", ref s);

            Assert.AreEqual(typeof(PartialUniversalGen.DerivedWithArray <>).Name, TypeOf.PUG_DerivedWithArray.Name);

            {
                var              t = TypeOf.PUG_DerivedWithArray.MakeGenericType(TypeOf.Short);
                IBase <short[]>  b = (IBase <short[]>)Activator.CreateInstance(t);
                IMiddle <short>  m = (IMiddle <short>)b;
                IDerived <short> d = (IDerived <short>)b;

                Assert.AreEqual(typeof(short[][]), b.BaseMethod(new short[0], ref s).GetType());
                Assert.AreEqual("BaseMethod", s);
                Assert.AreEqual(typeof(short[]), m.MiddleMethod(2, ref s).GetType());
                Assert.AreEqual("MiddleMethod", s);
                Assert.AreEqual(typeof(short[]), d.DerivedMethod(1, ref s).GetType());
                Assert.AreEqual("DerivedMethod", s);
            }

            {
                var             t = typeof(DerivedWithNonSharedGenerics <>).MakeGenericType(TypeOf.Long);
                IBase <int>     b = (IBase <int>)Activator.CreateInstance(t);
                IMiddle <long>  m = (IMiddle <long>)b;
                IDerived <long> d = (IDerived <long>)b;

                Assert.AreEqual(typeof(int[]), b.BaseMethod(123, ref s).GetType());
                Assert.AreEqual("BaseMethod", s);
                Assert.AreEqual(typeof(long[]), m.MiddleMethod(2, ref s).GetType());
                Assert.AreEqual("MiddleMethod", s);
                Assert.AreEqual(typeof(long[]), d.DerivedMethod(1, ref s).GetType());
                Assert.AreEqual("DerivedMethod", s);
            }

            {
                var              t = typeof(DerivedWithArrayWithTwoArgs <,>).MakeGenericType(TypeOf.Float, TypeOf.Float);
                IBase <float[]>  b = (IBase <float[]>)Activator.CreateInstance(t);
                IMiddle <float>  m = (IMiddle <float>)b;
                IDerived <float> d = (IDerived <float>)b;

                Assert.AreEqual(typeof(float[][]), b.BaseMethod(new float[0], ref s).GetType());
                Assert.AreEqual("BaseMethod", s);
                Assert.AreEqual(typeof(float[]), m.MiddleMethod(2.0f, ref s).GetType());
                Assert.AreEqual("MiddleMethod", s);
                Assert.AreEqual(typeof(float[]), d.DerivedMethod(1.0f, ref s).GetType());
                Assert.AreEqual("DerivedMethod", s);
            }

            {
                var               t = typeof(DerivedWithArrayWithTwoArgsLeadingToPartialAndNonShared <,>).MakeGenericType(TypeOf.Double, TypeOf.Double);
                IBase <int>       b = (IBase <int>)Activator.CreateInstance(t);
                IMiddle <double>  m = (IMiddle <double>)b;
                IDerived <double> d = (IDerived <double>)b;

                Assert.AreEqual(typeof(int[]), b.BaseMethod(11, ref s).GetType());
                Assert.AreEqual("BaseMethod", s);
                Assert.AreEqual(typeof(double[]), m.MiddleMethod(2.0, ref s).GetType());
                Assert.AreEqual("MiddleMethod", s);
                Assert.AreEqual(typeof(double[]), d.DerivedMethod(1.0, ref s).GetType());
                Assert.AreEqual("DerivedMethod", s);
            }
        }
 public static int TransformID2(IDerived obj)
 {
     return obj.ID * obj.ID2;
 }
Exemple #11
0
 public Square( Game game, Vector2D position )
 {
     this.game = game;
     this.position = position;
     this.owner = Cell.Derived( () => game.GetOwnerAt( position ) );
     this.isValidMove = Cell.Derived( () => game.IsValidMove( position ) );
 }
 static void M(IDerived obj)
 {
     obj.Y();  // allowed; IDerived has two Y, but one hides the other
 }
Exemple #13
0
        static void Main(string[] args)
        {
            // Create an IDerived reference to a Thing.
            // IDerived is an interface that "inherits" from IBase via
            // interface inheritance.
            Console.WriteLine("Pass a derived interface object "
                              + "through a base interface parameter: ");
            IDerived id = (IDerived) new Thing();

            // Now try to pass id through a reference to IBase (not IDerived).
            TestInheritedInterfacePassing(id);

            Console.WriteLine("\nYou can add an IDerived object to an IBase collection.");
            List <IBase> bases = new List <IBase>();

            bases.Add(id);
            Console.WriteLine("After adding an IDerived item, collection length is {0}.",
                              bases.Count);
            Console.WriteLine();

            // "Polymorphic" behavior is different for classes and interfaces.

            Console.WriteLine("\nDemonstrating class polymorphism.");
            Thing t = new Thing();

            // Install an instance of the derived class in t.
            t = new ThingDerived();
            // OK to call Thing method through Thing reference
            // even though the reference points to a ThingDerived object.
            // ThingDerived inherits Thing.SayHello().
            Console.Write("Calling base method through base class reference: ");
            t.SayHello();
            // Also OK to call ThingDerived method through Thing
            // reference.
            Console.WriteLine("Calling derived method through base class reference: {0}",
                              t.GetValue());
            ThingDerived td = new ThingDerived();

            Console.Write("Calling base method through derived object: ");
            td.SayHello();
            Console.WriteLine("Calling derived method through derived object: {0}",
                              td.GetValue());

            Console.WriteLine("\nDemonstrating interface 'polymorphism.'");
            // Thing implements IBase, so this cast is fine.
            IBase ib = (IBase) new Thing();

            // OK to call SayHello() through the interface because
            // Thing implements IBase's SayHello() method.
            Console.Write("Calling base method through derived interface reference: ");
            ib.SayHello();
            // Install an IDerived in the IBase reference.
            ib = (IDerived)ib;
            Console.Write("Attempting to call derived method through base reference ...");
            // The following doesn't compile because
            // ib knows nothing about IDerived.GetValue().
            //ib.GetValue();
            Console.WriteLine(" fails.");
            // Cast the base reference to a derived reference.
            IDerived id2 = (IDerived)ib;

            // However, this works because IDerived defines GetValue().
            Console.WriteLine("Calling derived method through converted base reference: {0}",
                              id2.GetValue());

            Console.WriteLine("Press Enter to terminate...");
            Console.Read();
        }
Exemple #14
0
 public EitherDerived(IDerived derived)
 {
     this.derived   = derived;
     this.isComplex = false;
 }
Exemple #15
0
 public static void TakeDerivedRef(ref IDerived argument)
 {
 }
Exemple #16
0
 public static void TakeDerived(IDerived argument)
 {
 }