11 #include <cppunit/ui/text/TestRunner.h> 12 #include <cppunit/TextOutputter.h> 13 #include <cppunit/extensions/TestFactoryRegistry.h> 14 #include <cppunit/extensions/HelperMacros.h> 15 #include <cppunit/TestAssert.h> 17 #include "../ModuleManager.h" 18 #include "../Properties.h" 24 :
public CppUnit::TestFixture
27 CPPUNIT_TEST(test_load);
28 CPPUNIT_TEST(test_unload);
29 CPPUNIT_TEST(test_unloadAll);
30 CPPUNIT_TEST(test_symbol);
31 CPPUNIT_TEST(test_setLoadpath);
32 CPPUNIT_TEST(test_getLoadPath);
33 CPPUNIT_TEST(test_addLoadpath);
34 CPPUNIT_TEST(test_getLoadedModules);
35 CPPUNIT_TEST(test_getLoadableModules);
36 CPPUNIT_TEST(test_allowAbsolutePath);
37 CPPUNIT_TEST(test_disallowAbsolutePath);
38 CPPUNIT_TEST(test_allowModuleDownload);
39 CPPUNIT_TEST(test_disallowModuleDownload);
40 CPPUNIT_TEST(test_findFile);
41 CPPUNIT_TEST(test_fileExist);
42 CPPUNIT_TEST(test_getInitFuncName);
43 CPPUNIT_TEST_SUITE_END();
70 const char* default_properties[] = {
71 "manager.modules.config_ext",
"so",
72 "manager.modules.config_path",
"/etc/rtc",
73 "manager.modules.detect_loadable",
"Yes",
74 "manager.modules.load_path",
"/usr/lib, /usr/local/lib, /usr/local/lib/rtc",
75 "manager.modules.init_func_suffix",
"Init",
76 "manager.modules.init_func_prefix",
"",
77 "manager.modules.abs_path_allowed",
"Yes",
78 "manager.modules.download_allowed",
"Yes",
79 "manager.modules.download_dir",
"/tmp/rtc",
80 "manager.modules.download_cleanup",
"Yes",
81 "manager.modules.preload",
"",
87 m_pModMgr->
load(
"libRTC.so");
88 m_pModMgr->
load(
"libm.so");
107 libname = m_pModMgr->
load(
"libRTC.so");
108 CPPUNIT_ASSERT(libname ==
"/usr/lib/libRTC.so");
110 libname = m_pModMgr->
load(
"libRTC.so");
111 CPPUNIT_ASSERT(libname ==
"/usr/lib/libRTC.so");
113 libname = m_pModMgr->
load(
"libRTC.so");
114 CPPUNIT_ASSERT(libname ==
"/usr/lib/libRTC.so");
117 libname = m_pModMgr->
load(
"/usr/lib/libRTC.so");
118 CPPUNIT_ASSERT(libname ==
"/usr/lib/libRTC.so");
121 libname = m_pModMgr->
load(
"/usr//users/kurihara/../kurihara/Components/test/test.so");
122 CPPUNIT_ASSERT(libname ==
"/usr//users/kurihara/../kurihara/Components/test/test.so");
147 std::cout <<
"Error " << e.
reason << std::endl;
151 std::cout <<
"NotFound " << e.
name << std::endl;
155 std::cout <<
"other exception" << std::endl;
165 libname = m_pModMgr->
load(
"libRTC.so");
166 CPPUNIT_ASSERT(libname ==
"/usr/lib/libRTC.so");
169 m_pModMgr->
unload(
"/usr/lib/libRTC.so");
170 m_pModMgr->
unload(
"/usr/lib/libm.so");
187 std::cout <<
"Error " << e.
reason << std::endl;
191 std::cout <<
"NotFound " << e.
name << std::endl;
195 std::cout <<
"other exception" << std::endl;
209 std::cout <<
"Error " << e.
reason << std::endl;
213 std::cout <<
"NotFound " << e.
name << std::endl;
217 std::cout <<
"other exception" << std::endl;
230 libname = m_pModMgr->
load(
"libm.so");
234 std::cout <<
"Error " << e.
reason << std::endl;
238 std::cout <<
"NotFound " << e.
name << std::endl;
242 std::cout <<
"other exception" << std::endl;
245 typedef double (*cosine)(double);
246 typedef double (*sine)(double);
251 _cos = (cosine) m_pModMgr->
symbol(libname,
"cos");
254 CPPUNIT_ASSERT_MESSAGE(
"load error: cos(0.0)",
255 (*_cos)(0.0) == 1.0);
256 CPPUNIT_ASSERT_MESSAGE(
"load error: cos(pi/2)",
257 (*_cos)(3.141592653589793238462643383279/2) < 0.01);
259 _sin = (sine) m_pModMgr->
symbol(libname,
"sin");
262 CPPUNIT_ASSERT_MESSAGE(
"load error: sin(0.0)",
263 (*_sin)(0.0) == 0.0);
264 CPPUNIT_ASSERT_MESSAGE(
"load error: sin(pi/2)",
265 (*_sin)(3.141592653589793238462643383279/2) == 1.0);
269 libname = m_pModMgr->
load(
"/usr/users/kurihara/RTM/Components/test/test.so");
270 typedef void (*testHello)();
274 _th = (testHello) m_pModMgr->
symbol(libname,
"_ZN4test5helloEv");
281 vector<string> set_loadpath, get_loadpath;
282 set_loadpath.push_back(
"/usr");
283 set_loadpath.push_back(
"/usr/lib");
284 set_loadpath.push_back(
"/usr/local/lib");
285 set_loadpath.push_back(
"/tmp");
286 set_loadpath.push_back(
"/usr/users/aaaaaaaaaaa/bbbbbbbbbbbb/ccccccccccccc/ddddddddddddd/eeeeeeeeeeeee/ffffffffffffffff/ggggggggggggg/hhhhhhhhhhhhh/iiiiiiiiiii");
291 unsigned int size = get_loadpath.size();
293 for (
unsigned int i = 0; i < size; i++) {
294 CPPUNIT_ASSERT(set_loadpath[i] == get_loadpath[i]);
301 vector<string> getlist, expectation;
302 expectation.push_back(
"/usr/lib");
303 expectation.push_back(
"/usr/local/lib");
304 expectation.push_back(
"/usr/local/lib/rtc");
307 for (
unsigned int i = 0; i < getlist.size(); i++) {
308 CPPUNIT_ASSERT(getlist[i] == expectation[i]);
315 vector<string> getlist, expectation, add_path;
316 expectation.push_back(
"/usr/lib");
317 expectation.push_back(
"/usr/local/lib");
318 expectation.push_back(
"/usr/local/lib/rtc");
319 expectation.push_back(
"/tmp");
320 expectation.push_back(
"/hoge");
321 expectation.push_back(
"/hoge/hoge");
323 add_path.push_back(
"/tmp");
324 add_path.push_back(
"/hoge");
325 add_path.push_back(
"/hoge/hoge");
329 for (
unsigned int i = 0; i < getlist.size(); i++) {
330 CPPUNIT_ASSERT(getlist[i] == expectation[i]);
337 vector<string> get_modlist;
340 CPPUNIT_ASSERT(get_modlist[0] ==
"/usr/lib/libRTC.so");
341 CPPUNIT_ASSERT(get_modlist[1] ==
"/usr/lib/libm.so");
349 vector<string> get_modlist;
351 for (
unsigned int i = 0; i < get_modlist.size(); i++) {
352 cout << get_modlist[i] << endl;
365 libname = m_pModMgr->
load(
"libRTC.so");
366 m_pModMgr->
unload(libname);
368 libname = m_pModMgr->
load(
"/usr/lib/libm.so");
369 m_pModMgr->
unload(libname);
371 libname = m_pModMgr->
load(
"../lib/libm.so");
372 m_pModMgr->
unload(libname);
376 libname = m_pModMgr->
load(
"../lib/libRTC.so");
377 m_pModMgr->
unload(libname);
385 std::cout <<
"Error " << e.
reason << std::endl;
389 std::cout <<
"NotFound " << e.
name << std::endl;
393 std::cout <<
"other exception" << std::endl;
420 std::vector<std::string>
path;
421 path.push_back(
"/lib");
422 path.push_back(
"/usr/lib");
423 path.push_back(
"/usr/local/lib");
425 result = m_pModMgr->
findFile(
"libm.so", path);
426 CPPUNIT_ASSERT_MESSAGE(
"fileFile error: libm.so",
427 result ==
"/usr/lib/libm.so");
429 result = m_pModMgr->
findFile(
"libc.so", path);
430 CPPUNIT_ASSERT_MESSAGE(
"fileFile error: libc.so",
431 result ==
"/usr/lib/libc.so");
433 result = m_pModMgr->
findFile(
"libACE.so", path);
434 CPPUNIT_ASSERT_MESSAGE(
"fileFile error: libACE.so",
435 result ==
"/usr/lib/libACE.so");
437 result = m_pModMgr->
findFile(
"hosts", path);
438 CPPUNIT_ASSERT_MESSAGE(
"fileFile error: hosts",
441 result = m_pModMgr->
findFile(
"munyamunya", path);
442 CPPUNIT_ASSERT_MESSAGE(
"fileFile error: munyamunya",
459 CPPUNIT_ASSERT(m_pModMgr->
fileExist(
"../../../../../../../../usr/lib/libm.so"));
460 CPPUNIT_ASSERT(m_pModMgr->
fileExist(
"/usr/lib/libm.so"));
473 CPPUNIT_ASSERT_MESSAGE(
"getInitFuncName error: Manipulator",
474 result ==
"ManipulatorInit");
477 CPPUNIT_ASSERT_MESSAGE(
"getInitFuncName error: PHANToM",
478 result ==
"PHANToMInit");
491 int main(
int argc,
char* argv[])
493 CppUnit::TextUi::TestRunner runner;
495 runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
496 CppUnit::Outputter* outputter =
497 new CppUnit::TextOutputter(&runner.result(), std::cout);
498 runner.setOutputter(outputter);
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.
std::string getInitFuncName(const std::string &file_path)
Create initialization function symbol.
void test_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.
void setLoadpath(const std::vector< std::string > &load_path)
Set the module load path.
void disallowAbsolutePath()
Disallow absolute path when specify module path.
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_getLoadableModules()
void test_disallowAbsolutePath()
void test_allowModuleDownload()
void test_allowAbsolutePath()
bool fileExist(const std::string &filename)
Check whether the file exists.
CPPUNIT_TEST_SUITE_REGISTRATION(ModuleManagerTests)
prop
Organization::get_organization_property ();.
int main(int argc, char *argv[])
std::vector< std::string > getLoadPath()
Get the module load path.
RTC::ModuleManager * m_pModMgr
Class represents a set of properties.
void unloadAll()
Unload all modules.
void test_disallowModuleDownload()
void unload(const std::string &file_name)
Unload the module.
void test_getInitFuncName()
std::string findFile(const std::string &fname, const std::vector< std::string > &load_path)
Search the file from the LoadPath.