20 #define LIBRARY_EXPORTS 23 #include <cppunit/ui/text/TestRunner.h> 24 #include <cppunit/TextOutputter.h> 25 #include <cppunit/extensions/TestFactoryRegistry.h> 26 #include <cppunit/extensions/HelperMacros.h> 27 #include <cppunit/TestAssert.h> 29 #include <coil/Factory.h> 30 #include <coil/DynamicLib.h> 34 #if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__) 35 const char *
LibName =
"FactoryTest_libPluginC.dll";
37 const char *
LibName =
"./.libs/libPluginC.so";
76 :
public CppUnit::TestFixture
79 CPPUNIT_TEST(test_case0);
80 CPPUNIT_TEST(test_case1);
81 CPPUNIT_TEST(test_case2);
82 CPPUNIT_TEST_SUITE_END();
119 std::string Astr(
"A");
120 std::string Bstr(
"B");
122 coil::Creator<Base, A>,
123 coil::Destructor<Base, A>);
125 coil::Creator<Base, B>,
126 coil::Destructor<Base, B>);
130 for (
int i(0); i < 1000; ++i)
133 CPPUNIT_ASSERT(a->
name() ==
"A");
136 CPPUNIT_ASSERT(b->name() ==
"B");
139 CPPUNIT_ASSERT(a == 0);
142 CPPUNIT_ASSERT(b == 0);
148 std::string Astr(
"A");
149 std::string Bstr(
"B");
151 coil::Creator<Base, A>,
152 coil::Destructor<Base, A>);
154 coil::Creator<Base, B>,
155 coil::Destructor<Base, B>);
160 std::cout <<
"dl.open error" << std::endl;
163 typedef void (*InitFunc)();
164 InitFunc init_func = (InitFunc)dl.
symbol(
"PluginCInit");
165 if (init_func == NULL)
167 std::cout <<
"synbol is NULL" << std::endl;
173 std::cout <<
"Factory C exists" << std::endl;
177 std::cout <<
"Factory C does not exist" << std::endl;
181 std::cout <<
"IDs -> ";
182 for (
int i(0), len(ids.size()); i < len; ++i)
184 std::cout << ids[i] <<
", ";
187 for (
int i(0); i < 1000; ++i)
190 CPPUNIT_ASSERT(a->
name() ==
"A");
193 CPPUNIT_ASSERT(b->name() ==
"B");
196 CPPUNIT_ASSERT(c->name() ==
"C");
199 CPPUNIT_ASSERT(a == 0);
202 CPPUNIT_ASSERT(b == 0);
205 CPPUNIT_ASSERT(c == 0);
216 std::string Astr(
"A");
217 std::string Bstr(
"B");
219 coil::Creator<Base, A>,
220 coil::Destructor<Base, A>);
225 coil::Creator<Base, B>,
226 coil::Destructor<Base, B>);
233 std::cout <<
"dl.open error" << std::endl;
236 typedef void (*InitFunc)();
237 InitFunc init_func = (InitFunc)dl.
symbol(
"PluginCInit");
238 if (init_func == NULL)
240 std::cout <<
"synbol is NULL" << std::endl;
248 for (
int i(0), len(ids.size()); i < len; ++i)
268 int main(
int argc,
char* argv[])
270 CppUnit::TextUi::TestRunner runner;
271 runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
272 CppUnit::Outputter* outputter =
273 new CppUnit::TextOutputter(&runner.result(), std::cout);
274 runner.setOutputter(outputter);
279 #endif // Factory_cpp CPPUNIT_TEST_SUITE_REGISTRATION(Factory::FactoryTests)
int main(int argc, char **argv)
virtual std::string name()=0
void * symbol(const char *symbol_name)
Return an address of the memory where a symbol was loaded.
coil::Factory< Base > m_factory
FactoryTests()
Constructor.
virtual std::string name()
RTC::ReturnCode_t ret(RTC::Local::ReturnCode_t r)
ReturnCode addFactory(const Identifier &id, Creator creator, Destructor destructor)
Add factory.
static GlobalFactory< AbstractClass, Identifier, Compare, Creator, Destructor > & instance()
Create instance.
GlobalFactory template class.
virtual void tearDown()
Test finalization.
void deleteObject(const Identifier &id, AbstractClass *&obj)
Delete factory object.
AbstractClass * createObject(const Identifier &id)
Create factory object.
virtual void setUp()
Test initialization.
~FactoryTests()
Destructor.
virtual std::string name()
virtual int open(const char *dll_name, int open_mode=COIL_DEFAULT_DYNLIB_MODE, int close_handle_on_destruction=1)
Load of the Dynamic link library.