summaryrefslogtreecommitdiff
path: root/cpp/test/Ice/servantLocator/ServantLocatorI.cpp
blob: 39900eb1c7577139ed7c21e0669e3f6bdc1b2434 (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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
// **********************************************************************
//
// Copyright (c) 2003-2009 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.
//
// **********************************************************************

#include <ServantLocatorI.h>
#include <Test.h>
#include <TestCommon.h>

#include <stdexcept>

using namespace std;
using namespace Ice;
using namespace Test;

ServantLocatorI::ServantLocatorI(const string& category) :
    _category(category),
    _deactivated(false)
{
}

ServantLocatorI::~ServantLocatorI()
{
    test(_deactivated);
}

Ice::ObjectPtr
ServantLocatorI::locate(const Ice::Current& current, Ice::LocalObjectPtr& cookie)
{
    test(!_deactivated);
    test(current.id.category == _category || _category.empty());

    if(current.id.name == "unknown")
    {
        return 0;
    }

    test(current.id.name == "locate" || current.id.name == "finished");
    if(current.id.name == "locate")
    {
        exception(current);
    }

    return newServantAndCookie(cookie);
}

void
ServantLocatorI::finished(const Ice::Current& current, const Ice::ObjectPtr& servant,
                          const Ice::LocalObjectPtr& cookie)
{
    test(!_deactivated);
    test(current.id.category == _category  || _category.empty());
    test(current.id.name == "locate" || current.id.name == "finished");

    if(current.id.name == "finished")
    {
        exception(current);
    }

    checkCookie(cookie);
}

void
ServantLocatorI::deactivate(const string&)
{
    test(!_deactivated);

    _deactivated = true;
}

void
ServantLocatorI::exception(const Ice::Current& current)
{
    if(current.operation == "ice_ids")
    {
        throw Test::TestIntfUserException();
    }
    else if(current.operation == "requestFailedException")
    {
        throw Ice::ObjectNotExistException(__FILE__, __LINE__);
    }
    else if(current.operation == "unknownUserException")
    {
        throw UnknownUserException(__FILE__, __LINE__, "reason");
    }
    else if(current.operation == "unknownLocalException")
    {
        throw UnknownLocalException(__FILE__, __LINE__, "reason");
    }
    else if(current.operation == "unknownException")
    {
        throw UnknownException(__FILE__, __LINE__, "reason");
    }
    else if(current.operation == "userException")
    {
        throwTestIntfUserException();
    }
    else if(current.operation == "localException")
    {
        throw Ice::SocketException(__FILE__, __LINE__, 0);
    }
    else if(current.operation == "stdException")
    {
        throw std::runtime_error("Hello");
    }
    else if(current.operation == "cppException")
    {
        throw 5;
    }
    else if(current.operation == "unknownExceptionWithServantException")
    {
        throw UnknownException(__FILE__, __LINE__, "reason");
    }
    else if(current.operation == "impossibleException")
    {
        throw TestIntfUserException(); // Yes, it really is meant to be TestIntfUserException.
    }
    else if(current.operation == "intfUserException")
    {
        throw TestImpossibleException(); // Yes, it really is meant to be TestImpossibleException.
    }
}