40 #ifndef ModuleManager_cpp 41 #define ModuleManager_cpp 43 #include <cppunit/ui/text/TestRunner.h> 44 #include <cppunit/TextOutputter.h> 45 #include <cppunit/extensions/TestFactoryRegistry.h> 46 #include <cppunit/extensions/HelperMacros.h> 47 #include <cppunit/TestAssert.h> 50 #include <coil/Properties.h> 59 :
public CppUnit::TestFixture
83 bool isFound(
const std::vector<coil::Properties>&
path,
const std::string& mod)
85 for (
int i(0), len(path.size()); i < len; ++i)
87 if (mod == path[i][
"file_path"])
return true;
112 const char* default_properties[] =
114 "manager.modules.config_ext",
"so",
115 "manager.modules.config_path",
"/etc/rtc",
116 "manager.modules.detect_loadable",
"Yes",
117 "manager.modules.load_path",
118 "../../.libs, .libs, /usr/lib, /usr/local/lib, /usr/local/lib/rtc",
119 "manager.modules.init_func_suffix",
"Init",
120 "manager.modules.init_func_prefix",
"",
121 "manager.modules.abs_path_allowed",
"Yes",
122 "manager.modules.download_allowed",
"Yes",
123 "manager.modules.download_dir",
"/tmp/rtc",
124 "manager.modules.download_cleanup",
"Yes",
125 "manager.modules.preload",
"",
133 m_pModMgr->
load(
"libRTC.so");
136 m_pModMgr->
load(
"libm.so");
190 CPPUNIT_FAIL(
"Error" + e.
reason);
194 CPPUNIT_FAIL(
"NotFound" + e.
name);
198 CPPUNIT_FAIL(
"NotAllowedOperation");
202 CPPUNIT_FAIL(
"InvalidArguments");
206 CPPUNIT_FAIL(
"FileNotFound" + e.
name);
210 CPPUNIT_FAIL(
"Other Exception");
220 m_pModMgr->
load(
"libm.a");
224 if (notThrown) CPPUNIT_FAIL(
"Exception not thrown.");
230 m_pModMgr->
load(
"inexist-file");
234 if (notThrown) CPPUNIT_FAIL(
"Exception not thrown.");
245 std::vector<std::string> loadPath = m_pModMgr->
getLoadPath();
248 std::vector<std::string> emptyPath;
253 bool notThrown =
false;
256 m_pModMgr->
load(
"libm.so");
260 if (notThrown) CPPUNIT_FAIL(
"Exception not thrown.");
266 std::string modName = m_pModMgr->
load(
"libm.so");
283 std::string modName1 = m_pModMgr->
load(
"libRTC.so");
286 std::string modName2 = m_pModMgr->
load(
"libm.so");
291 m_pModMgr->
unload(modName1);
302 m_pModMgr->
unload(
"libm.so");
303 CPPUNIT_FAIL(
"Exception not thrown.");
310 m_pModMgr->
unload(
"non-loaded-module.so");
311 CPPUNIT_FAIL(
"Exception not thrown.");
318 m_pModMgr->
unload(modName1);
319 CPPUNIT_FAIL(
"Exception not thrown.");
332 std::string modName1 = m_pModMgr->
load(
"libRTC.so");
335 std::string modName2 = m_pModMgr->
load(
"libm.so");
352 typedef double (*FUNCTION_COS)(double);
353 typedef double (*FUNCTION_SIN)(double);
356 std::string modName = m_pModMgr->
load(
"libm.so");
360 FUNCTION_COS func_cos = (FUNCTION_COS) m_pModMgr->
symbol(modName,
"cos");
361 CPPUNIT_ASSERT(func_cos != NULL);
364 FUNCTION_SIN func_sin = (FUNCTION_SIN) m_pModMgr->
symbol(modName,
"sin");
365 CPPUNIT_ASSERT(func_sin != NULL);
368 CPPUNIT_ASSERT_EQUAL(1.0, (*func_cos)(0.0));
369 CPPUNIT_ASSERT_EQUAL(0.0, (*func_sin)(0.0));
381 std::vector<std::string> loadPath;
382 loadPath.push_back(
"/usr");
383 loadPath.push_back(
"/usr/lib");
387 std::vector<std::string> loadPathRet = m_pModMgr->
getLoadPath();
388 CPPUNIT_ASSERT_EQUAL(2, (
int) loadPathRet.size());
389 CPPUNIT_ASSERT_EQUAL(std::string(
"/usr"), loadPathRet[0]);
390 CPPUNIT_ASSERT_EQUAL(std::string(
"/usr/lib"), loadPathRet[1]);
401 std::vector<std::string> loadPath1;
402 loadPath1.push_back(
"/usr");
403 loadPath1.push_back(
"/usr/lib");
404 std::sort(loadPath1.begin(), loadPath1.end());
406 std::vector<std::string> loadPath2;
407 loadPath2.push_back(
"/usr/local/lib");
408 loadPath2.push_back(
"/usr/local/lib/rtc");
409 std::sort(loadPath2.begin(), loadPath2.end());
411 std::vector<std::string> expectedPath;
412 expectedPath.push_back(
"/usr");
413 expectedPath.push_back(
"/usr/lib");
414 expectedPath.push_back(
"/usr/local/lib");
415 expectedPath.push_back(
"/usr/local/lib/rtc");
416 std::sort(expectedPath.begin(), expectedPath.end());
419 std::vector<std::string> loadPathRet;
422 CPPUNIT_ASSERT_EQUAL(2, (
int) loadPathRet.size());
423 for (
int i = 0; i < 2; ++i) {
424 CPPUNIT_ASSERT_EQUAL(loadPath1[i], loadPathRet[i]);
430 CPPUNIT_ASSERT_EQUAL(4, (
int) loadPathRet.size());
431 for (
int i = 0; i < 4; ++i) {
432 CPPUNIT_ASSERT_EQUAL(expectedPath[i], loadPathRet[i]);
450 int len = props.size();
451 CPPUNIT_ASSERT(len > 0);
454 for(
int i(0); i<len; ++i)
456 if(props[i].getProperty(
"module_file_name") ==
"DummyModule1.so")
462 CPPUNIT_ASSERT(bret);
475 std::string modName = m_pModMgr->
load(
"/usr/lib/libm.so");
483 m_pModMgr->
load(
"/usr/lib/libm.so");
484 CPPUNIT_FAIL(
"Exception not thrown.");
514 std::vector<std::string>
path;
515 path.push_back(
"/usr/lib");
518 CPPUNIT_ASSERT_EQUAL(std::string(
"/usr/lib/libm.so"),
519 m_pModMgr->
findFile(
"libm.so", path));
522 CPPUNIT_ASSERT_EQUAL(std::string(
""),
523 m_pModMgr->
findFile(
"inexist-file.so", path));
536 CPPUNIT_ASSERT(m_pModMgr->
fileExist(
"/usr/lib/libm.so"));
539 CPPUNIT_ASSERT(! m_pModMgr->
fileExist(
"/usr/lib/inexistent-file.so"));
542 CPPUNIT_ASSERT(m_pModMgr->
fileExist(
"/usr//lib/../lib/libm.so"));
553 CPPUNIT_ASSERT_EQUAL(std::string(
"ManipulatorInit"),
556 CPPUNIT_ASSERT_EQUAL(std::string(
"PHANToMInit"),
569 int main(
int argc,
char* argv[])
582 std::string arg(argv[i]);
583 std::string next_arg;
584 if (i + 1 < argc) next_arg = argv[i + 1];
587 if (arg ==
"--text") { format =
TEXT_OUT;
break; }
600 ofs.open(fname.c_str());
602 if ( arg ==
"--compiler" ) { format =
COMPILER_OUT;
break; }
603 if ( arg ==
"--cerr" ) { target = 1;
break; }
604 if ( arg ==
"--xsl" )
606 if (next_arg ==
"") xsl =
"default.xsl";
609 if ( arg ==
"--namespace" )
613 std::cerr <<
"no namespace specified" << std::endl;
623 CppUnit::TextUi::TestRunner runner;
625 runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
627 runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest());
628 CppUnit::Outputter* outputter = 0;
629 std::ostream* stream = target ? &std::cerr : &std::cout;
633 outputter =
new CppUnit::TextOutputter(&runner.result(),*stream);
636 std::cout <<
"XML_OUT" << std::endl;
637 outputter =
new CppUnit::XmlOutputter(&runner.result(),
639 static_cast<CppUnit::XmlOutputter*
>(outputter)->setStyleSheet(xsl);
642 outputter =
new CppUnit::CompilerOutputter(&runner.result(),*stream);
645 runner.setOutputter(outputter);
650 #endif // ModuleManager_cpp void * symbol(const std::string &file_name, const std::string &func_name)
Refer to the symbol of the module.
Structure for exception handling of unimplemented part and specified module missing.
int main(int argc, char **argv)
void test_addLoadpath()
addLoadpath()メソッドのテスト
std::string getInitFuncName(const std::string &file_path)
Create initialization function symbol.
void test_getLoadedModules()
getLoadedModules()メソッドのテスト
Structure for exception handling when file open is failed.
void addLoadpath(const std::vector< std::string > &load_path)
Add the module load path.
std::vector< coil::Properties > getLoadableModules()
Get the loadable module list.
ModuleManagerTests()
Constructor.
void test_unload()
unload()メソッドのテスト
void setLoadpath(const std::vector< std::string > &load_path)
Set the module load path.
void disallowAbsolutePath()
Disallow absolute path when specify module path.
void test_getLoadableModules()
getLoadableModules()メソッドのテスト
std::string load(const std::string &file_name)
Load the module.
void allowAbsolutePath()
Allow absolute path when specify module path.
std::vector< coil::Properties > getLoadedModules()
Get the module list that has been loaded.
void test_disallowModuleDownload()
disallowModuleDownload()メソッドのテスト
void test_setLoadpath_and_getLoadPath()
setLoadpath()とgetLoadPath()のテスト
Structure for exception handling when specified argument is invalid.
bool fileExist(const std::string &filename)
Check whether the file exists.
void test_allowAbsolutePath_and_disallowAbsolutePath()
allowAbsolutePath()メソッドとdisallowAbsolutePath()メソッドのテスト
virtual void setUp()
Test initialization.
void test_load()
load()メソッドのテスト
void test_getInitFuncName()
getInitFuncName()メソッドのテスト
Loadable modules manager class.
void test_load_inexistent_on_load_path()
load()メソッドのテスト
bool isFound(const std::vector< coil::Properties > &path, const std::string &mod)
prop
Organization::get_organization_property ();.
void test_fileExist()
fileExist()メソッドのテスト
void test_findFile()
findFile()メソッドのテスト
std::vector< std::string > getLoadPath()
Get the module load path.
Class represents a set of properties.
void unloadAll()
Unload all modules.
Structure for exception handling when specified file cannot be found.
void test_unloadAll()
unloadAll()メソッドのテスト
void unload(const std::string &file_name)
Unload the module.
RTC::ModuleManager * m_pModMgr
virtual void tearDown()
Test finalization.
std::string findFile(const std::string &fname, const std::vector< std::string > &load_path)
Search the file from the LoadPath.
void test_symbol()
symbol()メソッドのテスト
CPPUNIT_TEST_SUITE(ModuleManagerTests)
CPPUNIT_TEST_SUITE_REGISTRATION(ModuleManager::ModuleManagerTests)
void test_allowModuleDownload()
allowModuleDownload()メソッドのテスト
Structure for exception handling when specified operation cannot be allowed.
~ModuleManagerTests()
Destructor.