μHAL (v2.7.9)
Part of the IPbus software repository
test_client_factory.cpp
Go to the documentation of this file.
1 /*
2 ---------------------------------------------------------------------------
3 
4  This file is part of uHAL.
5 
6  uHAL is a hardware access library and programming framework
7  originally developed for upgrades of the Level-1 trigger of the CMS
8  experiment at CERN.
9 
10  uHAL is free software: you can redistribute it and/or modify
11  it under the terms of the GNU General Public License as published by
12  the Free Software Foundation, either version 3 of the License, or
13  (at your option) any later version.
14 
15  uHAL is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU General Public License for more details.
19 
20  You should have received a copy of the GNU General Public License
21  along with uHAL. If not, see <http://www.gnu.org/licenses/>.
22 
23  Tom Williams, Rutherford Appleton Laboratory, Oxfordshire
24  email: tom.williams <AT> cern.ch
25 
26 ---------------------------------------------------------------------------
27 */
28 
29 #include "uhal/ClientFactory.hpp"
30 #include "uhal/ProtocolUDP.hpp"
31 #include "uhal/ProtocolTCP.hpp"
32 #include "uhal/ProtocolIPbus.hpp"
34 #include "uhal/ProtocolMmap.hpp"
35 #include "uhal/ProtocolPCIe.hpp"
37 
38 #include <boost/test/unit_test.hpp>
39 
40 
41 namespace uhal {
42 namespace tests {
43 
44 
45 template <class T>
46 void checkClientFactory(const std::string& aId, const std::string& aURI, const std::vector<std::string>& aUserClientActivationList)
47 {
48  BOOST_TEST_MESSAGE("Creating client with ID '" << aId << "', URI '" << aURI << "' (" << aUserClientActivationList.size() << " user clients activated)");
49  for(size_t i=0; i < aUserClientActivationList.size(); i++) {
50  BOOST_TEST_MESSAGE(" - '" << aUserClientActivationList.at(i) << "'");
51  }
52 
53  boost::shared_ptr<ClientInterface> lClient(ClientFactory::getInstance().getClient(aId, aURI, aUserClientActivationList));
54  BOOST_REQUIRE(lClient);
55  BOOST_CHECK_EQUAL(lClient->id(), aId);
56  BOOST_CHECK_EQUAL(lClient->uri(), aURI);
57  BOOST_CHECK(typeid(*lClient) == typeid(T));
58 }
59 
60 
61 template <class T>
62 void checkClientFactory(const std::string& aId, const std::string& aURI)
63 {
64  BOOST_TEST_MESSAGE("Creating client with ID '" << aId << "', URI '" << aURI << "'");
65  boost::shared_ptr<ClientInterface> lClient(ClientFactory::getInstance().getClient(aId, aURI));
66  BOOST_REQUIRE(lClient);
67  BOOST_CHECK_EQUAL(lClient->id(), aId);
68  BOOST_CHECK_EQUAL(lClient->uri(), aURI);
69  BOOST_CHECK(typeid(*lClient) == typeid(T));
70 
71  checkClientFactory<T>(aId, aURI, std::vector<std::string>());
72 }
73 
74 
75 BOOST_AUTO_TEST_SUITE( client_factory )
76 
77 
78 BOOST_AUTO_TEST_CASE (core_clients)
79 {
80  checkClientFactory<UDP<IPbus<1,3> > >("alice", "ipbusudp-1.3://localhost:50001");
81  checkClientFactory<UDP<IPbus<2,0> > >("bob", "ipbusudp-2.0://localhost:50001");
82  checkClientFactory<TCP<IPbus<1,3>, 1 > >("charlie", "ipbustcp-1.3://localhost:50001");
83  checkClientFactory<TCP<IPbus<2,0>, 1 > >("dave", "ipbustcp-2.0://localhost:50001");
84  checkClientFactory<TCP<ControlHub < IPbus< 1 , 3 > > , 3 > >("x", "chtcp-1.3://localhost:12345?target=localhost:50001");
85  checkClientFactory<TCP<ControlHub < IPbus< 2 , 0 > > , 3 > >("y", "chtcp-2.0://localhost:12345?target=localhost:50001");
86  checkClientFactory<PCIe>("z", "ipbuspcie-2.0:///path1,/path2");
87  checkClientFactory<Mmap>("z", "ipbusmmap-2.0:///path/to/file");
88 
89  BOOST_CHECK_THROW(ClientFactory::getInstance().getClient("some_id", "unknown_protocol://localhost:50001"), exception::ProtocolDoesNotExist);
90 }
91 
92 
93 BOOST_AUTO_TEST_CASE (user_clients)
94 {
95  checkClientFactory<DummyClient>("bob", "__test__://localhost:50001", std::vector<std::string>(1, "__test__"));
96 
97  BOOST_CHECK_THROW(ClientFactory::getInstance().getClient("bob", "__test__://localhost:50001"), exception::ProtocolNotEnabled);
98  BOOST_CHECK_THROW(ClientFactory::getInstance().getClient("bob", "__test__://localhost:50001", std::vector<std::string>()), exception::ProtocolNotEnabled);
99 }
100 
101 
102 BOOST_AUTO_TEST_SUITE_END()
103 
104 } // end ns tests
105 } // end ns uhal
DummyClient.hpp
uhal::tests::BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(core_clients)
Definition: test_client_factory.cpp:78
ProtocolPCIe.hpp
boost::shared_ptr
Definition: DerivedNodeFactory.hpp:52
uhal::ClientFactory::getInstance
static ClientFactory & getInstance()
Static method to retrieve the single instance of the class.
Definition: ClientFactory.cpp:65
uhal::tests::BOOST_CHECK
BOOST_CHECK(!mem.valid())
uhal::tests::BOOST_CHECK_THROW
BOOST_CHECK_THROW(hw.getNode("REG").writeBlockOffset(xx, 0), uhal::exception::BulkTransferOffsetRequestedForSingleRegister)
ProtocolTCP.hpp
uhal
Definition: HttpResponseGrammar.hpp:49
ProtocolControlHub.hpp
ProtocolMmap.hpp
uhal::tests::checkClientFactory
void checkClientFactory(const std::string &aId, const std::string &aURI, const std::vector< std::string > &aUserClientActivationList)
Definition: test_client_factory.cpp:46
ProtocolIPbus.hpp
uhal::tests::BOOST_CHECK_EQUAL
BOOST_CHECK_EQUAL(mem.size(), N)
ProtocolUDP.hpp
ClientFactory.hpp