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 // **********************************************************************
13 using System
.Collections
.Generic
;
14 using System
.Diagnostics
;
15 using System
.Reflection
;
16 using System
.Threading
;
18 [assembly
: CLSCompliant(true)]
20 [assembly
: AssemblyTitle("IceTest")]
21 [assembly
: AssemblyDescription("Ice test")]
22 [assembly
: AssemblyCompany("ZeroC, Inc.")]
26 public class App
: Ice
.Application
32 _initData
= new Ice
.InitializationData();
33 _initData
.properties
= Ice
.Util
.createProperties();
34 _initData
.properties
.setProperty("Ice.Default.Router", "Glacier2/router:default -p 12347");
36 _initData
.dispatcher
= delegate(Ice
.VoidAction action
, Ice
.Connection connection
)
38 _initData
.dispatcher
= delegate(System
.Action action
, Ice
.Connection connection
)
45 public class SessionCalback1
: Glacier2
.SessionCallback
48 connected(Glacier2
.SessionHelper session
)
54 disconnected(Glacier2
.SessionHelper session
)
60 connectFailed(Glacier2
.SessionHelper session
, System
.Exception exception
)
66 catch(Glacier2
.PermissionDeniedException
)
68 Console
.Out
.WriteLine("ok");
79 catch(System
.Exception
)
86 createdCommunicator(Glacier2
.SessionHelper session
)
88 test(session
.communicator() != null);
92 public class SessionCalback2
: Glacier2
.SessionCallback
95 connected(Glacier2
.SessionHelper session
)
97 Console
.Out
.WriteLine("ok");
110 disconnected(Glacier2
.SessionHelper session
)
112 Console
.Out
.WriteLine("ok");
125 connectFailed(Glacier2
.SessionHelper session
, System
.Exception ex
)
127 Console
.Out
.WriteLine(ex
.ToString());
132 createdCommunicator(Glacier2
.SessionHelper session
)
134 test(session
.communicator() != null);
138 public class SessionCalback3
: Glacier2
.SessionCallback
141 connected(Glacier2
.SessionHelper session
)
147 disconnected(Glacier2
.SessionHelper session
)
153 connectFailed(Glacier2
.SessionHelper session
, System
.Exception exception
)
159 catch(Ice
.ConnectionRefusedException
)
161 Console
.Out
.WriteLine("ok");
172 catch(System
.Exception
)
179 createdCommunicator(Glacier2
.SessionHelper session
)
181 test(session
.communicator() != null);
185 public Ice
.InitializationData
getInitData()
190 public override int run(string[] args
)
192 _factory
= new Glacier2
.SessionFactoryHelper(_initData
, new SessionCalback1());
195 // Test to create a session with wrong userid/password
200 Console
.Out
.Write("testing SessionHelper connect with wrong userid/password... ");
203 _factory
.setRouterHost("127.0.0.1");
204 _factory
.setPort(12347);
205 _factory
.setRouterIdentity(Ice
.Util
.stringToIdentity("Glacier2/router"));
206 _factory
.setSecure(false);
207 _session
= _factory
.connect("userid", "xxx");
219 catch(ThreadInterruptedException
)
230 _factory
= new Glacier2
.SessionFactoryHelper(_initData
, new SessionCalback2());
234 Console
.Out
.Write("testing SessionHelper connect... ");
236 _factory
.setRouterHost("127.0.0.1");
237 _factory
.setPort(12347);
238 _factory
.setRouterIdentity(Ice
.Util
.stringToIdentity("Glacier2/router"));
239 _factory
.setSecure(false);
240 _session
= _factory
.connect("userid", "abc123");
252 catch(ThreadInterruptedException
)
258 Console
.Out
.Write("testing SessionHelper isConnected after connect... ");
260 test(_session
.isConnected());
261 Console
.Out
.WriteLine("ok");
263 Console
.Out
.Write("testing SessionHelper categoryForClient after connect... ");
267 test(!_session
.categoryForClient().Equals(""));
269 catch(Glacier2
.SessionNotExistException
)
273 Console
.Out
.WriteLine("ok");
277 // test(_session.session() != null);
279 // catch(Glacier2.SessionNotExistException ex)
284 Console
.Out
.Write("testing stringToProxy for server object... ");
286 Ice
.ObjectPrx
@base = _session
.communicator().stringToProxy("callback:tcp -p 12010");
287 Console
.Out
.WriteLine("ok");
289 Console
.Out
.Write("pinging server after session creation... ");
292 Console
.Out
.WriteLine("ok");
294 Console
.Out
.Write("testing checked cast for server object... ");
296 CallbackPrx twoway
= CallbackPrxHelper
.checkedCast(@base);
297 test(twoway
!= null);
298 Console
.Out
.WriteLine("ok");
300 Console
.Out
.Write("testing server shutdown... ");
303 Console
.Out
.WriteLine("ok");
305 test(_session
.communicator() != null);
306 Console
.Out
.Write("testing SessionHelper destroy... ");
320 catch(ThreadInterruptedException
)
326 Console
.Out
.Write("testing SessionHelper isConnected after destroy... ");
328 test(_session
.isConnected() == false);
329 Console
.Out
.WriteLine("ok");
331 Console
.Out
.Write("testing SessionHelper categoryForClient after destroy... ");
335 test(!_session
.categoryForClient().Equals(""));
338 catch(Glacier2
.SessionNotExistException
)
341 Console
.Out
.WriteLine("ok");
343 Console
.Out
.Write("testing SessionHelper session after destroy... ");
349 catch(Glacier2
.SessionNotExistException
)
352 Console
.Out
.WriteLine("ok");
354 Console
.Out
.Write("testing SessionHelper communicator after destroy... ");
356 test(_session
.communicator() == null);
357 Console
.Out
.WriteLine("ok");
360 Console
.Out
.Write("uninstalling router with communicator... ");
362 communicator().setDefaultRouter(null);
363 Console
.Out
.WriteLine("ok");
365 Ice
.ObjectPrx processBase
;
367 Console
.Out
.Write("testing stringToProxy for process object... ");
368 processBase
= communicator().stringToProxy("Glacier2/admin -f Process:tcp -h 127.0.0.1 -p 12348");
369 Console
.Out
.WriteLine("ok");
373 Ice
.ProcessPrx process
;
375 Console
.Out
.Write("testing checked cast for admin object... ");
376 process
= Ice
.ProcessPrxHelper
.checkedCast(processBase
);
377 test(process
!= null);
378 Console
.Out
.WriteLine("ok");
381 Console
.Out
.Write("testing Glacier2 shutdown... ");
388 catch(Ice
.LocalException
)
390 Console
.Out
.WriteLine("ok");
398 _factory
= new Glacier2
.SessionFactoryHelper(_initData
, new SessionCalback3());
402 Console
.Out
.Write("testing SessionHelper connect after router shutdown... ");
405 _factory
.setRouterHost("127.0.0.1");
406 _factory
.setPort(12347);
407 _factory
.setRouterIdentity(Ice
.Util
.stringToIdentity("Glacier2/router"));
408 _factory
.setSecure(false);
409 _session
= _factory
.connect("userid", "abc123");
421 catch(ThreadInterruptedException
)
427 Console
.Out
.Write("testing SessionHelper isConnect after connect failure... ");
429 test(_session
.isConnected() == false);
430 Console
.Out
.WriteLine("ok");
432 Console
.Out
.Write("testing SessionHelper communicator after connect failure... ");
434 test(_session
.communicator() == null);
435 Console
.Out
.WriteLine("ok");
437 Console
.Out
.Write("testing SessionHelper destroy after connect failure... ");
440 Console
.Out
.WriteLine("ok");
461 throw new Exception();
465 public static App me
;
466 public IceUtilInternal
.Monitor lck
= new IceUtilInternal
.Monitor();
467 private Ice
.InitializationData _initData
;
468 private Glacier2
.SessionHelper _session
;
469 private Glacier2
.SessionFactoryHelper _factory
;
472 public static int Main(string[] args
)
475 Debug
.Listeners
.Add(new ConsoleTraceListener());
479 app
.getInitData().properties
.setProperty("Ice.Warn.Connections", "0");
480 return app
.main(args
, app
.getInitData());