PluginFactory_t.cc
Go to the documentation of this file.
1 #define BOOST_TEST_MODULE (PluginFactory_t)
2 #include "boost/test/unit_test.hpp"
3 
7 #include "cetlib_except/exception.h"
8 
9 #include <memory>
10 #include <string>
11 
12 using namespace cet;
13 
14 // PluginFactory tests are independent of how its search path is
15 // constructed.
16 
17 // Make test fixture creation compile time generated so we can
18 // generated one test for the system default, and one for a
19 // user-supplied search path.
20 #if defined(PLUGIN_FACTORY_SEARCH_PATH)
22  explicit PluginFactoryTestFixture() { pf.setDiagReleaseVersion("ETERNAL"); }
23  BasicPluginFactory pf{search_path{"PLUGIN_FACTORY_SEARCH_PATH"}};
24 };
25 #else
27  explicit PluginFactoryTestFixture() { pf.setDiagReleaseVersion("ETERNAL"); }
29 };
30 #endif
31 
32 using namespace std::string_literals;
33 
34 BOOST_FIXTURE_TEST_SUITE(PluginFactory_t, PluginFactoryTestFixture)
35 
37 {
38  BOOST_TEST_REQUIRE("TestPluginBase"s ==
39  PluginTypeDeducer_v<cettest::TestPluginBase>);
40  BOOST_TEST_REQUIRE(pf.pluginType("TestPlugin") ==
41  PluginTypeDeducer_v<cettest::TestPluginBase>);
42 }
43 
45 {
46  auto p = pf.makePlugin<std::unique_ptr<cettest::TestPluginBase>, std::string>(
47  "TestPlugin", "Hi");
48  BOOST_TEST_REQUIRE(p->message() == "Hi"s);
49 }
50 
52 {
53  auto fptr = pf.find<std::string>(
54  "TestPlugin", "pluginType", cet::PluginFactory::nothrow);
55  BOOST_TEST_REQUIRE(fptr);
56  BOOST_TEST_REQUIRE(fptr() == PluginTypeDeducer_v<cettest::TestPluginBase>);
58  pf.find<std::string>("TestPlugin", "oops", cet::PluginFactory::nothrow) ==
59  nullptr);
60 }
61 
63 {
64  BOOST_CHECK_EXCEPTION(pf.makePlugin<std::unique_ptr<cettest::TestPluginBase>>(
65  "TestPluginX"s, "Hi"s),
67  [](cet::exception const& e) {
68  return e.category() == "Configuration" &&
69  std::string{e.what()}.find("ETERNAL") !=
70  std::string::npos;
71  });
72 }
73 
74 BOOST_AUTO_TEST_SUITE_END()
std::string string
Definition: nybbler.cc:12
static LibraryManager::nothrow_t nothrow
Definition: PluginFactory.h:54
BOOST_TEST_REQUIRE(static_cast< bool >(inFile))
BOOST_AUTO_TEST_CASE(checkType)
const double e
p
Definition: test.py:223
static QCString * s
Definition: config.cpp:1042
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33