μHAL (v2.8.17)
Part of the IPbus software repository
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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
30#include "uhal/ProtocolUDP.hpp"
31#include "uhal/ProtocolTCP.hpp"
34#include "uhal/ProtocolMmap.hpp"
35#include "uhal/ProtocolPCIe.hpp"
37
38#include <boost/test/unit_test.hpp>
39
40
41namespace uhal {
42namespace tests {
43
44
45template <class T>
46void 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 std::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
61template <class T>
62void checkClientFactory(const std::string& aId, const std::string& aURI)
63{
64 BOOST_TEST_MESSAGE("Creating client with ID '" << aId << "', URI '" << aURI << "'");
65 std::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
75BOOST_AUTO_TEST_SUITE( client_factory )
76
77
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
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
102BOOST_AUTO_TEST_SUITE_END()
103
104} // end ns tests
105} // end ns uhal
static ClientFactory & getInstance()
Static method to retrieve the single instance of the class.
None tests(nox.Session session)
Definition: noxfile.py:19
BOOST_CHECK_THROW(hw.getNode("REG").writeBlockOffset(xx, 0), uhal::exception::BulkTransferOffsetRequestedForSingleRegister)
BOOST_CHECK_EQUAL(mem.size(), N)
BOOST_CHECK(!mem.valid())
BOOST_AUTO_TEST_CASE(core_clients)
void checkClientFactory(const std::string &aId, const std::string &aURI, const std::vector< std::string > &aUserClientActivationList)