LibraryManager_t.cc
Go to the documentation of this file.
2 
3 #define BOOST_TEST_MODULE (LibraryManager Test)
4 #include "boost/test/unit_test.hpp"
5 
7 #include "cetlib_except/exception.h"
8 
9 #include <iterator>
10 #include <string>
11 #include <vector>
12 
13 using namespace cet;
14 
15 // LibraryManager tests are independent of how it's constructed so
16 // make test fixture creation compile time generated. This allows >1
17 // test to be built.
18 #if defined(LIBRARY_MANAGER_SEARCH_PATH)
19 // Construction using search_path
21 
23 
24  LibraryManager lm;
25  LibraryManager const& lm_ref;
26 };
27 
29  : lm{search_path{"LIBRARY_MANAGER_SEARCH_PATH"}, "cetlibtest"}, lm_ref{lm}
30 {}
31 #else
32 // Default construction, should use system dynamic loader path
34 
36 
39 };
40 
42  : lm{"cetlibtest"}, lm_ref{lm}
43 {}
44 #endif
45 
46 BOOST_FIXTURE_TEST_SUITE(LibraryManagerTests, LibraryManagerTestFixture)
47 
48 BOOST_AUTO_TEST_CASE(libSpecsVector)
49 {
50  std::vector<std::string> lib_list;
52 }
53 
54 BOOST_AUTO_TEST_CASE(libSpecsIter)
55 {
56  std::vector<std::string> lib_list;
57  BOOST_TEST_REQUIRE(lm_ref.getValidLibspecs(std::back_inserter(lib_list)) > 0);
58 }
59 
60 BOOST_AUTO_TEST_CASE(libListVector)
61 {
62  std::vector<std::string> lib_list;
64 }
65 
67 {
68  std::vector<std::string> lib_list;
69  BOOST_TEST_REQUIRE(lm_ref.getLoadableLibraries(std::back_inserter(lib_list)) >
70  0);
71 }
72 
73 BOOST_AUTO_TEST_CASE(getSymbolLong)
74 {
75  BOOST_TEST_REQUIRE(lm_ref.getSymbolByLibspec<void*>("2/1/5", "idString") !=
76  nullptr);
77 }
78 
79 BOOST_AUTO_TEST_CASE(getSymbolShort)
80 {
81  BOOST_TEST_REQUIRE(lm_ref.getSymbolByLibspec<void*>("5", "idString") !=
82  nullptr);
83 }
84 
85 BOOST_AUTO_TEST_CASE(getSymbolPathPrecedence)
86 {
87  BOOST_CHECK_NO_THROW(lm_ref.getSymbolByLibspec<void*>("1/1/1", "idString"));
88 }
89 
90 BOOST_AUTO_TEST_CASE(getSymbolAmbiguity)
91 {
92  BOOST_CHECK_EXCEPTION(
93  lm_ref.getSymbolByLibspec<void*>("3", "idString"),
95  [](cet::exception const& e) { return e.category() == "Configuration"; });
96 }
97 
98 namespace {
99  void
100  verify(std::string libspec, cettest::idString_t idString)
101  {
102  std::size_t pos{};
103  while ((pos = libspec.find_first_of('/', pos)) != std::string::npos) {
104  libspec[pos] = '_';
105  }
106  BOOST_TEST_REQUIRE(libspec == idString());
107  }
108 }
109 
110 BOOST_AUTO_TEST_CASE(getSymbolNoAmbiguity1)
111 {
112  std::string const libspecA{"1/2/3"};
113  std::string const libspecB{"1/1/3"};
114  cettest::idString_t idString{nullptr};
115  BOOST_CHECK_NO_THROW(
116  idString =
117  lm_ref.getSymbolByLibspec<cettest::idString_t>(libspecA, "idString"));
118  verify(libspecA, idString);
119  BOOST_CHECK_NO_THROW(
120  idString =
121  lm_ref.getSymbolByLibspec<cettest::idString_t>(libspecB, "idString"));
122  verify(libspecB, idString);
123  BOOST_CHECK_NO_THROW(
124  idString =
125  lm_ref.getSymbolByLibspec<cettest::idString_t>(libspecA, "idString"));
126  verify(libspecA, idString);
127 }
128 
129 BOOST_AUTO_TEST_CASE(getSymbolNoAmbiguity2)
130 {
131  std::string const libspecA{"1/1/3"};
132  std::string const libspecB{"1/2/3"};
133  cettest::idString_t idString{nullptr};
134  BOOST_CHECK_NO_THROW(
135  idString =
136  lm_ref.getSymbolByLibspec<cettest::idString_t>(libspecA, "idString"));
137  verify(libspecA, idString);
138  BOOST_CHECK_NO_THROW(
139  idString =
140  lm_ref.getSymbolByLibspec<cettest::idString_t>(libspecB, "idString"));
141  verify(libspecB, idString);
142  BOOST_CHECK_NO_THROW(
143  idString =
144  lm_ref.getSymbolByLibspec<cettest::idString_t>(libspecA, "idString"));
145  verify(libspecA, idString);
146 }
147 
148 BOOST_AUTO_TEST_CASE(dictLoadable)
149 {
150  std::vector<std::string> lib_list;
151  lm_ref.getLoadableLibraries(lib_list);
152  BOOST_TEST_REQUIRE(lm_ref.libraryIsLoadable(*lib_list.begin()));
153 }
154 
155 BOOST_AUTO_TEST_CASE(dictLoadableButNotLoaded)
156 {
157  std::vector<std::string> lib_list;
158  lm_ref.getLoadableLibraries(lib_list);
159  BOOST_TEST_REQUIRE(lm_ref.libraryIsLoadable(*lib_list.begin()));
160  BOOST_TEST_REQUIRE(!lm_ref.libraryIsLoaded(*lib_list.begin()));
161 }
162 
163 BOOST_AUTO_TEST_CASE(loadAllLibraries)
164 {
165  BOOST_REQUIRE_NO_THROW(lm_ref.loadAllLibraries());
166 }
167 
169 {
170  std::vector<std::string> lib_list;
171  lm_ref.getLoadableLibraries(lib_list);
173  BOOST_TEST_REQUIRE(lm_ref.libraryIsLoaded(*lib_list.begin()));
174 }
175 
176 BOOST_AUTO_TEST_CASE(dictNotLoadable)
177 {
178  std::vector<std::string> lib_list;
179  lm_ref.getLoadableLibraries(lib_list);
180  BOOST_TEST_REQUIRE(!lm_ref.libraryIsLoadable("UnknownLibrary"));
181 }
182 
183 BOOST_AUTO_TEST_SUITE_END()
size_t getValidLibspecs(std::vector< std::string > &list) const
LibraryManager const & lm_ref
std::string string
Definition: nybbler.cc:12
bool libraryIsLoadable(std::string const &path) const
BOOST_TEST_REQUIRE(static_cast< bool >(inFile))
T getSymbolByLibspec(std::string const &libspec, std::string const &sym_name) const
const double e
size_t getLoadableLibraries(std::vector< std::string > &list) const
void loadAllLibraries() const
bool libraryIsLoaded(std::string const &path) const
std::string(*)( idString_t)
BOOST_AUTO_TEST_CASE(libSpecsVector)
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33