ICE 3.4.2
[php5-ice-freebsdport.git] / cs / test / Ice / interceptor / Client.cs
blob7ccb553cd0ec9327ae4612c64f8966473531e44d
1 // **********************************************************************
2 //
3 // Copyright (c) 2003-2011 ZeroC, Inc. All rights reserved.
4 //
5 // This copy of Ice is licensed to you under the terms described in the
6 // ICE_LICENSE file included in this distribution.
7 //
8 // **********************************************************************
10 using System;
11 using System.Diagnostics;
12 using System.Reflection;
14 [assembly: CLSCompliant(true)]
16 [assembly: AssemblyTitle("IceTest")]
17 [assembly: AssemblyDescription("Ice test")]
18 [assembly: AssemblyCompany("ZeroC, Inc.")]
20 public class Client
22 public class App : Ice.Application
24 private static void test(bool b)
26 if(!b)
28 throw new Exception();
32 private int run(Test.MyObjectPrx prx, InterceptorI interceptor)
34 Console.Out.Write("testing simple interceptor... ");
35 Console.Out.Flush();
36 test(interceptor.getLastOperation() == null);
37 test(interceptor.getLastStatus() == Ice.DispatchStatus.DispatchAsync);
38 prx.ice_ping();
39 test(interceptor.getLastOperation().Equals("ice_ping"));
40 test(interceptor.getLastStatus() == Ice.DispatchStatus.DispatchOK);
41 String typeId = prx.ice_id();
42 test(interceptor.getLastOperation().Equals("ice_id"));
43 test(interceptor.getLastStatus() == Ice.DispatchStatus.DispatchOK);
44 test(prx.ice_isA(typeId));
45 test(interceptor.getLastOperation().Equals("ice_isA"));
46 test(interceptor.getLastStatus() == Ice.DispatchStatus.DispatchOK);
47 test(prx.add(33, 12) == 45);
48 test(interceptor.getLastOperation().Equals("add"));
49 test(interceptor.getLastStatus().Equals(Ice.DispatchStatus.DispatchOK));
50 Console.WriteLine("ok");
51 Console.Out.Write("testing retry... ");
52 Console.Out.Flush();
53 test(prx.addWithRetry(33, 12) == 45);
54 test(interceptor.getLastOperation().Equals("addWithRetry"));
55 test(interceptor.getLastStatus().Equals(Ice.DispatchStatus.DispatchOK));
56 Console.WriteLine("ok");
57 Console.Out.Write("testing user exception... ");
58 Console.Out.Flush();
59 try
61 prx.badAdd(33, 12);
62 test(false);
64 catch(Test.InvalidInputException)
66 // expected
68 test(interceptor.getLastOperation().Equals("badAdd"));
69 test(interceptor.getLastStatus().Equals(Ice.DispatchStatus.DispatchUserException));
70 Console.WriteLine("ok");
71 Console.Out.Write("testing ONE... ");
72 Console.Out.Flush();
73 interceptor.clear();
74 try
76 prx.notExistAdd(33, 12);
77 test(false);
79 catch(Ice.ObjectNotExistException)
81 // expected
83 test(interceptor.getLastOperation().Equals("notExistAdd"));
84 test(interceptor.getLastStatus() == Ice.DispatchStatus.DispatchAsync);
85 Console.WriteLine("ok");
86 Console.Out.Write("testing system exception... ");
87 Console.Out.Flush();
88 interceptor.clear();
89 try
91 prx.badSystemAdd(33, 12);
92 test(false);
94 catch(Ice.UnknownLocalException)
97 catch(Exception)
99 test(false);
101 test(interceptor.getLastOperation().Equals("badSystemAdd"));
102 test(interceptor.getLastStatus() == Ice.DispatchStatus.DispatchAsync);
103 Console.WriteLine("ok");
104 if(!prx.ice_isCollocationOptimized())
106 Console.Out.Write("testing simple AMD... ");
107 Console.Out.Flush();
108 test(prx.amdAdd(33, 12) == 45);
109 test(interceptor.getLastOperation().Equals("amdAdd"));
110 test(interceptor.getLastStatus().Equals(Ice.DispatchStatus.DispatchAsync));
111 Console.WriteLine("ok");
113 return 0;
116 private int runAmd(Test.MyObjectPrx prx, AMDInterceptorI interceptor)
118 Console.Out.Write("testing simple interceptor... ");
119 Console.Out.Flush();
120 test(interceptor.getLastOperation() == null);
121 test(interceptor.getLastStatus() == Ice.DispatchStatus.DispatchAsync);
122 test(prx.amdAdd(33, 12) == 45);
123 test(interceptor.getLastOperation().Equals("amdAdd"));
124 test(interceptor.getLastStatus().Equals(Ice.DispatchStatus.DispatchAsync));
125 test(interceptor.getActualStatus().Equals(Ice.DispatchStatus.DispatchOK));
126 Console.WriteLine("ok");
127 Console.Out.Write("testing retry... ");
128 Console.Out.Flush();
129 test(prx.amdAddWithRetry(33, 12) == 45);
130 test(interceptor.getLastOperation().Equals("amdAddWithRetry"));
131 test(interceptor.getLastStatus().Equals(Ice.DispatchStatus.DispatchAsync));
132 test(interceptor.getActualStatus().Equals(Ice.DispatchStatus.DispatchOK));
133 Console.WriteLine("ok");
134 Console.Out.Write("testing user exception... ");
135 Console.Out.Flush();
138 prx.amdBadAdd(33, 12);
139 test(false);
141 catch(Test.InvalidInputException)
143 // expected
145 test(interceptor.getLastOperation().Equals("amdBadAdd"));
146 test(interceptor.getLastStatus().Equals(Ice.DispatchStatus.DispatchAsync));
147 test(interceptor.getActualStatus().Equals(Ice.DispatchStatus.DispatchUserException));
148 Console.WriteLine("ok");
149 Console.Out.Write("testing ONE... ");
150 Console.Out.Flush();
151 interceptor.clear();
154 prx.amdNotExistAdd(33, 12);
155 test(false);
157 catch(Ice.ObjectNotExistException)
159 // expected
161 test(interceptor.getLastOperation().Equals("amdNotExistAdd"));
162 test(interceptor.getLastStatus().Equals(Ice.DispatchStatus.DispatchAsync));
163 test(interceptor.getActualStatus() == Ice.DispatchStatus.DispatchAsync);
164 test(interceptor.getException() is Ice.ObjectNotExistException);
165 Console.WriteLine("ok");
166 Console.Out.Write("testing system exception... ");
167 Console.Out.Flush();
168 interceptor.clear();
171 prx.amdBadSystemAdd(33, 12);
172 test(false);
174 catch(Ice.UnknownLocalException)
176 test(!prx.ice_isCollocationOptimized());
178 test(interceptor.getLastOperation().Equals("amdBadSystemAdd"));
179 test(interceptor.getLastStatus().Equals(Ice.DispatchStatus.DispatchAsync));
180 test(interceptor.getActualStatus() == Ice.DispatchStatus.DispatchAsync);
181 test(interceptor.getException() is Ice.InitializationException);
182 Console.WriteLine("ok");
183 return 0;
186 public override int run(string[] args)
189 // Create OA and servants
192 communicator().getProperties().setProperty("MyOA.AdapterId", "myOA");
194 Ice.ObjectAdapter oa = communicator().createObjectAdapterWithEndpoints("MyOA2", "tcp -h localhost");
196 Ice.Object servant = new MyObjectI();
197 InterceptorI interceptor = new InterceptorI(servant);
199 Test.MyObjectPrx prx = Test.MyObjectPrxHelper.uncheckedCast(oa.addWithUUID(interceptor));
201 oa.activate();
203 Console.WriteLine("Collocation optimization on");
204 int rs = run(prx, interceptor);
205 if(rs == 0)
207 Console.WriteLine("Collocation optimization off");
208 interceptor.clear();
209 prx = Test.MyObjectPrxHelper.uncheckedCast(prx.ice_collocationOptimized(false));
210 rs = run(prx, interceptor);
212 if(rs == 0)
214 Console.WriteLine("Now with AMD");
215 AMDInterceptorI amdInterceptor = new AMDInterceptorI(servant);
216 prx = Test.MyObjectPrxHelper.uncheckedCast(oa.addWithUUID(amdInterceptor));
217 prx = Test.MyObjectPrxHelper.uncheckedCast(prx.ice_collocationOptimized(false));
219 rs = runAmd(prx, amdInterceptor);
222 return rs;
226 public static int Main(string[] args)
228 #if !COMPACT
229 Debug.Listeners.Add(new ConsoleTraceListener());
230 #endif
232 App app = new App();
233 Ice.InitializationData data = new Ice.InitializationData();
234 #if COMPACT
236 // When using Ice for .NET Compact Framework, we need to specify
237 // the assembly so that Ice can locate classes and exceptions.
239 data.properties = Ice.Util.createProperties();
240 data.properties.setProperty("Ice.FactoryAssemblies", "client");
241 #endif
242 return app.main(args, data);