diff options
author | Mark Spruiell <mes@zeroc.com> | 2004-08-27 23:22:32 +0000 |
---|---|---|
committer | Mark Spruiell <mes@zeroc.com> | 2004-08-27 23:22:32 +0000 |
commit | 393a9d31e57045570783f8bd649b98e1d17f4993 (patch) | |
tree | 02d0eaf3598d7f0f648c8a6e6f41719a842e00a2 /py/test/Ice/exceptions/AllTests.py | |
parent | removed self (diff) | |
download | ice-393a9d31e57045570783f8bd649b98e1d17f4993.tar.bz2 ice-393a9d31e57045570783f8bd649b98e1d17f4993.tar.xz ice-393a9d31e57045570783f8bd649b98e1d17f4993.zip |
initial check-in
Diffstat (limited to 'py/test/Ice/exceptions/AllTests.py')
-rw-r--r-- | py/test/Ice/exceptions/AllTests.py | 424 |
1 files changed, 424 insertions, 0 deletions
diff --git a/py/test/Ice/exceptions/AllTests.py b/py/test/Ice/exceptions/AllTests.py new file mode 100644 index 00000000000..e0172be1523 --- /dev/null +++ b/py/test/Ice/exceptions/AllTests.py @@ -0,0 +1,424 @@ +# ********************************************************************** +# +# Copyright (c) 2003-2004 ZeroC, Inc. All rights reserved. +# +# This copy of Ice is licensed to you under the terms described in the +# ICE_LICENSE file included in this distribution. +# +# ********************************************************************** + +import Ice, Test, _Top, Mod, threading, sys + +def test(b): + if not b: + raise RuntimeError('test assertion failed') + +class EmptyI(_Top.Empty): + pass + +class ServantLocatorI(Ice.ServantLocator): + def locate(self, current): + return None + + def finished(self, current, servant, cookie): + pass + + def deactivate(self, category): + pass + +class ObjectFactoryI(Ice.ObjectFactory): + def create(id): + return None + + def destroy(): + pass + +class CallbackBase: + def __init__(self): + self._called = False + self._cond = threading.Condition() + + def check(self): + self._cond.acquire() + try: + while not self._called: + self._cond.wait(5.0) + if self._called: + self._called = false + return True; + else: + return False + finally: + self._cond.release() + + def called(self): + self._cond.acquire() + _called = True + self._cond.notify() + self._cond.release() + +def allTests(communicator, collocated): + print "testing servant registration exceptions... ", + adapter = communicator.createObjectAdapter("TestAdapter1") + obj = EmptyI() + adapter.add(obj, Ice.stringToIdentity("x")) + gotException = False + try: + adapter.add(obj, Ice.stringToIdentity("x")) + except Ice.AlreadyRegisteredException: + gotException = True + test(gotException) + + gotException = False + adapter.remove(Ice.stringToIdentity("x")) + try: + adapter.remove(Ice.stringToIdentity("x")) + except Ice.NotRegisteredException: + gotException = True + test(gotException) + + adapter.deactivate() + print "ok" + + print "testing servant locator registrations exceptions... ", + adapter = communicator.createObjectAdapter("TestAdapter2") + loc = ServantLocatorI() + adapter.addServantLocator(loc, "x") + gotException = False + try: + adapter.addServantLocator(loc, "x") + except Ice.AlreadyRegisteredException: + gotException = True + test(gotException) + + adapter.deactivate() + print "ok" + + print "testing object factory registration exceptions... ", + of = ObjectFactoryI() + communicator.addObjectFactory(of, "x") + gotException = False + try: + communicator.addObjectFactory(of, "x") + except Ice.AlreadyRegisteredException: + gotException = True + test(gotException) + + gotException = False + communicator.removeObjectFactory("x") + try: + communicator.removeObjectFactory("x") + except Ice.NotRegisteredException: + gotException = True + test(gotException) + print "ok" + + print "testing stringToProxy... ", + ref = "thrower:default -p 12345 -t 10000" + base = communicator.stringToProxy(ref) + test(base) + print "ok" + + print "testing checked cast... ", + thrower = _Top.ThrowerPrx.checkedCast(base) + test(thrower) + test(thrower == base) + print "ok" + + print "catching exact types... ", + + try: + thrower.throwAasA(1) + test(False) + except _Top.A, ex: + test(ex.aMem == 1) + except: + print sys.exc_info()[1].unknown + test(False) + + try: + thrower.throwAorDasAorD(1) + test(False) + except _Top.A, ex: + test(ex.aMem == 1) + except: + print sys.exc_info() + test(False) + + try: + thrower.throwAorDasAorD(-1) + test(False) + except _Top.D, ex: + test(ex.dMem == -1) + except: + print sys.exc_info() + test(False) + + try: + thrower.throwBasB(1, 2) + test(False) + except _Top.B, ex: + test(ex.aMem == 1) + test(ex.bMem == 2) + except: + print sys.exc_info() + test(False) + + try: + thrower.throwCasC(1, 2, 3) + test(False) + except _Top.C, ex: + test(ex.aMem == 1) + test(ex.bMem == 2) + test(ex.cMem == 3) + except: + print sys.exc_info() + test(False) + + try: + thrower.throwModA(1, 2) + test(False) + except Mod.A, ex: + test(ex.aMem == 1) + test(ex.a2Mem == 2) + except Ice.OperationNotExistException: + # + # This operation is not supported in Java. + # + pass + except: + print sys.exc_info() + test(False) + + print "ok" + + print "catching base types... ", + + try: + thrower.throwBasB(1, 2) + test(False) + except _Top.A, ex: + test(ex.aMem == 1) + except: + print sys.exc_info() + test(False) + + try: + thrower.throwCasC(1, 2, 3) + test(False) + except _Top.B, ex: + test(ex.aMem == 1) + test(ex.bMem == 2) + except: + print sys.exc_info() + test(False) + + try: + thrower.throwModA(1, 2) + test(False) + except _Top.A, ex: + test(ex.aMem == 1) + except Ice.OperationNotExistException: + # + # This operation is not supported in Java. + # + pass + except: + print sys.exc_info() + test(False) + + print "ok" + + print "catching derived types... ", + + try: + thrower.throwBasA(1, 2) + test(False) + except _Top.B, ex: + test(ex.aMem == 1) + test(ex.bMem == 2) + except: + print sys.exc_info() + test(False) + + try: + thrower.throwCasA(1, 2, 3) + test(False) + except _Top.C, ex: + test(ex.aMem == 1) + test(ex.bMem == 2) + test(ex.cMem == 3) + except: + print sys.exc_info() + test(False) + + try: + thrower.throwCasB(1, 2, 3) + test(False) + except _Top.C, ex: + test(ex.aMem == 1) + test(ex.bMem == 2) + test(ex.cMem == 3) + except: + print sys.exc_info() + test(False) + + print "ok" + + if thrower.supportsUndeclaredExceptions(): + print "catching unknown user exception... ", + + try: + thrower.throwUndeclaredA(1) + test(False) + except _Top.A, ex: + # + # We get the original exception with collocation + # optimization. + # + test(collocated) + test(ex.aMem == 1) + except Ice.UnknownUserException: + # + # We get an unknown user exception without collocation + # optimization. + # + test(not collocated) + except: + print sys.exc_info() + test(False) + + try: + thrower.throwUndeclaredB(1, 2) + test(False) + except _Top.B, ex: + # + # We get the original exception with collocation + # optimization. + # + test(collocated) + test(ex.aMem == 1) + test(ex.bMem == 2) + except Ice.UnknownUserException: + # + # We get an unknown user exception without collocation + # optimization. + # + test(not collocated) + except: + print sys.exc_info() + test(False) + + try: + thrower.throwUndeclaredC(1, 2, 3) + test(False) + except _Top.C, ex: + # + # We get the original exception with collocation + # optimization. + # + test(collocated) + test(ex.aMem == 1) + test(ex.bMem == 2) + test(ex.cMem == 3) + except Ice.UnknownUserException: + # + # We get an unknown user exception without + # collocation optimization. + # + test(not collocated) + except: + print sys.exc_info() + test(False) + + print "ok" + + print "catching object not exist exception... ", + + id = Ice.stringToIdentity("does not exist") + try: + thrower2 = _Top.ThrowerPrx.uncheckedCast(thrower.ice_newIdentity(id)) + thrower2.throwAasA(1) +# thrower2.ice_ping() + test(False) + except Ice.ObjectNotExistException, ex: + test(ex.id == id) + except: + print sys.exc_info() + test(False) + + print "ok" + + print "catching facet not exist exception... ", + + try: + thrower2 = _Top.ThrowerPrx.uncheckedCast(thrower, "no such facet") + try: + thrower2.ice_ping() + test(False) + except Ice.FacetNotExistException, ex: + test(ex.facet == "no such facet") + except: + print sys.exc_info() + test(False) + + print "ok" + + print "catching operation not exist exception... ", + + try: + thrower2 = _Top.WrongOperationPrx.uncheckedCast(thrower) + thrower2.noSuchOperation() + test(False) + except Ice.OperationNotExistException, ex: + test(ex.operation == "noSuchOperation") + except: + print sys.exc_info() + test(False) + + print "ok" + + print "catching unknown local exception... ", + + try: + thrower.throwLocalException() + test(False) + except Ice.TimeoutException: + # + # We get the original exception with collocation + # optimization. + # + test(collocated) + except Ice.UnknownLocalException: + # + # We get an unknown local exception without collocation + # optimization. + # + test(not collocated) + except: + print sys.exc_info() + test(False) + + print "ok" + + print "catching unknown non-Ice exception... ", + + try: + thrower.throwNonIceException() + test(False) + except Ice.UnknownException: + # + # We get an unknown exception without collocation + # optimization. + # + assert(not collocated) + except: + # + # We get the original exception with collocation + # optimization. + # + assert(collocated) + + print "ok" + + return thrower |