1 // **********************************************************************
3 // Copyright (c) 2003-2011 ZeroC, Inc. All rights reserved.
5 // This copy of Ice is licensed to you under the terms described in the
6 // ICE_LICENSE file included in this distribution.
8 // **********************************************************************
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.")]
22 public class App
: Ice
.Application
24 private static void test(bool b
)
28 throw new Exception();
32 private int run(Test
.MyObjectPrx prx
, InterceptorI interceptor
)
34 Console
.Out
.Write("testing simple interceptor... ");
36 test(interceptor
.getLastOperation() == null);
37 test(interceptor
.getLastStatus() == Ice
.DispatchStatus
.DispatchAsync
);
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... ");
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... ");
64 catch(Test
.InvalidInputException
)
68 test(interceptor
.getLastOperation().Equals("badAdd"));
69 test(interceptor
.getLastStatus().Equals(Ice
.DispatchStatus
.DispatchUserException
));
70 Console
.WriteLine("ok");
71 Console
.Out
.Write("testing ONE... ");
76 prx
.notExistAdd(33, 12);
79 catch(Ice
.ObjectNotExistException
)
83 test(interceptor
.getLastOperation().Equals("notExistAdd"));
84 test(interceptor
.getLastStatus() == Ice
.DispatchStatus
.DispatchAsync
);
85 Console
.WriteLine("ok");
86 Console
.Out
.Write("testing system exception... ");
91 prx
.badSystemAdd(33, 12);
94 catch(Ice
.UnknownLocalException
)
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... ");
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");
116 private int runAmd(Test
.MyObjectPrx prx
, AMDInterceptorI interceptor
)
118 Console
.Out
.Write("testing simple interceptor... ");
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... ");
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... ");
138 prx
.amdBadAdd(33, 12);
141 catch(Test
.InvalidInputException
)
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... ");
154 prx
.amdNotExistAdd(33, 12);
157 catch(Ice
.ObjectNotExistException
)
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... ");
171 prx
.amdBadSystemAdd(33, 12);
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");
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
));
203 Console
.WriteLine("Collocation optimization on");
204 int rs
= run(prx
, interceptor
);
207 Console
.WriteLine("Collocation optimization off");
209 prx
= Test
.MyObjectPrxHelper
.uncheckedCast(prx
.ice_collocationOptimized(false));
210 rs
= run(prx
, interceptor
);
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
);
226 public static int Main(string[] args
)
229 Debug
.Listeners
.Add(new ConsoleTraceListener());
233 Ice
.InitializationData data
= new Ice
.InitializationData();
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");
242 return app
.main(args
, data
);