File indexing completed on 2024-04-06 12:12:59
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #include <Utilities/Testing/interface/CppUnit_testdriver.icpp>
0015 #include <cppunit/extensions/HelperMacros.h>
0016 #include <functional>
0017 #include <iostream>
0018
0019
0020 #include "FWCore/PluginManager/interface/PluginFactoryManager.h"
0021 #include "FWCore/PluginManager/interface/PluginFactoryBase.h"
0022
0023 class TestPluginFactoryManager : public CppUnit::TestFixture {
0024 CPPUNIT_TEST_SUITE(TestPluginFactoryManager);
0025 CPPUNIT_TEST(test);
0026 CPPUNIT_TEST_SUITE_END();
0027
0028 public:
0029 void test();
0030 void setUp() {}
0031 void tearDown() {}
0032 };
0033
0034
0035 CPPUNIT_TEST_SUITE_REGISTRATION(TestPluginFactoryManager);
0036
0037 class DummyTestPlugin : public edmplugin::PluginFactoryBase {
0038 public:
0039 DummyTestPlugin(const std::string& iName) : name_(iName) { finishedConstruction(); }
0040 const std::string& category() const { return name_; }
0041 std::vector<edmplugin::PluginInfo> available() const { return std::vector<edmplugin::PluginInfo>(); }
0042 const std::string name_;
0043 };
0044
0045 struct Catcher {
0046 std::string lastSeen_;
0047
0048 void catchIt(const edmplugin::PluginFactoryBase* iFactory) { lastSeen_ = iFactory->category(); }
0049 };
0050
0051 void TestPluginFactoryManager::test() {
0052 using namespace edmplugin;
0053 using std::placeholders::_1;
0054 PluginFactoryManager& pfm = *(PluginFactoryManager::get());
0055 CPPUNIT_ASSERT(pfm.begin() == pfm.end());
0056
0057 Catcher catcher;
0058 pfm.newFactory_.connect(std::bind(std::mem_fn(&Catcher::catchIt), &catcher, _1));
0059
0060 DummyTestPlugin one("one");
0061 CPPUNIT_ASSERT((pfm.begin() != pfm.end()));
0062 CPPUNIT_ASSERT(catcher.lastSeen_ == std::string("one"));
0063 }