test_rosgraph_masterapi_online.py
Go to the documentation of this file.
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 
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         # register and lookup self
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)


test_rosgraph
Author(s): Ken Conley
autogenerated on Fri Aug 28 2015 12:33:38