ICE 3.4.2
[php5-ice-freebsdport.git] / py / test / Ice / blobject / Client.py
blob24829f5451127b90ac6b692eb82ff970a1cb56e0
1 #!/usr/bin/env python
2 # **********************************************************************
4 # Copyright (c) 2003-2011 ZeroC, Inc. All rights reserved.
6 # This copy of Ice is licensed to you under the terms described in the
7 # ICE_LICENSE file included in this distribution.
9 # **********************************************************************
11 import os, sys, traceback
13 import Ice
14 Ice.loadSlice('Test.ice')
15 import Test
16 import RouterI
18 def test(b):
19 if not b:
20 raise RuntimeError('test assertion failed')
22 def run(args, communicator, sync):
23 hello = Test.HelloPrx.checkedCast(communicator.stringToProxy("test:default -p 12010"))
24 hello.sayHello(False)
25 hello.sayHello(False, { "_fwd":"o" } )
26 test(hello.add(10, 20) == 30)
27 try:
28 hello.raiseUE()
29 test(False)
30 except Test.UE:
31 pass
33 try:
34 Test.HelloPrx.checkedCast(communicator.stringToProxy("unknown:default -p 12010 -t 10000"))
35 test(False)
36 except Ice.ObjectNotExistException:
37 pass
39 # First try an object at a non-existent endpoint.
40 try:
41 Test.HelloPrx.checkedCast(communicator.stringToProxy("missing:default -p 12000 -t 10000"))
42 test(False)
43 except Ice.UnknownLocalException, e:
44 test(e.unknown.find('ConnectionRefusedException'))
45 if sync:
46 hello.shutdown()
47 return True
49 argv = sys.argv[:] # Clone the arguments to use again later
51 try:
52 initData = Ice.InitializationData()
53 initData.properties = Ice.createProperties(argv)
54 initData.properties.setProperty('Ice.Warn.Dispatch', '0')
55 communicator = Ice.initialize(argv, initData)
56 router = RouterI.RouterI(communicator, False)
57 print "testing async blobject...",
58 sys.stdout.flush()
59 status = run(sys.argv, communicator, False)
60 print "ok"
61 router.destroy()
62 except:
63 traceback.print_exc()
64 status = False
66 if communicator:
67 try:
68 communicator.destroy()
69 except:
70 traceback.print_exc()
71 status = False
73 if status:
74 try:
75 initData = Ice.InitializationData()
76 initData.properties = Ice.createProperties(sys.argv)
77 initData.properties.setProperty('Ice.Warn.Dispatch', '0')
78 communicator = Ice.initialize(sys.argv, initData)
79 router = RouterI.RouterI(communicator, True)
80 print "testing sync blobject...",
81 sys.stdout.flush()
82 status = run(sys.argv, communicator, True)
83 print "ok"
84 router.destroy()
85 except:
86 traceback.print_exc()
87 status = False
89 if communicator:
90 try:
91 communicator.destroy()
92 except:
93 traceback.print_exc()
94 status = False
96 sys.exit(not status)