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  :     pluginfactory_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 <iostream>
0017 #include <sstream>
0018 
0019 // user include files
0020 #include "FWCore/PluginManager/interface/PluginManager.h"
0021 #include "FWCore/PluginManager/interface/standard.h"
0022 
0023 #include "FWCore/PluginManager/interface/PluginFactory.h"
0024 
0025 class TestPluginFactory : public CppUnit::TestFixture {
0026   CPPUNIT_TEST_SUITE(TestPluginFactory);
0027   CPPUNIT_TEST(test);
0028   CPPUNIT_TEST(testTry);
0029   CPPUNIT_TEST_SUITE_END();
0030 
0031 public:
0032   void test();
0033   void testTry();
0034   void setUp() {
0035     if (!alreadySetup_) {
0036       alreadySetup_ = true;
0037       edmplugin::PluginManager::configure(edmplugin::standard::config());
0038     }
0039   }
0040   void tearDown() {}
0041   static bool alreadySetup_;
0042 };
0043 
0044 bool TestPluginFactory::alreadySetup_ = false;
0045 
0046 ///registration of the test so that the runner can find it
0047 CPPUNIT_TEST_SUITE_REGISTRATION(TestPluginFactory);
0048 
0049 namespace edmplugintest {
0050   struct DummyBase {};
0051 
0052   struct Dummy : public DummyBase {};
0053 }  // namespace edmplugintest
0054 
0055 typedef edmplugin::PluginFactory<edmplugintest::DummyBase*(void)> FactoryType;
0056 EDM_REGISTER_PLUGINFACTORY(FactoryType, "Test Dummy");
0057 
0058 DEFINE_EDM_PLUGIN(FactoryType, edmplugintest::Dummy, "Dummy");
0059 
0060 void TestPluginFactory::test() {
0061   using namespace edmplugin;
0062 
0063   std::unique_ptr<edmplugintest::DummyBase> p(FactoryType::get()->create("Dummy"));
0064   CPPUNIT_ASSERT(0 != p.get());
0065 }
0066 
0067 void TestPluginFactory::testTry() {
0068   using namespace edmplugin;
0069   CPPUNIT_ASSERT(0 == FactoryType::get()->tryToCreate("ThisDoesNotExist"));
0070 
0071   std::unique_ptr<edmplugintest::DummyBase> p(FactoryType::get()->tryToCreate("Dummy"));
0072   CPPUNIT_ASSERT(0 != p.get());
0073 }