ICE 3.4.2
[php5-ice-freebsdport.git] / cpp / test / IceSSL / configuration / TestI.cpp
blob0cbca8041102b75198f53f956e4da8fd6a7e36ad
1 // **********************************************************************
2 //
3 // Copyright (c) 2003-2011 ZeroC, Inc. All rights reserved.
4 //
5 // This copy of Ice is licensed to you under the terms described in the
6 // ICE_LICENSE file included in this distribution.
7 //
8 // **********************************************************************
10 #include <Ice/Ice.h>
11 #include <IceUtil/Thread.h>
12 #include <TestI.h>
13 #include <TestCommon.h>
14 #include <IceSSL/Plugin.h>
16 using namespace std;
17 using namespace Ice;
19 ServerI::ServerI(const CommunicatorPtr& communicator) :
20 _communicator(communicator)
24 void
25 ServerI::noCert(const Ice::Current& c)
27 try
29 IceSSL::NativeConnectionInfoPtr info = IceSSL::NativeConnectionInfoPtr::dynamicCast(c.con->getInfo());
30 test(info->nativeCerts.size() == 0);
32 catch(const Ice::LocalException&)
34 test(false);
38 void
39 ServerI::checkCert(const string& subjectDN, const string& issuerDN, const Ice::Current& c)
41 try
43 IceSSL::NativeConnectionInfoPtr info = IceSSL::NativeConnectionInfoPtr::dynamicCast(c.con->getInfo());
44 test(info->nativeCerts.size() == 2 &&
45 info->nativeCerts[0]->getSubjectDN() == IceSSL::DistinguishedName(subjectDN) &&
46 info->nativeCerts[0]->getIssuerDN() == IceSSL::DistinguishedName(issuerDN));
48 catch(const Ice::LocalException&)
50 test(false);
54 void
55 ServerI::checkCipher(const string& cipher, const Ice::Current& c)
57 try
59 IceSSL::NativeConnectionInfoPtr info = IceSSL::NativeConnectionInfoPtr::dynamicCast(c.con->getInfo());
60 test(info->cipher.compare(0, cipher.size(), cipher) == 0);
62 catch(const Ice::LocalException&)
64 test(false);
68 void
69 ServerI::destroy()
71 _communicator->destroy();
74 Test::ServerPrx
75 ServerFactoryI::createServer(const Test::Properties& props, const Current& current)
77 InitializationData initData;
78 initData.properties = createProperties();
79 for(Test::Properties::const_iterator p = props.begin(); p != props.end(); ++p)
81 initData.properties->setProperty(p->first, p->second);
84 CommunicatorPtr communicator = initialize(initData);
85 ObjectAdapterPtr adapter = communicator->createObjectAdapterWithEndpoints("ServerAdapter", "ssl");
86 ServerIPtr server = new ServerI(communicator);
87 ObjectPrx obj = adapter->addWithUUID(server);
88 _servers[obj->ice_getIdentity()] = server;
89 adapter->activate();
91 return Test::ServerPrx::uncheckedCast(obj);
94 void
95 ServerFactoryI::destroyServer(const Test::ServerPrx& srv, const Ice::Current&)
97 map<Identity, ServerIPtr>::iterator p = _servers.find(srv->ice_getIdentity());
98 if(p != _servers.end())
100 p->second->destroy();
101 _servers.erase(p);
105 void
106 ServerFactoryI::shutdown(const Ice::Current& current)
108 test(_servers.empty());
109 current.adapter->getCommunicator()->shutdown();