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 import os
00034 import sys
00035 import time
00036 import unittest
00037 import traceback
00038
00039 import yaml
00040
00041 import roslib.message
00042 import genpy
00043 from genpy import Time, Duration
00044
00045
00046
00047 class MessageTest(unittest.TestCase):
00048
00049 def test_check_types_Header(self):
00050
00051
00052
00053 from test_roslib_comm.msg import HeaderTest
00054 x = HeaderTest()
00055 x._check_types()
00056
00057 def test_strify_message(self):
00058 from genpy.message import Message, strify_message, fill_message_args
00059 def roundtrip(m):
00060 yaml_text = strify_message(m)
00061 print yaml_text
00062 loaded = yaml.load(yaml_text)
00063 print "loaded", loaded
00064 new_inst = m.__class__()
00065 if loaded is not None:
00066 fill_message_args(new_inst, [loaded])
00067 else:
00068 fill_message_args(new_inst, [])
00069 return new_inst
00070
00071
00072
00073
00074 from test_roslib_comm.msg import ArrayOfMsgs
00075 from std_msgs.msg import String, Time, MultiArrayLayout, MultiArrayDimension
00076 dims1 = [MultiArrayDimension(*args) for args in [('', 0, 0), ('x', 1, 2), ('y of z', 3, 4)]]
00077 dims2 = [MultiArrayDimension('hello world', 91280, 1983274)]
00078 times = [Time(genpy.Time(*args)) for args in [(0,), (12345, 6789), (1, 1)]]
00079 val = ArrayOfMsgs([String(''), String('foo'), String('bar of soap')],
00080 times,
00081 [MultiArrayLayout(dims1, 0), MultiArrayLayout(dims2, 12354)],
00082 )
00083 self.assertEquals(val, roundtrip(val))
00084
00085
00086 def test_get_message_class(self):
00087 from roslib.message import get_message_class
00088
00089 try:
00090 self.assertEquals(None, get_message_class('String'))
00091 self.fail("should have thrown ValueError")
00092 except ValueError: pass
00093
00094 self.assertEquals(None, get_message_class('fake/Fake'))
00095
00096 self.assertEquals(None, get_message_class('roslib/Fake'))
00097
00098 self.assertEquals(None, get_message_class('genmsg_cpp/Fake'))
00099
00100 import rosgraph_msgs.msg
00101 import std_msgs.msg
00102 self.assertEquals(std_msgs.msg.Header, get_message_class('Header'))
00103 self.assertEquals(std_msgs.msg.Header, get_message_class('std_msgs/Header'))
00104 self.assertEquals(rosgraph_msgs.msg.Log, get_message_class('rosgraph_msgs/Log'))
00105
00106 def test_get_service_class(self):
00107 from roslib.message import get_service_class
00108
00109
00110 self.assertEquals(None, get_service_class('fake/Fake'))
00111
00112 self.assertEquals(None, get_service_class('roslib/Fake'))
00113
00114 self.assertEquals(None, get_service_class('genmsg_cpp/Fake'))
00115
00116 import std_srvs.srv
00117 self.assertEquals(std_srvs.srv.Empty, get_service_class('std_srvs/Empty'))
00118