Skip to content

Commit

Permalink
Merge pull request #23 from k-okada/master
Browse files Browse the repository at this point in the history
add test code to catch if pkg-config openhrp3.1 does not work well, also...
  • Loading branch information
k-okada committed Mar 4, 2014
2 parents 0631f7a + 472e4ca commit 6cb8b52
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 1 deletion.
4 changes: 3 additions & 1 deletion catkin.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,14 @@ 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
")

##
##
##
add_rostest(test/test_openhrp3.test)
add_rostest(test/test_modelloader.test)
64 changes: 64 additions & 0 deletions test/test_openhrp3.py
Original file line number Diff line number Diff line change
@@ -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 <hrpModel/Body.h>
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)



3 changes: 3 additions & 0 deletions test/test_openhrp3.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<launch>
<test test-name="test_openhrp3" pkg="openhrp3" type="test_openhrp3.py" />
</launch>

0 comments on commit 6cb8b52

Please sign in to comment.