$search
00001 #!/usr/bin/env python 00002 # Software License Agreement (BSD License) 00003 # 00004 # Copyright (c) 2008, 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 # Revision $Id: test_embed_msg.py 1986 2008-08-26 23:57:56Z sfkwc $ 00035 00036 ## Integration test for empty services to test serializers 00037 ## and transport 00038 00039 PKG = 'test_ros' 00040 NAME = 'test_master' 00041 import roslib; roslib.load_manifest(PKG) 00042 00043 import sys 00044 import unittest 00045 00046 import rospy 00047 00048 from test_ros.master import MasterApiTestCase, set_node_name 00049 00050 # Due to the need to have a fresh master for each of these test cases, 00051 # we have to go through the pain of exposing each of the test cases one-by-one 00052 00053 class MasterSimpleApi(MasterApiTestCase): 00054 def testGetPid(self): 00055 self._testGetPid() 00056 def testGetUri(self): 00057 self._testGetUri() 00058 00059 class MasterRegisterServiceSuccess(MasterApiTestCase): 00060 def testRegisterServiceSuccess(self): 00061 self._testRegisterServiceSuccess() 00062 00063 class MasterRegisterPublisherSuccess(MasterApiTestCase): 00064 def testRegisterPublisherSuccess(self): 00065 self._testRegisterPublisherSuccess() 00066 class MasterRegisterPublisherTypes(MasterApiTestCase): 00067 ## #591: this test may change if we make registering '*' unsupported 00068 def testRegisterPublisherTypes(self): 00069 self._testRegisterPublisherTypes() 00070 00071 class MasterRegisterSubscriberSimpleSuccess(MasterApiTestCase): 00072 def testRegisterSubscriberSimpleSuccess(self): 00073 self._testRegisterSubscriberSimpleSuccess() 00074 00075 00076 class MasterUnregisterServiceSuccess(MasterApiTestCase): 00077 def testUnregisterServiceSuccess(self): 00078 self._testUnregisterServiceSuccess() 00079 00080 class MasterUnregisterPublisherSuccess(MasterApiTestCase): 00081 def testUnregisterPublisherSuccess(self): 00082 self._testUnregisterPublisherSuccess() 00083 00084 class MasterUnregisterSubscriberSuccess(MasterApiTestCase): 00085 def testUnregisterSubscriberSuccess(self): 00086 self._testUnregisterSubscriberSuccess() 00087 00088 class MasterRegisterServiceInvalid(MasterApiTestCase): 00089 def testRegisterServiceInvalid(self): 00090 self._testRegisterServiceInvalid() 00091 00092 class MasterRegisterPublisherInvalid(MasterApiTestCase): 00093 def testRegisterPublisherInvalid(self): 00094 self._testRegisterPublisherInvalid() 00095 00096 class MasterRegisterSubscriberInvalid(MasterApiTestCase): 00097 def testRegisterSubscriberInvalid(self): 00098 self._testRegisterSubscriberInvalid() 00099 00100 00101 class MasterUnregisterServiceInvalid(MasterApiTestCase): 00102 def testUnregisterServiceInvalid(self): 00103 self._testUnregisterServiceInvalid() 00104 00105 class MasterUnregisterPublisherInvalid(MasterApiTestCase): 00106 def testUnregisterPublisherInvalid(self): 00107 self._testUnregisterPublisherInvalid() 00108 00109 class MasterUnregisterSubscriberInvalid(MasterApiTestCase): 00110 def testUnregisterSubscriberInvalid(self): 00111 self._testUnregisterSubscriberInvalid() 00112 00113 00114 00115 if __name__ == '__main__': 00116 # this is terribly complicated on the account that we want a fresh master for each test, so we cannot 00117 # run all the tests as a single test node. instead, we have to have a separate test node per test. 00118 00119 import optparse 00120 from optparse import OptionParser 00121 parser = OptionParser(usage="usage: %prog [options] topic", prog=NAME) 00122 00123 # have to redeclare --text/--cov options, which are standard rostest options 00124 parser.add_option("--text",dest="text_ignore", default=False, 00125 action="store_true", help="rostest standard option") 00126 parser.add_option("--cov",dest="cov_ignore", default=False, 00127 action="store_true", help="rostest standard option") 00128 00129 parser.add_option("--simple",dest="simple", default=False, 00130 action="store_true", help="MasterSimpleApi") 00131 00132 parser.add_option("--gtest_output",dest="gtest_output", default='', 00133 help="xml output file") 00134 00135 parser.add_option("--regsrvsuccess", dest="regsrvsuccess", default=False, 00136 action="store_true", help="MasterRegisterServiceSuccess") 00137 parser.add_option("--regpubsuccess", dest="regpubsuccess", default=False, 00138 action="store_true", help="MasterRegisterPublisherSuccess") 00139 parser.add_option("--regpubtypes", dest="regpubtypes", default=False, 00140 action="store_true", help="MasterRegisterPublisherTypes") 00141 parser.add_option("--regsubsimplesuccess", dest="regsubsimplesuccess", default=False, 00142 action="store_true", help="MasterRegisterSubscriberSimpleSuccess") 00143 00144 00145 parser.add_option("--unregsrvsuccess", dest="unregsrvsuccess", default=False, 00146 action="store_true", help="MasterUnregisterServiceSuccess") 00147 parser.add_option("--unregpubsuccess", dest="unregpubsuccess", default=False, 00148 action="store_true", help="MasterUnregisterPublisherSuccess") 00149 parser.add_option("--unregsubsuccess", dest="unregsubsuccess", default=False, 00150 action="store_true", help="MasterUnregisterSubscriberSuccess") 00151 00152 parser.add_option("--regsrvinvalid", dest="regsrvinvalid", default=False, 00153 action="store_true", help="MasterRegisterServiceInvalid") 00154 parser.add_option("--regsubinvalid", dest="regsubinvalid", default=False, 00155 action="store_true", help="MasterRegisterSubscriberInvalid") 00156 parser.add_option("--regpubinvalid", dest="regpubinvalid", default=False, 00157 action="store_true", help="MasterRegisterPublisherInvalid") 00158 00159 parser.add_option("--unregsrvinvalid", dest="unregsrvinvalid", default=False, 00160 action="store_true", help="MasterUnregisterServiceInvalid") 00161 parser.add_option("--unregsubinvalid", dest="unregsubinvalid", default=False, 00162 action="store_true", help="MasterUnregisterSubscriberInvalid") 00163 parser.add_option("--unregpubinvalid", dest="unregpubinvalid", default=False, 00164 action="store_true", help="MasterUnregisterPublisherInvalid") 00165 00166 00167 (options, args) = parser.parse_args() 00168 if options.simple: 00169 cls = MasterSimpleApi 00170 00171 elif options.regsrvsuccess: 00172 cls = MasterRegisterServiceSuccess 00173 elif options.regpubsuccess: 00174 cls = MasterRegisterPublisherSuccess 00175 elif options.regpubtypes: 00176 cls = MasterRegisterPublisherTypes 00177 elif options.regsubsimplesuccess: 00178 cls = MasterRegisterSubscriberSimpleSuccess 00179 00180 elif options.unregsrvsuccess: 00181 cls = MasterUnregisterServiceSuccess 00182 elif options.unregpubsuccess: 00183 cls = MasterUnregisterPublisherSuccess 00184 elif options.unregsubsuccess: 00185 cls = MasterUnregisterSubscriberSuccess 00186 00187 elif options.regsrvinvalid: 00188 cls = MasterRegisterServiceInvalid 00189 elif options.regpubinvalid: 00190 cls = MasterRegisterPublisherInvalid 00191 elif options.regsubinvalid: 00192 cls = MasterRegisterSubscriberInvalid 00193 00194 elif options.unregsrvinvalid: 00195 cls = MasterUnregisterServiceInvalid 00196 elif options.unregpubinvalid: 00197 cls = MasterUnregisterPublisherInvalid 00198 elif options.unregsubinvalid: 00199 cls = MasterUnregisterSubscriberInvalid 00200 00201 if not cls: 00202 parser.error("you must specify a test to run with an [options] flag") 00203 00204 set_node_name(NAME) 00205 rospy.init_node(NAME, disable_rostime=True) 00206 import rostest 00207 rostest.rosrun(PKG, NAME, cls, sys.argv)