ChimeraTK-DeviceAccess  03.18.00
testRunTimeBackendLoading.cpp
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Deutsches Elektronen-Synchrotron DESY, MSK, ChimeraTK Project <chimeratk-support@desy.de>
2 // SPDX-License-Identifier: LGPL-3.0-or-later
3 
4 #define BOOST_TEST_DYN_LINK
5 #define BOOST_TEST_MODULE BackendLoadingTest
6 #include <boost/test/unit_test.hpp>
7 using namespace boost::unit_test_framework;
8 
9 //#include <cstdio>
10 //#include <boost/make_shared.hpp>
11 
12 #include "BackendFactory.h"
13 #include "Exception.h"
14 using namespace ChimeraTK;
15 
16 BOOST_AUTO_TEST_SUITE(BackendLoadingTestSuite)
17 
18 BOOST_AUTO_TEST_CASE(testBackendLoading) {
19  BackendFactory::getInstance().setDMapFilePath("");
20 
21  // check that we can load backends always known to the factory,
22  // but we cannot load the one coming from the plugin to exclude that we
23  // accidentally already linkes the so file we want to load
24  BOOST_CHECK_NO_THROW(BackendFactory::getInstance().createBackend("(dummy?map=goodMapFile.map)"));
25  BOOST_CHECK_THROW(
26  BackendFactory::getInstance().createBackend("(working?map=goodMapFile.map"), ChimeraTK::logic_error);
27 
28  BackendFactory::getInstance().setDMapFilePath("runtimeLoading/wrongVersionPlugin.dmap");
29  // although a plugin with a wrong version was in the dmap file, the other
30  // backends can still be opended
31  BOOST_CHECK_NO_THROW(BackendFactory::getInstance().createBackend("MY_DUMMY"));
32 
33  // Only when we access the one where loading failed we get an error
34  // (not using boost throw to print excaption.what())
35  BOOST_CHECK_THROW(BackendFactory::getInstance().createBackend("WRONG_VERSION"), ChimeraTK::logic_error);
36 
37  // Now try loading valid plugins
38  BackendFactory::getInstance().setDMapFilePath("runtimeLoading/runtimeLoading.dmap");
39  // Each call of createBackend is loading the plugins. Check that this is not
40  // causing problems.
41  BOOST_CHECK_NO_THROW(BackendFactory::getInstance().createBackend("WORKING"));
42  BOOST_CHECK_NO_THROW(BackendFactory::getInstance().createBackend("ANOTHER"));
43 }
44 
45 BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(testBackendLoading)
Definition: testRunTimeBackendLoading.cpp:18
BackendFactory.h
Exception.h
ChimeraTK
Definition: DummyBackend.h:16
ChimeraTK::logic_error
Exception thrown when a logic error has occured.
Definition: Exception.h:51