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); }
public static InitialPrx allTests(Ice.Communicator communicator) #endif { 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"); Write("testing stringToProxy... "); Flush(); String @ref = "initial:default -p 12010"; 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(); E e = initial.getE(); test(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(); test(f.checkValues()); test(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(); test(i != null); I j = initial.getJ(); test(j != null && ((J)j) != null); I h = initial.getH(); test(h != null && ((H)h) != null); 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 compact ID..."); Flush(); try { test(initial.getCompact() != null); } catch (Ice.OperationNotExistException) { } WriteLine("ok"); Write("testing UnexpectedObjectException..."); Flush(); @ref = "uoet:default -p 12010"; @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"); #if SILVERLIGHT initial.shutdown(); #else return(initial); #endif }
public static InitialPrx allTests(TestCommon.Application app) { Ice.Communicator communicator = app.communicator(); Write("testing stringToProxy... "); Flush(); string ref_Renamed = "initial:" + app.getTestEndpoint(0); Ice.ObjectPrx @base = communicator.stringToProxy(ref_Renamed); 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 proxies for class hierarchy... "); Flush(); Test.MA.CAPrx ca = initial.caop(); Test.MB.CBPrx cb = initial.cbop(); Test.MA.CCPrx cc = initial.ccop(); Test.MA.CDPrx cd = initial.cdop(); test(ca != cb); test(ca != cc); test(ca != cd); test(cb != cc); test(cb != cd); test(cc != cd); WriteLine("ok"); Write("getting proxies for interface hierarchy... "); Flush(); Test.MA.IAPrx ia = initial.iaop(); Test.MB.IB1Prx ib1 = initial.ib1op(); Test.MB.IB2Prx ib2 = initial.ib2op(); Test.MA.ICPrx ic = initial.icop(); test(ia != ib1); test(ia != ib2); test(ia != ic); test(ib1 != ic); test(ib2 != ic); WriteLine("ok"); Write("invoking proxy operations on class hierarchy... "); Flush(); Test.MA.CAPrx cao; Test.MB.CBPrx cbo; Test.MA.CCPrx cco; cao = ca.caop(ca); test(cao.Equals(ca)); cao = ca.caop(cb); test(cao.Equals(cb)); cao = ca.caop(cc); test(cao.Equals(cc)); cao = cb.caop(ca); test(cao.Equals(ca)); cao = cb.caop(cb); test(cao.Equals(cb)); cao = cb.caop(cc); test(cao.Equals(cc)); cao = cc.caop(ca); test(cao.Equals(ca)); cao = cc.caop(cb); test(cao.Equals(cb)); cao = cc.caop(cc); test(cao.Equals(cc)); cao = cb.cbop(cb); test(cao.Equals(cb)); cbo = cb.cbop(cb); test(cbo.Equals(cb)); cao = cb.cbop(cc); test(cao.Equals(cc)); cbo = cb.cbop(cc); test(cbo.Equals(cc)); cao = cc.cbop(cb); test(cao.Equals(cb)); cbo = cc.cbop(cb); test(cbo.Equals(cb)); cao = cc.cbop(cc); test(cao.Equals(cc)); cbo = cc.cbop(cc); test(cbo.Equals(cc)); cao = cc.ccop(cc); test(cao.Equals(cc)); cbo = cc.ccop(cc); test(cbo.Equals(cc)); cco = cc.ccop(cc); test(cco.Equals(cc)); WriteLine("ok"); Write("ditto, but for interface hierarchy... "); Flush(); Test.MA.IAPrx iao; Test.MB.IB1Prx ib1o; Test.MB.IB2Prx ib2o; Test.MA.ICPrx ico; iao = ia.iaop(ia); test(iao.Equals(ia)); iao = ia.iaop(ib1); test(iao.Equals(ib1)); iao = ia.iaop(ib2); test(iao.Equals(ib2)); iao = ia.iaop(ic); test(iao.Equals(ic)); iao = ib1.iaop(ia); test(iao.Equals(ia)); iao = ib1.iaop(ib1); test(iao.Equals(ib1)); iao = ib1.iaop(ib2); test(iao.Equals(ib2)); iao = ib1.iaop(ic); test(iao.Equals(ic)); iao = ib2.iaop(ia); test(iao.Equals(ia)); iao = ib2.iaop(ib1); test(iao.Equals(ib1)); iao = ib2.iaop(ib2); test(iao.Equals(ib2)); iao = ib2.iaop(ic); test(iao.Equals(ic)); iao = ic.iaop(ia); test(iao.Equals(ia)); iao = ic.iaop(ib1); test(iao.Equals(ib1)); iao = ic.iaop(ib2); test(iao.Equals(ib2)); iao = ic.iaop(ic); test(iao.Equals(ic)); iao = ib1.ib1op(ib1); test(iao.Equals(ib1)); ib1o = ib1.ib1op(ib1); test(ib1o.Equals(ib1)); iao = ib1.ib1op(ic); test(iao.Equals(ic)); ib1o = ib1.ib1op(ic); test(ib1o.Equals(ic)); iao = ic.ib1op(ib1); test(iao.Equals(ib1)); ib1o = ic.ib1op(ib1); test(ib1o.Equals(ib1)); iao = ic.ib1op(ic); test(iao.Equals(ic)); ib1o = ic.ib1op(ic); test(ib1o.Equals(ic)); iao = ib2.ib2op(ib2); test(iao.Equals(ib2)); ib2o = ib2.ib2op(ib2); test(ib2o.Equals(ib2)); iao = ib2.ib2op(ic); test(iao.Equals(ic)); ib2o = ib2.ib2op(ic); test(ib2o.Equals(ic)); iao = ic.ib2op(ib2); test(iao.Equals(ib2)); ib2o = ic.ib2op(ib2); test(ib2o.Equals(ib2)); iao = ic.ib2op(ic); test(iao.Equals(ic)); ib2o = ic.ib2op(ic); test(ib2o.Equals(ic)); iao = ic.icop(ic); test(iao.Equals(ic)); ib1o = ic.icop(ic); test(ib1o.Equals(ic)); ib2o = ic.icop(ic); test(ib2o.Equals(ic)); ico = ic.icop(ic); test(ico.Equals(ic)); WriteLine("ok"); Write("ditto, but for class implementing interfaces... "); Flush(); cao = cd.caop(cd); test(cao.Equals(cd)); cbo = cd.cbop(cd); test(cbo.Equals(cd)); cco = cd.ccop(cd); test(cco.Equals(cd)); iao = cd.iaop(cd); test(iao.Equals(cd)); ib1o = cd.ib1op(cd); test(ib1o.Equals(cd)); ib2o = cd.ib2op(cd); test(ib2o.Equals(cd)); cao = cd.cdop(cd); test(cao.Equals(cd)); cbo = cd.cdop(cd); test(cbo.Equals(cd)); cco = cd.cdop(cd); test(cco.Equals(cd)); iao = cd.cdop(cd); test(iao.Equals(cd)); ib1o = cd.cdop(cd); test(ib1o.Equals(cd)); ib2o = cd.cdop(cd); test(ib2o.Equals(cd)); WriteLine("ok"); return(initial); }
public override int run(string[] args) { if (args.Length > 0) { Console.Error.WriteLine(appName() + ": too many arguments"); return(1); } var initial = InitialPrxHelper.checkedCast(communicator().propertyToProxy("Initial.Proxy")); if (initial == null) { Console.Error.WriteLine("invalid object reference"); return(1); } Console.Out.WriteLine(); Console.Out.WriteLine("Let's first transfer a simple object, for a class without"); Console.Out.WriteLine("operations, and print its contents. No factory is required"); Console.Out.WriteLine("for this."); Console.Out.WriteLine("[press enter]"); Console.In.ReadLine(); Simple simple = initial.getSimple(); Console.Out.WriteLine("==> " + simple.message); Console.Out.WriteLine(); Console.Out.WriteLine("Yes, this worked. Now let's try to transfer an object for a class"); Console.Out.WriteLine("with operations as type Demo.Printer, without installing a factory first."); Console.Out.WriteLine("This should give us a `no factory' exception."); Console.Out.WriteLine("[press enter]"); Console.In.ReadLine(); Printer printer; PrinterPrx printerProxy; try { initial.getPrinter(out printer, out printerProxy); Console.Error.WriteLine("Did not get the expected NoValueFactoryException!"); return(1); } catch (Ice.NoValueFactoryException ex) { Console.Out.WriteLine("==> " + ex); } Console.Out.WriteLine(); Console.Out.WriteLine("Yep, that's what we expected. Now let's try again, but with"); Console.Out.WriteLine("installing an appropriate factory first. If successful, we print"); Console.Out.WriteLine("the object's content."); Console.Out.WriteLine("[press enter]"); Console.In.ReadLine(); communicator().getValueFactoryManager().add(ValueFactory.create, Demo.Printer.ice_staticId()); initial.getPrinter(out printer, out printerProxy); Console.Out.WriteLine("==> " + printer.message); Console.Out.WriteLine(); Console.Out.WriteLine("Cool, it worked! Let's try calling the printBackwards() method"); Console.Out.WriteLine("on the object we just received locally."); Console.Out.WriteLine("[press enter]"); Console.In.ReadLine(); Console.Out.Write("==> "); printer.printBackwards(); Console.Out.WriteLine(); Console.Out.WriteLine("Now we call the same method, but on the remote object. Watch the"); Console.Out.WriteLine("server's output."); Console.Out.WriteLine("[press enter]"); Console.In.ReadLine(); printerProxy.printBackwards(); Console.Out.WriteLine(); Console.Out.WriteLine("Next, we transfer a derived object from the server as a base"); Console.Out.WriteLine("object. Since we haven't yet installed a factory for the derived"); Console.Out.WriteLine("class, the derived class (Demo.DerivedPrinter) is sliced"); Console.Out.WriteLine("to its base class (Demo.Printer)."); Console.Out.WriteLine("[press enter]"); Console.In.ReadLine(); Printer derivedAsBase = initial.getDerivedPrinter(); Console.Out.WriteLine("==> The type ID of the received object is \"" + derivedAsBase.ice_id() + "\""); Debug.Assert(derivedAsBase.ice_id().Equals(Demo.Printer.ice_staticId())); Console.Out.WriteLine(); Console.Out.WriteLine("Now we install a factory for the derived class, and try again."); Console.Out.WriteLine("Because we receive the derived object as a base object,"); Console.Out.WriteLine("we need to do a class cast to get from the base to the derived object."); Console.Out.WriteLine("[press enter]"); Console.In.ReadLine(); communicator().getValueFactoryManager().add(ValueFactory.create, Demo.DerivedPrinter.ice_staticId()); var derived = (DerivedPrinter)initial.getDerivedPrinter(); Console.Out.WriteLine("==> class cast to derived object succeeded"); Console.Out.WriteLine("==> The type ID of the received object is \"" + derived.ice_id() + "\""); Console.Out.WriteLine(); Console.Out.WriteLine("Let's print the message contained in the derived object, and"); Console.Out.WriteLine("call the operation printUppercase() on the derived object"); Console.Out.WriteLine("locally."); Console.Out.WriteLine("[press enter]"); Console.In.ReadLine(); Console.Out.WriteLine("==> " + derived.derivedMessage); Console.Out.Write("==> "); derived.printUppercase(); Console.Out.WriteLine(); Console.Out.WriteLine("Now let's make sure that slice is preserved with [\"preserve-slice\"]"); Console.Out.WriteLine("metadata. We create a derived type on the client and pass it to the"); Console.Out.WriteLine("server, which does not have a factory for the derived type. We do a"); Console.Out.WriteLine("class cast to make sure we can still access the derived type when"); Console.Out.WriteLine("it has been returned from the server."); Console.Out.WriteLine("[press enter]"); Console.In.ReadLine(); ClientPrinter clientp = new ClientPrinterI(); clientp.message = "a message 4 u"; communicator().getValueFactoryManager().add(ValueFactory.create, Demo.ClientPrinter.ice_staticId()); derivedAsBase = initial.updatePrinterMessage(clientp); clientp = (ClientPrinter)derivedAsBase; Console.Out.WriteLine("==> " + clientp.message); Console.Out.WriteLine(); Console.Out.WriteLine("Finally, we try the same again, but instead of returning the"); Console.Out.WriteLine("derived object, we throw an exception containing the derived"); Console.Out.WriteLine("object."); Console.Out.WriteLine("[press enter]"); Console.In.ReadLine(); try { initial.throwDerivedPrinter(); } catch (DerivedPrinterException ex) { derived = ex.derived; Debug.Assert(derived != null); } Console.Out.WriteLine("==> " + derived.derivedMessage); Console.Out.Write("==> "); derived.printUppercase(); Console.Out.WriteLine(); Console.Out.WriteLine("That's it for this demo. Have fun with Ice!"); initial.shutdown(); return(0); }
public static InitialPrx allTests(Ice.Communicator 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"; 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 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 compact ID..."); Flush(); try { test(initial.getCompact() != null); } catch (Ice.OperationNotExistException) { } WriteLine("ok"); Write("testing UnexpectedObjectException..."); Flush(); @ref = "uoet:default -p 12010"; @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 return(initial); }