00001
00002
00003 PKG = 'hrpsys'
00004 NAME = 'test-pkgconfig'
00005
00006 code = """
00007 #include <sys/types.h> /* iob.h need this */
00008 #include "io/iob.h"
00009 int main (int argc, char** argv)
00010 {
00011 open_iob();
00012 close_iob();
00013 return 0;
00014 }
00015 """
00016 import unittest, os, sys
00017 from subprocess import call, check_output, Popen, PIPE, STDOUT
00018
00019 class TestHrpsysPkgconfig(unittest.TestCase):
00020 PKG_CONFIG_PATH = ''
00021
00022 def setUp(self):
00023
00024 hrpsys_path = check_output(['rospack','find','hrpsys']).rstrip()
00025 openhrp3_path = check_output(['rospack','find','openhrp3']).rstrip()
00026 if os.path.exists(os.path.join(hrpsys_path, "bin")) :
00027 self.PKG_CONFIG_PATH='PKG_CONFIG_PATH=%s/lib/pkgconfig:%s/lib/pkgconfig:$PKG_CONFIG_PATH'%(hrpsys_path, openhrp3_path)
00028
00029 def pkg_config_variable(self, var):
00030 return check_output("%s pkg-config hrpsys-base --variable=%s"%(self.PKG_CONFIG_PATH, var), shell=True).rstrip()
00031
00032 def check_if_file_exists(self, var, fname):
00033 pkg_var = var
00034 pkg_dname = self.pkg_config_variable(pkg_var)
00035 pkg_path = os.path.join(pkg_dname, fname)
00036 pkg_ret = os.path.exists(pkg_path)
00037 self.assertTrue(pkg_ret, "pkg-config hrpsys --variable=%s`/%s (%s) returns %r"%(pkg_var, fname, pkg_path, pkg_ret))
00038
00039
00040 def check_if_file_exists_from_rospack(self, fname):
00041 pkg_dname = check_output(['rospack','find','hrpsys']).rstrip()
00042 pkg_path = os.path.join(pkg_dname, fname)
00043 pkg_ret = os.path.exists(pkg_path)
00044 self.assertTrue(pkg_ret, "`rospack find hrpsys`(%s) returns %r"%(pkg_path, pkg_ret))
00045
00046 def test_files_for_hrpsys(self):
00047
00048 self.check_if_file_exists_from_rospack("share/hrpsys/samples/PA10/")
00049 self.check_if_file_exists_from_rospack("share/hrpsys/samples/PA10/rtc.conf")
00050 self.check_if_file_exists_from_rospack("share/hrpsys/samples/PA10/RobotHardware.conf")
00051 self.check_if_file_exists_from_rospack("share/hrpsys/samples/PA10/PA10.conf")
00052
00053 def test_files_for_hrpsys_ros_bridge(self):
00054
00055 self.check_if_file_exists("idldir", "HRPDataTypes.idl")
00056
00057 def test_compile_iob(self):
00058 global PID
00059 cmd = "%s pkg-config hrpsys-base --cflags --libs"%(self.PKG_CONFIG_PATH)
00060 print "`"+cmd+"` =",check_output(cmd, shell=True, stderr=STDOUT)
00061 ret = call("gcc -o hrpsys-sample-pkg-config /tmp/%d-hrpsys-sample.cpp `%s` -lhrpIo"%(PID,cmd), shell=True)
00062 self.assertTrue(ret==0)
00063
00064 def test_idlfile(self):
00065 cmd = "%s pkg-config hrpsys-base --variable=idldir"%(self.PKG_CONFIG_PATH)
00066 print "`"+cmd+"`/RobotHardwareService.idl = ",os.path.join(check_output(cmd, shell=True, stderr=STDOUT).rstrip(), "RobotHardwareService.idl")
00067 self.assertTrue(os.path.exists(os.path.join(check_output(cmd, shell=True).rstrip(), "RobotHardwareService.idl")))
00068
00069
00070 if __name__ == '__main__':
00071 import rostest
00072 global PID
00073 PID = os.getpid()
00074 f = open("/tmp/%d-hrpsys-sample.cpp"%(PID),'w')
00075 f.write(code)
00076 f.close()
00077 rostest.run(PKG, NAME, TestHrpsysPkgconfig, sys.argv)