summaryrefslogtreecommitdiff
path: root/py/test/Ice/servantLocator/TestAMDI.py
blob: b19211b0b57c0ac2979917975af310880f9b1d19 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/usr/bin/env python
# **********************************************************************
#
# Copyright (c) 2003-2007 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 os, sys, traceback, time
import Ice, Test

def test(b):
    if not b:
        raise RuntimeError('test assertion failed')

class TestI(Test.TestIntf):

    def requestFailedException_async(self, cb, current=None):
        cb.ice_response()

    def unknownUserException_async(self, cb, current=None):
        cb.ice_response()

    def unknownLocalException_async(self, cb, current=None):
        cb.ice_response()

    def unknownException_async(self, cb, current=None):
        cb.ice_response()

    def localException_async(self, cb, current=None):
        cb.ice_response()

    def userException_async(self, cb, current=None):
        cb.ice_response()

    def pythonException_async(self, cb, current=None):
        cb.ice_response()

    def shutdown_async(self, cb, current=None):
        current.adapter.deactivate()
        cb.ice_response()

class CookieI(Test.Cookie):
    def message(self):
        return 'blahblah'

class ServantLocatorI(Ice.ServantLocator):
    def __init__(self, category):
        self._deactivated = False
        self._category = category

    def __del__(self):
        test(self._deactivated)

    def locate(self, current):
        test(not self._deactivated)

        test(current.id.category == self._category or self._category == "")
        
        if current.id.name == "unknown":
            return None

        test(current.id.name == "locate" or current.id.name == "finished")
        if current.id.name == "locate":
            self.exception(current)

        return (TestI(), CookieI())

    def finished(self, current, servant, cookie):
        test(not self._deactivated)

        test(current.id.category == self._category  or self._category == "")
        test(current.id.name == "locate" or current.id.name == "finished")
        
        if current.id.name == "finished":
            self.exception(current)

        test(isinstance(cookie, Test.Cookie))
        test(cookie.message() == 'blahblah')

    def deactivate(self, category):
        test(not self._deactivated)

        self._deactivated = True

    def exception(self, current):
        if current.operation == "requestFailedException":
            raise Ice.ObjectNotExistException()
        elif current.operation == "unknownUserException":
            ex = Ice.UnknownUserException()
            ex.unknown = "reason"
            raise ex
        elif current.operation == "unknownLocalException":
            ex = Ice.UnknownLocalException()
            ex.unknown = "reason"
            raise ex
        elif current.operation == "unknownException":
            ex = Ice.UnknownException()
            ex.unknown = "reason"
            raise ex
        elif current.operation == "userException":
            raise Test.TestIntfUserException()
        elif current.operation == "localException":
            ex = Ice.SocketException()
            ex.error = 0
            raise ex
        elif current.operation == "pythonException":
            raise RuntimeError("message")