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