From 472e4caf5d3f32707e0d45cf7bc78bba6dc1b6ea Mon Sep 17 00:00:00 2001 From: Kei Okada Date: Tue, 4 Mar 2014 13:58:21 +0900 Subject: [PATCH] add test code to catch if pkg-config openhrp3.1 does not work well, also fixed install process PROJECT_SOURCE_DIR -> CMAKE_INSTALL_PREFIX/share/openhrp3 --- catkin.cmake | 4 ++- test/test_openhrp3.py | 64 +++++++++++++++++++++++++++++++++++++++++ test/test_openhrp3.test | 3 ++ 3 files changed, 70 insertions(+), 1 deletion(-) create mode 100755 test/test_openhrp3.py create mode 100644 test/test_openhrp3.test diff --git a/catkin.cmake b/catkin.cmake index 3391d9ac..8d3c9417 100644 --- a/catkin.cmake +++ b/catkin.cmake @@ -126,7 +126,8 @@ install(CODE install(CODE "execute_process(COMMAND echo \"fix \$ENV{DESTDIR}/${CMAKE_INSTALL_PREFIX}/${CATKIN_PACKAGE_LIB_DESTINATION}/pkgconfig/openhrp3.pc ${CATKIN_DEVEL_PREFIX} -> ${CMAKE_INSTALL_PREFIX}\") - execute_process(COMMAND sed -i s@${PROJECT_SOURCE_DIR}@${CMAKE_INSTALL_PREFIX}@g \$ENV{DESTDIR}/${CMAKE_INSTALL_PREFIX}/${CATKIN_PACKAGE_LIB_DESTINATION}/pkgconfig/openhrp3.1.pc) # basic + execute_process(COMMAND sed -i s@${CATKIN_DEVEL_PREFIX}@${CMAKE_INSTALL_PREFIX}@g \$ENV{DESTDIR}/${CMAKE_INSTALL_PREFIX}/${CATKIN_PACKAGE_LIB_DESTINATION}/pkgconfig/openhrp3.1.pc) # + execute_process(COMMAND sed -i s@${PROJECT_SOURCE_DIR}@${CMAKE_INSTALL_PREFIX}/share/openhrp3@g \$ENV{DESTDIR}/${CMAKE_INSTALL_PREFIX}/${CATKIN_PACKAGE_LIB_DESTINATION}/pkgconfig/openhrp3.1.pc) # basic execute_process(COMMAND sed -i s@{prefix}/bin@{prefix}/lib/openhrp3@g \$ENV{DESTDIR}/${CMAKE_INSTALL_PREFIX}/${CATKIN_PACKAGE_LIB_DESTINATION}/pkgconfig/openhrp3.1.pc) # basic execute_process(COMMAND sed -i s@{prefix}/share@{prefix}/share/openhrp3/share@g \$ENV{DESTDIR}/${CMAKE_INSTALL_PREFIX}/${CATKIN_PACKAGE_LIB_DESTINATION}/pkgconfig/openhrp3.1.pc) # basic ") @@ -134,4 +135,5 @@ install(CODE ## ## ## +add_rostest(test/test_openhrp3.test) add_rostest(test/test_modelloader.test) diff --git a/test/test_openhrp3.py b/test/test_openhrp3.py new file mode 100755 index 00000000..248b6eec --- /dev/null +++ b/test/test_openhrp3.py @@ -0,0 +1,64 @@ +#!/usr/bin/env python + +PKG = 'openhrp3' +import roslib; roslib.load_manifest(PKG) # This line is not needed with Catkin. + +import os +import sys +import unittest + +code = """ +#include + +int main (int argc, char** argv) +{ + hrp::BodyPtr body(new hrp::Body()); + return 0; +} +""" +from subprocess import call, check_output, Popen, PIPE, STDOUT + +## A sample python unit test +class TestCompile(unittest.TestCase): + ## test 1 == 1 + def test_compile_pkg_config(self): + global PID + cmd = "pkg-config openhrp3.1 --cflags --libs" + print "`"+cmd+"` =",check_output(cmd, shell=True, stderr=STDOUT) + ret = call("gcc -o openhrp3-sample-pkg-config /tmp/%d-openhrp3-sample.cpp `%s`"%(PID,cmd), shell=True) + self.assertTrue(ret==0) + + def _test_compile_move_ankle(self): + cmd1 = "pkg-config openhrp3.1 --cflags --libs" + cmd2 = "pkg-config openhrp3.1 --variable=idl_dir" + print "`"+cmd1+"` =",check_output(cmd1, shell=True, stderr=STDOUT) + print "`"+cmd2+"` =",check_output(cmd2, shell=True, stderr=STDOUT) + ret = call("gcc -o move_ankle `%s`/../sample/example/move_ankle/move_ankle.cpp `%s`"%(cmd2,cmd1), shell=True) + self.assertTrue(ret==0) + + def test_idl_dir(self): + cmd = "pkg-config openhrp3.1 --variable=idl_dir" + fname = "OpenHRP/OpenHRPCommon.idl" + # check if dil file exists + print "`"+cmd+"`"+fname+" = "+os.path.join(check_output(cmd, shell=True).rstrip(), fname) + self.assertTrue(os.path.exists(os.path.join(check_output(cmd, shell=True).rstrip(), fname))) + + def test_sample_pa10(self): + cmd = "pkg-config openhrp3.1 --variable=idl_dir" + fname = "../sample/model/PA10/pa10.main.wrl" + # check if dil file exists + print "`"+cmd+"`"+fname+" = "+os.path.join(check_output(cmd, shell=True).rstrip(), fname) + self.assertTrue(os.path.exists(os.path.join(check_output(cmd, shell=True).rstrip(), fname))) + +#unittest.main() +if __name__ == '__main__': + import rostest + global PID + PID = os.getpid() + f = open("/tmp/%d-openhrp3-sample.cpp"%(PID),'w') + f.write(code) + f.close() + rostest.rosrun(PKG, 'test_openhrp3', TestCompile) + + + diff --git a/test/test_openhrp3.test b/test/test_openhrp3.test new file mode 100644 index 00000000..e763528b --- /dev/null +++ b/test/test_openhrp3.test @@ -0,0 +1,3 @@ + + +