1 //
2 // Copyright (c) ZeroC, Inc. All rights reserved.
3 //
4 
5 #include <ServantLocatorI.h>
6 #include <TestHelper.h>
7 #include <Test.h>
8 #include <TestI.h>
9 
10 using namespace std;
11 using namespace Ice;
12 
13 class ServantLocatorI : public Test::ServantLocatorI
14 {
15 public:
16 
ServantLocatorI(const string & category)17     ServantLocatorI(const string& category) : Test::ServantLocatorI(category)
18     {
19     }
20 
21 protected:
22 
23 #ifdef ICE_CPP11_MAPPING
24     virtual Ice::ObjectPtr
newServantAndCookie(shared_ptr<void> & cookie) const25     newServantAndCookie(shared_ptr<void>& cookie) const
26     {
27         cookie = make_shared<CookieI>();
28         return make_shared<TestI>();
29     }
30 
31     virtual void
checkCookie(const shared_ptr<void> & cookie) const32     checkCookie(const shared_ptr<void>& cookie) const
33     {
34         Test::CookiePtr co = static_pointer_cast<Test::Cookie>(cookie);
35         test(co);
36         test(co->message() == "blahblah");
37     }
38 #else
39     virtual Ice::ObjectPtr
40     newServantAndCookie(Ice::LocalObjectPtr& cookie) const
41     {
42         cookie = new CookieI();
43         return new TestI();
44     }
45 
46     virtual void
47     checkCookie(const Ice::LocalObjectPtr& cookie) const
48     {
49         Test::CookiePtr co = Test::CookiePtr::dynamicCast(cookie);
50         test(co);
51         test(co->message() == "blahblah");
52     }
53 #endif
54     virtual void
throwTestIntfUserException() const55     throwTestIntfUserException() const
56     {
57         throw Test::TestIntfUserException();
58     }
59 };
60 
61 class TestActivationI : public Test::TestActivation
62 {
63 public:
64 
activateServantLocator(bool activate,const Ice::Current & current)65     void activateServantLocator(bool activate, const Ice::Current& current)
66     {
67         if(activate)
68         {
69             current.adapter->addServantLocator(ICE_MAKE_SHARED(ServantLocatorI, ""), "");
70             current.adapter->addServantLocator(ICE_MAKE_SHARED(ServantLocatorI, "category"), "category");
71         }
72         else
73         {
74             ServantLocatorPtr locator = current.adapter->removeServantLocator("");
75             locator->deactivate("");
76             locator = current.adapter->removeServantLocator("category");
77             locator->deactivate("category");
78         }
79     }
80 };
81 
82 class Collocated : public Test::TestHelper
83 {
84 public:
85 
86     void run(int, char**);
87 };
88 
89 void
run(int argc,char ** argv)90 Collocated::run(int argc, char** argv)
91 {
92     Ice::CommunicatorHolder communicator = initialize(argc, argv);
93     communicator->getProperties()->setProperty("Ice.Warn.Dispatch", "0");
94     communicator->getProperties()->setProperty("TestAdapter.Endpoints", getTestEndpoint());
95 
96     Ice::ObjectAdapterPtr adapter = communicator->createObjectAdapter("TestAdapter");
97     adapter->addServantLocator(ICE_MAKE_SHARED(ServantLocatorI, ""), "");
98     adapter->addServantLocator(ICE_MAKE_SHARED(ServantLocatorI, "category"), "category");
99     adapter->add(ICE_MAKE_SHARED(TestI), Ice::stringToIdentity("asm"));
100     adapter->add(ICE_MAKE_SHARED(TestActivationI), Ice::stringToIdentity("test/activation"));
101 
102     Test::TestIntfPrxPtr allTests(Test::TestHelper*);
103     allTests(this);
104 }
105 
106 DEFINE_TEST(Collocated)
107