$search
00001 #!/usr/bin/env python 00002 # Software License Agreement (BSD License) 00003 # 00004 # Copyright (c) 2009, Willow Garage, Inc. 00005 # All rights reserved. 00006 # 00007 # Redistribution and use in source and binary forms, with or without 00008 # modification, are permitted provided that the following conditions 00009 # are met: 00010 # 00011 # * Redistributions of source code must retain the above copyright 00012 # notice, this list of conditions and the following disclaimer. 00013 # * Redistributions in binary form must reproduce the above 00014 # copyright notice, this list of conditions and the following 00015 # disclaimer in the documentation and/or other materials provided 00016 # with the distribution. 00017 # * Neither the name of Willow Garage, Inc. nor the names of its 00018 # contributors may be used to endorse or promote products derived 00019 # from this software without specific prior written permission. 00020 # 00021 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00022 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00023 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00024 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00025 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00026 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00027 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00028 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00029 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00030 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 00031 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00032 # POSSIBILITY OF SUCH DAMAGE. 00033 import roslib; roslib.load_manifest('test_rosgraph') 00034 00035 import os 00036 import sys 00037 import unittest 00038 00039 import rosgraph.masterapi 00040 import rostest 00041 00042 _ID = '/caller_id' 00043 00044 class MasterApiOnlineTest(unittest.TestCase): 00045 00046 def setUp(self): 00047 self.m = rosgraph.masterapi.Master(_ID) 00048 00049 def test_getPid(self): 00050 val = self.m.getPid() 00051 val = int(val) 00052 00053 def test_getUri(self): 00054 val = self.m.getUri() 00055 self.assert_(val.startswith('http://')) 00056 00057 def test_lookupService(self): 00058 uri = 'http://localhost:897' 00059 rpcuri = 'rosrpc://localhost:9812' 00060 self.m.registerService('/bar/service', rpcuri, uri) 00061 self.assertEquals(rpcuri, self.m.lookupService('/bar/service')) 00062 try: 00063 self.assertEquals(uri, self.m.lookupService('/fake/service')) 00064 self.fail("should have thrown") 00065 except rosgraph.masterapi.Error: 00066 pass 00067 00068 def test_registerService(self): 00069 self.m.registerService('/bar/service', 'rosrpc://localhost:9812', 'http://localhost:893') 00070 00071 def test_unregisterService(self): 00072 self.m.registerService('/unreg_service/service', 'rosrpc://localhost:9812', 'http://localhost:893') 00073 val = self.m.registerService('/unreg_service/service', 'rosrpc://localhost:9812', 'http://localhost:893') 00074 self.assertEquals(1, val) 00075 00076 def test_registerSubscriber(self): 00077 val = self.m.registerSubscriber('/reg_sub/node', 'std_msgs/String', 'http://localhost:9812') 00078 self.assertEquals([], val) 00079 00080 def test_unregisterSubscriber(self): 00081 self.m.registerSubscriber('/reg_unsub/node', 'std_msgs/String', 'http://localhost:9812') 00082 val = self.m.unregisterSubscriber('/reg_unsub/node', 'http://localhost:9812') 00083 self.assertEquals(1, val) 00084 00085 def test_registerPublisher(self): 00086 val = self.m.registerPublisher('/reg_pub/topic', 'std_msgs/String', 'http://localhost:9812') 00087 00088 def test_unregisterPublisher(self): 00089 uri = 'http://localhost:9812' 00090 self.m.registerPublisher('/unreg_pub/fake_topic', 'std_msgs/String', uri) 00091 self.m.unregisterPublisher('/unreg_pub/fake_topic', uri) 00092 00093 def test_lookupNode(self): 00094 # register and lookup self 00095 uri = 'http://localhost:12345' 00096 self.m.registerPublisher('fake_topic', 'std_msgs/String', uri) 00097 self.assertEquals(uri, self.m.lookupNode(_ID)) 00098 00099 try: 00100 self.m.lookupNode('/non/existent') 00101 self.fail("should have thrown") 00102 except rosgraph.masterapi.Error: 00103 pass 00104 00105 def test_getPublishedTopics(self): 00106 topics = self.m.getPublishedTopics('/') 00107 00108 def test_getTopicTypes(self): 00109 topic_types = self.m.getTopicTypes() 00110 00111 def test_getSystemState(self): 00112 pub, sub, srvs = self.m.getSystemState() 00113 00114 def test_is_online(self): 00115 self.assert_(rosgraph.masterapi.is_online()) 00116 self.assert_(self.m.is_online()) 00117 00118 def test_getParam(self): 00119 try: 00120 self.m.getParam('fake_param') 00121 self.fail("should have failed to lookup fake parameter") 00122 except rosgraph.masterapi.Error: 00123 pass 00124 00125 def test_hasParam(self): 00126 self.failIf(self.m.hasParam('fake_param'), "should have failed to lookup fake parameter") 00127 self.assert_(self.m.hasParam('/run_id'), "should have failed to lookup fake parameter") 00128 00129 def test_setParam(self): 00130 self.m.setParam('/foo', 1) 00131 00132 def test_searchParam(self): 00133 self.assertEquals("/run_id", self.m.searchParam('run_id')) 00134 00135 def test_getParamNames(self): 00136 self.assert_(type(self.m.getParamNames()) == list) 00137 00138 00139 if __name__ == '__main__': 00140 rostest.rosrun('test_rosgrap', 'test_rosgraph_masterapi_online', MasterApiOnlineTest) 00141