Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:12:59

0001 // -*- C++ -*-
0002 //
0003 // Package:     PluginManager
0004 // Class  :     pluginfactorymanager_t
0005 //
0006 // Implementation:
0007 //     <Notes on implementation>
0008 //
0009 // Original Author:  Chris Jones
0010 //         Created:  Wed Apr  4 13:38:29 EDT 2007
0011 //
0012 
0013 // system include files
0014 #include <Utilities/Testing/interface/CppUnit_testdriver.icpp>
0015 #include <cppunit/extensions/HelperMacros.h>
0016 #include <functional>
0017 #include <iostream>
0018 
0019 // user include files
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 ///registration of the test so that the runner can find it
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 }