1 //
2 // Copyright (c) ZeroC, Inc. All rights reserved.
3 //
4
5 #include <Ice/Ice.h>
6 #include <TestHelper.h>
7 #include <IceUtil/Options.h>
8 #include <BlobjectI.h>
9
10 using namespace std;
11
12 class ServantLocatorI : public Ice::ServantLocator
13 {
14 public:
15
ServantLocatorI(bool array,bool async)16 ServantLocatorI(bool array, bool async)
17 {
18 if(array)
19 {
20 if(async)
21 {
22 _blobject = ICE_MAKE_SHARED(BlobjectArrayAsyncI);
23 }
24 else
25 {
26 _blobject = ICE_MAKE_SHARED(BlobjectArrayI);
27 }
28 }
29 else
30 {
31 if(async)
32 {
33 _blobject = ICE_MAKE_SHARED(BlobjectAsyncI);
34 }
35 else
36 {
37 _blobject = ICE_MAKE_SHARED(BlobjectI);
38 }
39 }
40 }
41
42 #ifdef ICE_CPP11_MAPPING
43 virtual Ice::ObjectPtr
locate(const Ice::Current &,shared_ptr<void> &)44 locate(const Ice::Current&, shared_ptr<void>&)
45 {
46 return _blobject;
47 }
48
49 virtual void
finished(const Ice::Current &,const Ice::ObjectPtr &,const shared_ptr<void> &)50 finished(const Ice::Current&, const Ice::ObjectPtr&, const shared_ptr<void>&)
51 {
52 }
53 #else
54 virtual Ice::ObjectPtr
locate(const Ice::Current &,Ice::LocalObjectPtr &)55 locate(const Ice::Current&, Ice::LocalObjectPtr&)
56 {
57 return _blobject;
58 }
59
60 virtual void
finished(const Ice::Current &,const Ice::ObjectPtr &,const Ice::LocalObjectPtr &)61 finished(const Ice::Current&, const Ice::ObjectPtr&, const Ice::LocalObjectPtr&)
62 {
63 }
64 #endif
65 virtual void
deactivate(const string &)66 deactivate(const string&)
67 {
68 }
69
70 private:
71
72 Ice::ObjectPtr _blobject;
73 };
74
75 class Server : public Test::TestHelper
76 {
77 public:
78
79 void run(int, char**);
80 };
81
82 void
run(int argc,char ** argv)83 Server::run(int argc, char** argv)
84 {
85 Ice::CommunicatorHolder communicator = initialize(argc, argv);
86 IceUtilInternal::Options opts;
87 opts.addOpt("", "array");
88 opts.addOpt("", "async");
89
90 vector<string> args;
91 try
92 {
93 args = opts.parse(argc, (const char**)argv);
94 }
95 catch(const IceUtilInternal::BadOptException& e)
96 {
97 cout << argv[0] << ": error: " << e.reason << endl;
98 throw;
99 }
100 bool array = opts.isSet("array");
101 bool async = opts.isSet("async");
102
103 communicator->getProperties()->setProperty("TestAdapter.Endpoints", getTestEndpoint());
104 Ice::ObjectAdapterPtr adapter = communicator->createObjectAdapter("TestAdapter");
105 adapter->addServantLocator(ICE_MAKE_SHARED(ServantLocatorI, array, async), "");
106 adapter->activate();
107
108 serverReady();
109
110 communicator->waitForShutdown();
111 }
112
113 DEFINE_TEST(Server)
114