Imported Upstream version 2.81
[platform/upstream/libbullet.git] / UnitTests / cppunit / src / cppunit / PlugInManager.cpp
1 #include <cppunit/config/SourcePrefix.h>
2 #include <cppunit/XmlOutputterHook.h>
3
4 #if !defined(CPPUNIT_NO_TESTPLUGIN)
5 #include <cppunit/extensions/TestFactoryRegistry.h>
6 #include <cppunit/plugin/PlugInManager.h>
7 #include <cppunit/plugin/TestPlugIn.h>
8 #include <cppunit/plugin/DynamicLibraryManager.h>
9
10
11 CPPUNIT_NS_BEGIN
12
13
14 PlugInManager::PlugInManager()
15 {
16 }
17
18
19 PlugInManager::~PlugInManager()
20 {
21   for ( PlugIns::iterator it = m_plugIns.begin(); it != m_plugIns.end(); ++it )
22     unload( *it );
23 }
24
25
26 void
27 PlugInManager::load( const std::string &libraryFileName,
28                      const PlugInParameters &parameters )
29 {
30   PlugInInfo info;
31   info.m_fileName = libraryFileName;
32   info.m_manager = new DynamicLibraryManager( libraryFileName );
33
34   TestPlugInSignature plug = (TestPlugInSignature)info.m_manager->findSymbol( 
35         CPPUNIT_STRINGIZE( CPPUNIT_PLUGIN_EXPORTED_NAME ) );
36   info.m_interface = (*plug)();
37
38   m_plugIns.push_back( info );
39   
40   info.m_interface->initialize( &TestFactoryRegistry::getRegistry(), parameters );
41 }
42
43
44 void 
45 PlugInManager::unload( const std::string &libraryFileName )
46 {
47   for ( PlugIns::iterator it = m_plugIns.begin(); it != m_plugIns.end(); ++it )
48   {
49     if ( (*it).m_fileName == libraryFileName )
50     {
51       unload( *it );
52       m_plugIns.erase( it );
53       break;
54     }
55   }
56 }
57
58
59 void 
60 PlugInManager::addListener( TestResult *eventManager )
61 {
62   for ( PlugIns::iterator it = m_plugIns.begin(); it != m_plugIns.end(); ++it )
63     (*it).m_interface->addListener( eventManager );
64 }
65
66
67 void 
68 PlugInManager::removeListener( TestResult *eventManager )
69 {
70   for ( PlugIns::iterator it = m_plugIns.begin(); it != m_plugIns.end(); ++it )
71     (*it).m_interface->removeListener( eventManager );
72 }
73
74
75 void 
76 PlugInManager::unload( PlugInInfo &plugIn )
77 {
78   try
79   {
80     plugIn.m_interface->uninitialize( &TestFactoryRegistry::getRegistry() );
81     delete plugIn.m_manager;
82   }
83   catch (...)
84   {
85     delete plugIn.m_manager;
86     plugIn.m_manager = NULL;
87     throw;
88   }
89 }
90
91
92 void 
93 PlugInManager::addXmlOutputterHooks( XmlOutputter *outputter )
94 {
95   for ( PlugIns::iterator it = m_plugIns.begin(); it != m_plugIns.end(); ++it )
96     (*it).m_interface->addXmlOutputterHooks( outputter );
97 }
98
99
100 void 
101 PlugInManager::removeXmlOutputterHooks()
102 {
103   for ( PlugIns::iterator it = m_plugIns.begin(); it != m_plugIns.end(); ++it )
104     (*it).m_interface->removeXmlOutputterHooks();
105 }
106
107
108 CPPUNIT_NS_END
109
110 #endif // !defined(CPPUNIT_NO_TESTPLUGIN)