00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 PKG = 'test_roslaunch'
00037
00038 import roslib; roslib.load_manifest(PKG)
00039
00040 import os, sys, unittest
00041
00042 import rostest
00043 import roslib.packages
00044 from roslib.params import get_param
00045
00046
00047 class TestParamsBasic(unittest.TestCase):
00048
00049 def test_values(self):
00050
00051 self.assertEquals(get_param('stringempty'), '')
00052 print get_param('stringbar')
00053 self.assertEquals(get_param('stringbar'), 'bar')
00054 self.assertEquals(get_param('str10'), '10')
00055 self.assertEquals(get_param('string10'), '10')
00056 self.assertEquals(get_param('stringentity'), '<stringentity/>')
00057
00058 self.assertEquals(get_param("integerneg1"), -1)
00059 self.assertEquals(get_param("integer0"), 0)
00060 self.assertEquals(get_param("integer1"), 1)
00061 self.assertEquals(get_param("integernoop1"), 1)
00062 self.assertEquals(get_param("integer12345"), 12345)
00063
00064 self.assertEquals(get_param("floatpi"),3.14159)
00065 self.assertEquals(get_param("floatnooppi"),3.14159)
00066 self.assertEquals(get_param("float3"),3.0)
00067 self.assertEquals(get_param("floatneg1"),-1.0)
00068
00069 for p in ['true', 'TRUE', 'True']:
00070 self.assertTrue(get_param(p), "[%s] is not false: %s"%(p, get_param(p)))
00071 for p in ['false', "FALSE", 'False']:
00072 self.assertFalse(get_param(p), "[%s] is not false: %s"%(p, get_param(p)))
00073
00074
00075 def test_ns(self):
00076 self.assertEquals(get_param("/wg/childparam"),"wg")
00077 self.assertEquals(get_param("/wg2/childparam"),"wg2")
00078 self.assertEquals(get_param("/wg3/childparam"),"wg3")
00079 self.assertEquals(get_param("/wg/wg4/childparam"),"wg4")
00080 self.assertEquals(get_param("/wg/wg4/wg5/childparam"),"wg5")
00081
00082 self.assertEquals(get_param("/wga/wg/childparam"),"wg")
00083 self.assertEquals(get_param("/wga/wg2/childparam"),"wg2")
00084 self.assertEquals(get_param("/wga/wg3/childparam"),"wg3")
00085 self.assertEquals(get_param("/wga/wg/wg4/childparam"),"wg4")
00086 self.assertEquals(get_param("/wga/wg/wg4/wg5/childparam"),"wg5")
00087
00088 self.assertEquals(get_param("/wga/wgb/wg/childparam"),"bwg")
00089 self.assertEquals(get_param("/wga/wgb/wg2/childparam"),"bwg2")
00090 self.assertEquals(get_param("/wga/wgb/wg3/childparam"),"bwg3")
00091 self.assertEquals(get_param("/wga/wgb/wg/wg4/childparam"),"bwg4")
00092 self.assertEquals(get_param("/wga/wgb/wg/wg4/wg5/childparam"),"bwg5")
00093
00094 self.assertEquals(get_param("/wgc/childparam"),"wg")
00095 self.assertEquals(get_param("/wgc2/childparam"),"wg2")
00096 self.assertEquals(get_param("/wgc3/childparam"),"wg3")
00097 self.assertEquals(get_param("/wgc/wg4/childparam"),"wg4")
00098 self.assertEquals(get_param("/wgc/wg4/wg5/childparam"),"wg5")
00099
00100
00101 def test_commandandfile(self):
00102 dir = roslib.packages.get_pkg_dir('roslaunch')
00103 f = open(os.path.join(dir, 'example.launch'), 'r')
00104 data = f.read()
00105 f.close()
00106 test_file = data
00107 self.assertEquals(get_param("commandoutput"),test_file)
00108 self.assertEquals(get_param("textfile"),test_file)
00109
00110 import xmlrpclib
00111 bindata = get_param("binaryfile")
00112 self.assertTrue(isinstance(bindata, xmlrpclib.Binary))
00113 self.assertEquals(bindata.data,test_file)
00114
00115 if __name__ == '__main__':
00116 rostest.rosrun(PKG, sys.argv[0], TestParamsBasic, sys.argv)
00117