Go to the documentation of this file.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 import os
00035 import sys
00036 import unittest
00037
00038 import rosgraph.masterapi
00039 import rostest
00040
00041 _ID = '/caller_id'
00042
00043 class MasterApiOnlineTest(unittest.TestCase):
00044
00045 def setUp(self):
00046 self.m = rosgraph.masterapi.Master(_ID)
00047
00048 def test_getPid(self):
00049 val = self.m.getPid()
00050 val = int(val)
00051
00052 def test_getUri(self):
00053 val = self.m.getUri()
00054 self.assert_(val.startswith('http://'))
00055
00056 def test_lookupService(self):
00057 uri = 'http://localhost:897'
00058 rpcuri = 'rosrpc://localhost:9812'
00059 self.m.registerService('/bar/service', rpcuri, uri)
00060 self.assertEquals(rpcuri, self.m.lookupService('/bar/service'))
00061 try:
00062 self.assertEquals(uri, self.m.lookupService('/fake/service'))
00063 self.fail("should have thrown")
00064 except rosgraph.masterapi.Error:
00065 pass
00066
00067 def test_registerService(self):
00068 self.m.registerService('/bar/service', 'rosrpc://localhost:9812', 'http://localhost:893')
00069
00070 def test_unregisterService(self):
00071 self.m.registerService('/unreg_service/service', 'rosrpc://localhost:9812', 'http://localhost:893')
00072 val = self.m.registerService('/unreg_service/service', 'rosrpc://localhost:9812', 'http://localhost:893')
00073 self.assertEquals(1, val)
00074
00075 def test_registerSubscriber(self):
00076 val = self.m.registerSubscriber('/reg_sub/node', 'std_msgs/String', 'http://localhost:9812')
00077 self.assertEquals([], val)
00078
00079 def test_unregisterSubscriber(self):
00080 self.m.registerSubscriber('/reg_unsub/node', 'std_msgs/String', 'http://localhost:9812')
00081 val = self.m.unregisterSubscriber('/reg_unsub/node', 'http://localhost:9812')
00082 self.assertEquals(1, val)
00083
00084 def test_registerPublisher(self):
00085 val = self.m.registerPublisher('/reg_pub/topic', 'std_msgs/String', 'http://localhost:9812')
00086
00087 def test_unregisterPublisher(self):
00088 uri = 'http://localhost:9812'
00089 self.m.registerPublisher('/unreg_pub/fake_topic', 'std_msgs/String', uri)
00090 self.m.unregisterPublisher('/unreg_pub/fake_topic', uri)
00091
00092 def test_lookupNode(self):
00093
00094 uri = 'http://localhost:12345'
00095 self.m.registerPublisher('fake_topic', 'std_msgs/String', uri)
00096 self.assertEquals(uri, self.m.lookupNode(_ID))
00097
00098 try:
00099 self.m.lookupNode('/non/existent')
00100 self.fail("should have thrown")
00101 except rosgraph.masterapi.Error:
00102 pass
00103
00104 def test_getPublishedTopics(self):
00105 topics = self.m.getPublishedTopics('/')
00106
00107 def test_getTopicTypes(self):
00108 topic_types = self.m.getTopicTypes()
00109
00110 def test_getSystemState(self):
00111 pub, sub, srvs = self.m.getSystemState()
00112
00113 def test_is_online(self):
00114 self.assert_(rosgraph.masterapi.is_online())
00115 self.assert_(self.m.is_online())
00116
00117 def test_getParam(self):
00118 try:
00119 self.m.getParam('fake_param')
00120 self.fail("should have failed to lookup fake parameter")
00121 except rosgraph.masterapi.Error:
00122 pass
00123
00124 def test_hasParam(self):
00125 self.failIf(self.m.hasParam('fake_param'), "should have failed to lookup fake parameter")
00126 self.assert_(self.m.hasParam('/run_id'), "should have failed to lookup fake parameter")
00127
00128 def test_setParam(self):
00129 self.m.setParam('/foo', 1)
00130
00131 def test_searchParam(self):
00132 self.assertEquals("/run_id", self.m.searchParam('run_id'))
00133
00134 def test_getParamNames(self):
00135 self.assert_(type(self.m.getParamNames()) == list)
00136
00137 if __name__ == '__main__':
00138 rostest.rosrun('test_rosgrap', 'test_rosgraph_masterapi_online', MasterApiOnlineTest)