diff options
Diffstat (limited to 'csharp/test/Ice/objects/AllTests.cs')
-rw-r--r-- | csharp/test/Ice/objects/AllTests.cs | 214 |
1 files changed, 119 insertions, 95 deletions
diff --git a/csharp/test/Ice/objects/AllTests.cs b/csharp/test/Ice/objects/AllTests.cs index 44c065414ab..d050088c288 100644 --- a/csharp/test/Ice/objects/AllTests.cs +++ b/csharp/test/Ice/objects/AllTests.cs @@ -11,121 +11,128 @@ using System; using System.Diagnostics; using Test; -#if SILVERLIGHT -using System.Windows.Controls; -#endif - -public class AllTests : TestCommon.TestApp +public class AllTests : TestCommon.AllTests { + public static Ice.Value MyValueFactory(string type) + { + if (type.Equals("::Test::B")) + { + return new BI(); + } + else if (type.Equals("::Test::C")) + { + return new CI(); + } + else if (type.Equals("::Test::D")) + { + return new DI(); + } + else if (type.Equals("::Test::E")) + { + return new EI(); + } + else if (type.Equals("::Test::F")) + { + return new FI(); + } + else if (type.Equals("::Test::I")) + { + return new II(); + } + else if (type.Equals("::Test::J")) + { + return new JI(); + } + else if (type.Equals("::Test::H")) + { + return new HI(); + } + Debug.Assert(false); // Should never be reached + return null; + } + private class MyObjectFactory : Ice.ObjectFactory { - public Ice.Object create(string type) + public MyObjectFactory() + { + _destroyed = false; + } + + ~MyObjectFactory() + { + Debug.Assert(_destroyed); + } + + public Ice.Value create(string type) { - if (type.Equals("::Test::B")) - { - return new BI(); - } - else if (type.Equals("::Test::C")) - { - return new CI(); - } - else if (type.Equals("::Test::D")) - { - return new DI(); - } - else if (type.Equals("::Test::E")) - { - return new EI(); - } - else if (type.Equals("::Test::F")) - { - return new FI(); - } - else if (type.Equals("::Test::I")) - { - return new II(); - } - else if (type.Equals("::Test::J")) - { - return new JI(); - } - else if (type.Equals("::Test::H")) - { - return new HI(); - } - Debug.Assert(false); // Should never be reached return null; } public void destroy() { - // Nothing to do + _destroyed = true; } - } -#if SILVERLIGHT - public override Ice.InitializationData initData() - { - Ice.InitializationData initData = new Ice.InitializationData(); - initData.properties = Ice.Util.createProperties(); - initData.properties.setProperty("Ice.FactoryAssemblies", "objects,version=1.0.0.0"); - return initData; + + private bool _destroyed; } - override - public void run(Ice.Communicator communicator) -#else - public static InitialPrx allTests(Ice.Communicator communicator) -#endif + public static InitialPrx allTests(TestCommon.Application app) { - Ice.ObjectFactory factory = new MyObjectFactory(); - communicator.addObjectFactory(factory, "::Test::B"); - communicator.addObjectFactory(factory, "::Test::C"); - communicator.addObjectFactory(factory, "::Test::D"); - communicator.addObjectFactory(factory, "::Test::E"); - communicator.addObjectFactory(factory, "::Test::F"); - communicator.addObjectFactory(factory, "::Test::I"); - communicator.addObjectFactory(factory, "::Test::J"); - communicator.addObjectFactory(factory, "::Test::H"); + 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:default -p 12010"; + 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); @@ -142,18 +149,18 @@ public class AllTests : TestCommon.TestApp //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.postUnmarshalInvoked); test(b1.theA.preMarshalInvoked); - test(b1.theA.postUnmarshalInvoked()); + test(b1.theA.postUnmarshalInvoked); test(((B)b1.theA).theC.preMarshalInvoked); - test(((B)b1.theA).theC.postUnmarshalInvoked()); + 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; @@ -166,7 +173,7 @@ public class AllTests : TestCommon.TestApp test(cout != null); test(dout != null); WriteLine("ok"); - + Write("checking consistency... "); Flush(); test(b1out != b2out); @@ -181,42 +188,42 @@ public class AllTests : TestCommon.TestApp test(dout.theB == b2out); test(dout.theC == null); test(dout.preMarshalInvoked); - test(dout.postUnmarshalInvoked()); + test(dout.postUnmarshalInvoked); test(dout.theA.preMarshalInvoked); - test(dout.theA.postUnmarshalInvoked()); + test(dout.theA.postUnmarshalInvoked); test(dout.theB.preMarshalInvoked); - test(dout.theB.postUnmarshalInvoked()); + test(dout.theB.postUnmarshalInvoked); test(dout.theB.theC.preMarshalInvoked); - test(dout.theB.theC.postUnmarshalInvoked()); + test(dout.theB.theC.postUnmarshalInvoked); WriteLine("ok"); Write("testing protected members... "); Flush(); - E e = initial.getE(); - test(e.checkValues()); + 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); - F f = initial.getF(); + FI f = (FI)initial.getF(); test(f.checkValues()); - test(f.e2.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(); - I i = initial.getI(); + var i = initial.getI(); test(i != null); - I j = initial.getJ(); - test(j != null && ((J)j) != null); - I h = initial.getH(); - test(h != null && ((H)h) != 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")); @@ -226,7 +233,7 @@ public class AllTests : TestCommon.TestApp test(d1.a3.name.Equals("a3")); test(d1.a4.name.Equals("a4")); WriteLine("ok"); - + Write("throw EDerived... "); Flush(); try @@ -258,7 +265,7 @@ public class AllTests : TestCommon.TestApp 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); @@ -280,9 +287,17 @@ public class AllTests : TestCommon.TestApp } 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:default -p 12010"; + @ref = "uoet:" + app.getTestEndpoint(0); @base = communicator.stringToProxy(@ref); test(@base != null); UnexpectedObjectExceptionTestPrx uoet = UnexpectedObjectExceptionTestPrxHelper.uncheckedCast(@base); @@ -303,10 +318,19 @@ public class AllTests : TestCommon.TestApp test(false); } WriteLine("ok"); -#if SILVERLIGHT - initial.shutdown(); -#else + +// 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 + return initial; -#endif } } |