This commit is contained in:
Ivan
2022-04-05 11:42:28 +03:00
commit 6dc0eb0fcf
5565 changed files with 1200500 additions and 0 deletions

View File

@@ -0,0 +1,4 @@
test_rosmaster/String s1
string data
test_rosmaster/String s2
string data

View File

@@ -0,0 +1 @@
int32 a

View File

@@ -0,0 +1 @@
test_rosmaster/Empty empty

View File

@@ -0,0 +1,3 @@
int32 areq
---
int32 aresp

View File

@@ -0,0 +1,3 @@
test_rosmaster/Empty empty
---
test_rosmaster/Empty empty

View File

@@ -0,0 +1,181 @@
#!/usr/bin/env python
# Software License Agreement (BSD License)
#
# Copyright (c) 2008, Willow Garage, Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials provided
# with the distribution.
# * Neither the name of Willow Garage, Inc. nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
import os
import sys
import unittest
try:
from cStringIO import StringIO
except ImportError:
from io import StringIO
import time
import rospkg
import rosmsg
from subprocess import Popen, PIPE, check_call, call
#TODO: currently have an extra copy of msg and srv files in local dir
# for historical/porting reasons. Ideally there would only be one copy
# in test_ros instead.
def get_test_path():
return os.path.abspath(os.path.dirname(__file__))
class TestRosmsg(unittest.TestCase):
def setUp(self):
pass
def test_fullusage(self):
from rosmsg import MODE_MSG
text = rosmsg.fullusage(MODE_MSG)
self.assert_("Commands" in text)
cmds = ['show', 'md5', 'package', 'packages']
for c in cmds:
self.assert_(c in text)
def test_get_msg_text(self):
d = get_test_path()
msg_d = os.path.join(d, 'msg')
test_message_package = 'test_rosmaster'
rospack = rospkg.RosPack()
msg_raw_d = os.path.join(rospack.get_path(test_message_package), 'msg')
for t in ['RosmsgA', 'RosmsgB']:
with open(os.path.join(msg_d, '%s.msg'%t), 'r') as f:
text = f.read()
with open(os.path.join(msg_raw_d, '%s.msg'%t), 'r') as f:
text_raw = f.read()
type_ = test_message_package+'/'+t
self.assertEquals(text, rosmsg.get_msg_text(type_, raw=False))
self.assertEquals(text_raw, rosmsg.get_msg_text(type_, raw=True))
# test recursive types
t = 'RosmsgC'
with open(os.path.join(d, '%s_raw.txt'%t), 'r') as f:
text = f.read()
with open(os.path.join(msg_raw_d, '%s.msg'%t), 'r') as f:
text_raw = f.read()
type_ = test_message_package+'/'+t
self.assertEquals(text, rosmsg.get_msg_text(type_, raw=False))
self.assertEquals(text_raw, rosmsg.get_msg_text(type_, raw=True))
def test_iterate_packages(self):
from rosmsg import iterate_packages, MODE_MSG, MODE_SRV
import rospkg
rospack = rospkg.RosPack()
found = {}
for p, path in iterate_packages(rospack, MODE_MSG):
found[p] = path
assert os.path.basename(path) == 'msg', path
# make sure it's a package
assert rospack.get_path(p)
assert found
for p, path in iterate_packages(rospack, MODE_SRV):
found[p] = path
assert os.path.basename(path) == 'srv', path
# make sure it's a package
assert rospack.get_path(p)
assert found
def test_list_types(self):
try:
l = rosmsg.list_types('rosmsg', '.foo')
self.fail("should have failed on invalid mode")
except ValueError: pass
# test msgs
l = rosmsg.list_types('rospy', mode='.msg')
self.assertEquals([], l)
l = rosmsg.list_types('test_rosmaster', mode='.msg')
for t in ['test_rosmaster/RosmsgA', 'test_rosmaster/RosmsgB', 'test_rosmaster/RosmsgC']:
assert t in l
l = rosmsg.list_types('rospy', mode='.srv')
self.assertEquals([], l)
l = rosmsg.list_types('test_rosmaster', mode='.srv')
for t in ['test_rosmaster/RossrvA', 'test_rosmaster/RossrvB']:
assert t in l
def test_get_srv_text(self):
d = get_test_path()
srv_d = os.path.join(d, 'srv')
test_srv_package = 'test_rosmaster'
rospack = rospkg.RosPack()
srv_raw_d = os.path.join(rospack.get_path(test_srv_package), 'srv')
for t in ['RossrvA', 'RossrvB']:
with open(os.path.join(srv_d, '%s.srv'%t), 'r') as f:
text = f.read()
with open(os.path.join(srv_raw_d, '%s.srv'%t), 'r') as f:
text_raw = f.read()
type_ = test_srv_package+'/'+t
self.assertEquals(text, rosmsg.get_srv_text(type_, raw=False))
self.assertEquals(text_raw, rosmsg.get_srv_text(type_, raw=True))
def test_rosmsg_cmd_packages(self):
from rosmsg import rosmsg_cmd_packages, MODE_MSG, MODE_SRV
with fakestdout() as b:
rosmsg_cmd_packages(MODE_MSG, 'foo', ['packages'])
val = b.getvalue().strip()
packages1 = val.split('\n')
assert 'std_msgs' in packages1
with fakestdout() as b:
rosmsg_cmd_packages(MODE_MSG, 'foo', ['packages', '-s'])
val = b.getvalue().strip()
packages2 = val.split(' ')
assert 'std_msgs' in packages2
assert set(packages1) == set(packages2), "%s vs. %s"%(packages1, packages2)
def test_rosmsg_cmd_list(self):
from rosmsg import rosmsg_cmd_list, MODE_MSG, MODE_SRV
with fakestdout() as b:
rosmsg_cmd_list(MODE_MSG, 'messages', ['list'])
val = b.getvalue().strip()
packages1 = val.split('\n')
assert 'std_msgs/String' in packages1
from contextlib import contextmanager
@contextmanager
def fakestdout():
realstdout = sys.stdout
fakestdout = StringIO()
sys.stdout = fakestdout
yield fakestdout
sys.stdout = realstdout

View File

@@ -0,0 +1,178 @@
#!/usr/bin/env python
# Software License Agreement (BSD License)
#
# Copyright (c) 2008, Willow Garage, Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials provided
# with the distribution.
# * Neither the name of Willow Garage, Inc. nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
import os
import sys
import unittest
import time
import rospkg
from subprocess import Popen, PIPE, check_call, call
_SCRIPT_FOLDER = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'scripts'))
class TestRosmsg(unittest.TestCase):
def setUp(self):
self.new_environ = os.environ
self.new_environ["PYTHONPATH"] = os.path.join(os.getcwd(), "src")+':'+os.environ['PYTHONPATH']
## test that the rosmsg command works
def test_cmd_help(self):
sub = ['show', 'md5', 'package', 'packages', 'list']
for cmd in ['rosmsg', 'rossrv']:
glob_cmd=[os.path.join(_SCRIPT_FOLDER, cmd)]
output = Popen(glob_cmd, stdout=PIPE, env=self.new_environ).communicate()[0]
self.assert_('Commands' in output)
output = Popen(glob_cmd+['-h'], stdout=PIPE, env=self.new_environ).communicate()[0]
self.assert_('Commands' in output)
self.assert_('Traceback' not in output)
for c in sub:
self.assert_("%s %s"%(cmd, c) in output, "%s %s"%(cmd, c) + " not in "+ output + " of " + str(glob_cmd))
for c in sub:
output = Popen(glob_cmd + [c, '-h'], stdout=PIPE, env=self.new_environ).communicate()[0]
self.assert_('Usage' in output)
self.assert_("%s %s"%(cmd, c) in output, output)
def test_cmd_packages(self):
# - single line
output1 = Popen(['rosmsg', 'packages', '-s'], stdout=PIPE).communicate()[0]
# - multi-line
output2 = Popen(['rosmsg', 'packages'], stdout=PIPE).communicate()[0]
l1 = [x for x in output1.split() if x]
l2 = [x.strip() for x in output2.split('\n') if x.strip()]
self.assertEquals(l1, l2)
for p in ['std_msgs', 'test_rosmaster']:
self.assert_(p in l1)
for p in ['std_srvs', 'rosmsg']:
self.assert_(p not in l1)
output1 = Popen(['rossrv', 'packages', '-s'], stdout=PIPE).communicate()[0]
output2 = Popen(['rossrv', 'packages'], stdout=PIPE).communicate()[0]
l1 = [x for x in output1.split() if x]
l2 = [x.strip() for x in output2.split('\n') if x.strip()]
self.assertEquals(l1, l2)
for p in ['std_srvs', 'test_rosmaster']:
self.assert_(p in l1)
for p in ['std_msgs', 'rospy']:
self.assert_(p not in l1)
def test_cmd_list(self):
# - multi-line
output1 = Popen([os.path.join(_SCRIPT_FOLDER,'rosmsg'), 'list'], stdout=PIPE).communicate()[0]
l1 = [x.strip() for x in output1.split('\n') if x.strip()]
for p in ['std_msgs/String', 'test_rosmaster/Floats']:
self.assert_(p in l1)
for p in ['std_srvs/Empty', 'roscpp/Empty']:
self.assert_(p not in l1)
output1 = Popen([os.path.join(_SCRIPT_FOLDER,'rossrv'), 'list'], stdout=PIPE).communicate()[0]
l1 = [x.strip() for x in output1.split('\n') if x.strip()]
for p in ['std_srvs/Empty', 'roscpp/Empty']:
self.assert_(p in l1)
for p in ['std_msgs/String', 'test_rosmaster/Floats']:
self.assert_(p not in l1)
def test_cmd_package(self):
# this test is obviously very brittle, but should stabilize as the tests stabilize
# - single line output
output1 = Popen(['rosmsg', 'package', '-s', 'test_rosmaster'], stdout=PIPE).communicate()[0]
# - multi-line output
output2 = Popen(['rosmsg', 'package', 'test_rosmaster'], stdout=PIPE).communicate()[0]
l = set([x for x in output1.split() if x])
l2 = set([x.strip() for x in output2.split('\n') if x.strip()])
self.assertEquals(l, l2)
for m in ['test_rosmaster/RosmsgA',
'test_rosmaster/RosmsgB',
'test_rosmaster/RosmsgC']:
self.assertTrue(m in l, l)
output = Popen(['rossrv', 'package', '-s', 'test_rosmaster'], stdout=PIPE).communicate()[0]
output2 = Popen(['rossrv', 'package','test_rosmaster'], stdout=PIPE).communicate()[0]
l = set([x for x in output.split() if x])
l2 = set([x.strip() for x in output2.split('\n') if x.strip()])
self.assertEquals(l, l2)
for m in ['test_rosmaster/RossrvA', 'test_rosmaster/RossrvB']:
self.assertTrue(m in l, l)
## test that the rosmsg/rossrv show command works
def test_cmd_show(self):
output = Popen(['rosmsg', 'show', 'std_msgs/String'], stdout=PIPE).communicate()[0]
self.assertEquals('string data', output.strip())
output = Popen(['rossrv', 'show', 'std_srvs/Empty'], stdout=PIPE).communicate()[0]
self.assertEquals('---', output.strip())
output = Popen(['rossrv', 'show', 'std_srvs/Empty'], stdout=PIPE).communicate()[0]
self.assertEquals('---', output.strip())
output = Popen(['rossrv', 'show', 'test_rosmaster/AddTwoInts'], stdout=PIPE).communicate()[0]
self.assertEquals('int64 a\nint64 b\n---\nint64 sum', output.strip())
# test against test_rosmsg package
d = os.path.abspath(os.path.dirname(__file__))
msg_d = os.path.join(d, 'msg')
test_message_package = 'test_rosmaster'
rospack = rospkg.RosPack()
msg_raw_d = os.path.join(rospack.get_path(test_message_package), 'msg')
# - test with non-recursive types
for t in ['RosmsgA', 'RosmsgB']:
with open(os.path.join(msg_d, '%s.msg'%t), 'r') as f:
text = f.read()
with open(os.path.join(msg_raw_d, '%s.msg'%t), 'r') as f:
text_raw = f.read()
text = text+'\n' # running command adds one new line
text_raw = text_raw+'\n'
type_ =test_message_package+'/'+t
output = Popen(['rosmsg', 'show', type_], stdout=PIPE).communicate()[0]
self.assertEquals(text, output)
output = Popen(['rosmsg', 'show', '-r',type_], stdout=PIPE).communicate()[0]
self.assertEquals(text_raw, output)
output = Popen(['rosmsg', 'show', '--raw', type_], stdout=PIPE).communicate()[0]
self.assertEquals(text_raw, output)
# test as search
type_ = t
text = "[test_rosmaster/%s]:\n%s"%(t, text)
text_raw = "[test_rosmaster/%s]:\n%s"%(t, text_raw)
output = Popen(['rosmsg', 'show', type_], stdout=PIPE).communicate()[0]
self.assertEquals(text, output)
output = Popen(['rosmsg', 'show', '-r',type_], stdout=PIPE, stderr=PIPE).communicate()
self.assertEquals(text_raw, output[0], "Failed: %s"%(str(output)))
output = Popen(['rosmsg', 'show', '--raw', type_], stdout=PIPE).communicate()[0]
self.assertEquals(text_raw, output)

View File

@@ -0,0 +1,133 @@
#!/usr/bin/env python
# Software License Agreement (BSD License)
#
# Copyright (c) 2011, Willow Garage, Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials provided
# with the distribution.
# * Neither the name of Willow Garage, Inc. nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
# Author: Thibault Kruse
from __future__ import with_statement
NAME = 'test_rosmsgproto'
import os
import sys
import unittest
import time
import std_msgs
import rostest
import rosmsg
from rosmsg import *
from nose.plugins.skip import SkipTest
_NO_DICT=True
if "OrderedDict" in collections.__dict__:
_NO_DICT=False
class RosMsgProtoTest(unittest.TestCase):
def test_get_array_type_instance(self):
self.assertEqual(0, get_array_type_instance("int16[]"))
self.assertEqual(0, get_array_type_instance("char[]"))
self.assertEqual(0, get_array_type_instance("uint16[]"))
self.assertEqual(0, get_array_type_instance("int32[]"))
self.assertEqual(0, get_array_type_instance("uint16[]"))
self.assertEqual(False,get_array_type_instance("bool[]"))
self.assertEqual(0, get_array_type_instance("float32[]"))
self.assertEqual(0, get_array_type_instance("float64[]"))
self.assertEqual("", get_array_type_instance("string[]"))
self.assertFalse(None == get_array_type_instance("time[]"))
self.assertFalse(None == get_array_type_instance("duration[]"))
self.assertTrue(None == get_array_type_instance("colorRGBA[]"))
self.assertTrue(None == get_array_type_instance("empty[]"))
# TODO check for complex types
def test_create_names_filter(self):
class foo:
def __init__(self):
self.__slots__= ["bar","foo","bar","baz","bar"]
self.assertEqual(["foo", "baz"], create_names_filter("bar")(foo()))
def test_rosmsg_cmd_prototype_std_msgs_Int16(self):
if _NO_DICT: raise SkipTest("Test skipped because Python version too low")
self.assertEqual('"data: 0"', rosmsg_cmd_prototype(["msg", "std_msgs/Int16"]))
self.assertEqual('data: 0', rosmsg_cmd_prototype(["msg", "std_msgs/Int16", "-H"]))
self.assertEqual('" data: 0"', rosmsg_cmd_prototype(["msg", "std_msgs/Int16", "-p", " "]))
self.assertEqual(' data: 0', rosmsg_cmd_prototype(["msg", "std_msgs/Int16", "-p", " ", "-H"]))
self.assertEqual('"{}"', rosmsg_cmd_prototype(["msg", "std_msgs/Int16","-x", "data"]))
def test_rosmsg_cmd_prototype_std_msgs_String(self):
if _NO_DICT: raise SkipTest("Test skipped because Python version too low")
self.assertEqual('"data: \'\'"', rosmsg_cmd_prototype(["msg", "std_msgs/String"]))
self.assertEqual('data: \'\'', rosmsg_cmd_prototype(["msg", "std_msgs/String", "-H"]))
self.assertEqual(' data: \'\'', rosmsg_cmd_prototype(["msg", "std_msgs/String", "-p", " ", "-H"]))
def test_rosmsg_cmd_prototype_std_msgs_Header(self):
if _NO_DICT: raise SkipTest("Test skipped because Python version too low")
self.assertEqual('"seq: 0\nstamp:\n secs: 0\n nsecs: 0\nframe_id: \'\'"', rosmsg_cmd_prototype(["msg", "std_msgs/Header"]))
self.assertEqual('"{seq: 0, stamp: {secs: 0, nsecs: 0}, frame_id: \'\'}"', rosmsg_cmd_prototype(["msg", "std_msgs/Header", "-f1"]))
def test_rosmsg_cmd_prototype_std_msgs_Bool(self):
if _NO_DICT: raise SkipTest("Test skipped because Python version too low")
self.assertEqual('"data: false"', rosmsg_cmd_prototype(["msg", "std_msgs/Bool"]))
def test_rosmsg_cmd_prototype_std_msgs_Time(self):
if _NO_DICT: raise SkipTest("Test skipped because Python version too low")
self.assertEqual('"data:\n secs: 0\n nsecs: 0"', rosmsg_cmd_prototype(["msg", "std_msgs/Time"]))
self.assertEqual('"{data: {secs: 0, nsecs: 0}}"', rosmsg_cmd_prototype(["msg", "std_msgs/Time", "-f1"]))
def test_rosmsg_cmd_prototype_std_msgs_Duration(self):
if _NO_DICT: raise SkipTest("Test skipped because Python version too low")
self.assertEqual('"data:\n secs: 0\n nsecs: 0"', rosmsg_cmd_prototype(["msg", "std_msgs/Duration"]))
self.assertEqual('"{data: {secs: 0, nsecs: 0}}"', rosmsg_cmd_prototype(["msg", "std_msgs/Duration", "-f1"]))
def test_rosmsg_cmd_prototype_std_msgs_ColorRGBA(self):
self.assertEqual('"r: 0.0\ng: 0.0\nb: 0.0\na: 0.0"', rosmsg_cmd_prototype(["msg", "std_msgs/ColorRGBA", "-f0"]))
def test_rosmsg_cmd_prototype_std_msgs_MultiArrayLayout(self):
self.assertEqual('"dim:\n- label: \'\'\n size: 0\n stride: 0\ndata_offset: 0"', rosmsg_cmd_prototype(["msg", "std_msgs/MultiArrayLayout"]))
self.assertEqual('"dim: []\ndata_offset: 0"', rosmsg_cmd_prototype(["msg", "std_msgs/MultiArrayLayout", "-e"]))
def test_rosmsg_cmd_prototype_std_msgs_Float64MultiArray(self):
self.assertEqual('"layout:\n dim:\n - label: \'\'\n size: 0\n stride: 0\n data_offset: 0\ndata:\n- 0"', rosmsg_cmd_prototype(["msg", "std_msgs/Float64MultiArray"]))
self.assertEqual('"layout:\n dim:\n - label: \'\'\n size: 0\n data_offset: 0"', rosmsg_cmd_prototype(["msg", "std_msgs/Float64MultiArray", "-x", "stride,data"]))
def test_rosmsg_cmd_prototype_std_msgs_MultiArrayDimension(self):
self.assertEqual('"label: \'\'\nsize: 0\nstride: 0"', rosmsg_cmd_prototype(["msg", "std_msgs/MultiArrayDimension"]))
def test_rosmsg_cmd_prototype_std_msgs_Float32MultiArray(self):
self.assertEqual('"layout:\n dim:\n - label: \'\'\n size: 0\n stride: 0\n data_offset: 0\ndata:\n- 0"', rosmsg_cmd_prototype(["msg", "std_msgs/Float32MultiArray"]))
self.assertEqual('"layout:\n dim:\n - label: \'\'\n size: 0\n stride: 0\n data_offset: 0\ndata:\n- 0"', rosmsg_cmd_prototype(["msg", "std_msgs/Float32MultiArray", "-f0"]))
self.assertEqual('"{layout: {dim: [{label: \'\', size: 0, stride: 0}], data_offset: 0}, data: [0]}"', rosmsg_cmd_prototype(["msg", "std_msgs/Float32MultiArray", "-f1"]))

View File

@@ -0,0 +1,103 @@
#!/usr/bin/env python
# Software License Agreement (BSD License)
#
# Copyright (c) 2011, Willow Garage, Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials provided
# with the distribution.
# * Neither the name of Willow Garage, Inc. nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
# Author: Thibault Kruse
from __future__ import with_statement
NAME = 'test_rosmsgproto'
import os
import sys
import unittest
import time
import copy
import rostest
import subprocess
from subprocess import Popen, PIPE, call
import collections
import rosmsg
from nose.plugins.skip import SkipTest
ROSMSGPROTO_FN = [os.path.join(os.getcwd(), '../scripts/rosmsg-proto')]
_NO_DICT = True
if "OrderedDict" in collections.__dict__:
_NO_DICT = False
class RosMsgProtoCommandlineTestMsg(unittest.TestCase):
def setUp(self):
# proto depends on python 2.7 having OrderedDict
if _NO_DICT: raise SkipTest("Test skipped because Python version too low")
self.new_environ = os.environ
self.new_environ["PYTHONPATH"] = os.path.join(os.getcwd(), "src")+':'+os.environ['PYTHONPATH']
def testFail(self):
cmd = copy.copy(ROSMSGPROTO_FN)
cmd.extend(["msg", "foo123barxyz"])
call = subprocess.Popen(cmd, stdout = subprocess.PIPE, stderr = subprocess.PIPE, env = self.new_environ)
(output, erroutput) = call.communicate()
self.assertEqual('', output)
self.assertTrue('Unknown message name foo123barxyz' in erroutput)
def testSilentFail(self):
cmd = copy.copy(ROSMSGPROTO_FN)
cmd.extend(["msg", "-s", "foo123barxyz"])
call = subprocess.Popen(cmd, stdout = subprocess.PIPE, stderr = subprocess.PIPE, env = self.new_environ)
(output, erroutput) = call.communicate()
self.assertEqual('', output)
self.assertEqual('', erroutput)
def testSilentFailCpp(self):
cmd = copy.copy(ROSMSGPROTO_FN)
cmd.extend(["msg", "-s", "foo123barxyz::bar"])
call = subprocess.Popen(cmd, stdout = subprocess.PIPE, stderr = subprocess.PIPE, env = self.new_environ)
(output, erroutput) = call.communicate()
self.assertEqual('', output)
self.assertEqual('', erroutput)
def testSilentFailDot(self):
cmd = copy.copy(ROSMSGPROTO_FN)
cmd.extend(["msg", "-s", "foo123barxyz.bar"])
call = subprocess.Popen(cmd, stdout = subprocess.PIPE, stderr = subprocess.PIPE, env = self.new_environ)
(output, erroutput) = call.communicate()
self.assertEqual('', output)
self.assertEqual('', erroutput)
def testSilentFailMode(self):
cmd = copy.copy(ROSMSGPROTO_FN)
cmd.extend(["msgfoobar", "-s", "foo123barxyz.bar"])
call = subprocess.Popen(cmd, stdout = subprocess.PIPE, stderr = subprocess.PIPE, env = self.new_environ)
(output, erroutput) = call.communicate()
self.assertEqual('', output)
self.assertEqual('', erroutput)