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 PKG = 'app_manager'
00034 import roslib; roslib.load_manifest(PKG)
00035
00036 import os
00037 import sys
00038 import unittest
00039
00040 import rosunit
00041
00042 class AppTest(unittest.TestCase):
00043
00044
00045 def test_Interface(self):
00046 from app_manager.app import Interface
00047 s1 = {'/chatter': 'std_msgs/String'}
00048 p1 = {'/chatter': 'std_msgs/String'}
00049 i1 = Interface(s1, p1)
00050 self.assertEquals(i1, i1)
00051 self.assertEquals(s1, i1.subscribed_topics)
00052 self.assertEquals(s1, i1.published_topics)
00053
00054 i2 = Interface({'/chatter': 'std_msgs/String'}, {'/chatter': 'std_msgs/String'})
00055 self.assertEquals(i1, i2)
00056 i3 = Interface({'/chatter2': 'std_msgs/String'}, {'/chatter': 'std_msgs/String'})
00057 self.assertNotEquals(i1, i3)
00058 i4 = Interface({'/chatter': 'std_msgs/String'}, {'/chatter2': 'std_msgs/String'})
00059 self.assertNotEquals(i1, i4)
00060
00061 def test_Client(self):
00062 from app_manager.app import Client
00063 c1 = Client(client_type="android",
00064 manager_data={"manager1": "dataA"},
00065 app_data={"app1": "dataB"})
00066 self.assertEquals("android", c1.client_type)
00067 self.assertEquals({"manager1": "dataA"}, c1.manager_data)
00068 self.assertEquals({"app1": "dataB"}, c1.app_data)
00069 self.assertEquals(c1, c1)
00070 c2 = Client(client_type="android",
00071 manager_data={"manager1": "dataA"},
00072 app_data={"app1": "dataB"})
00073 self.assertEquals(c1, c2)
00074 noteq = [
00075 Client("androidB", {"manager1": "dataA"},
00076 {"app1": "dataB"}),
00077 Client("android", {"manager2": "dataA"},
00078 {"app1": "dataB"}),
00079 Client("android", {"manager1": "dataA"},
00080 {"app2": "dataB"}),
00081 ]
00082 for c3 in noteq:
00083 self.assertNotEquals(c1, c3)
00084
00085 def test_AppDefinition(self):
00086
00087 from app_manager.app import AppDefinition, Client
00088 ad1 = AppDefinition('foo', 'Foo', 'Is Foo', 'android', 'foo.launch', 'foo.interface', [Client("android", {}, {})])
00089 self.assertEquals(ad1, ad1)
00090 ad2 = AppDefinition('foo', 'Foo', 'Is Foo', 'android', 'foo.launch', 'foo.interface', [Client("android", {}, {})])
00091 self.assertEquals(ad1, ad2)
00092 ad3 = AppDefinition('foo', 'Foo', 'Is Foo', 'android', 'foo.launch', 'foo.interface', [Client("android", {}, {})], None)
00093 self.assertEquals(ad1, ad3)
00094
00095 ad1b = AppDefinition('foo', 'Foo', 'Is Foo', 'android', 'foo.launch', 'foo.interface', [Client("android", {}, {})], 'app_manager/icon.png')
00096 self.assertEquals(ad1, ad1)
00097 ad2b = AppDefinition('foo', 'Foo', 'Is Foo', 'android', 'foo.launch', 'foo.interface', [Client("android", {}, {})], 'app_manager/icon.png')
00098 self.assertEquals(ad1b, ad2b)
00099 nad2b = AppDefinition('foo', 'Foo', 'Is Foo', 'android', 'foo.launch', 'foo.interface', [Client("android", {}, {})], 'app_manager/icon2.png')
00100 self.assertNotEquals(ad1, nad2b)
00101
00102 noteq = [
00103 AppDefinition('bar', 'Foo', 'Is Foo', 'android', 'foo.launch', 'foo.interface', [Client("android", {}, {})]),
00104 AppDefinition('foo', 'Bar', 'Is Foo', 'android', 'foo.launch', 'foo.interface', [Client("android", {}, {})]),
00105 AppDefinition('foo', 'Foo', 'Is Bar', 'android', 'foo.launch', 'foo.interface', [Client("android", {}, {})]),
00106 AppDefinition('foo', 'Foo', 'Is Foo', 'ios', 'foo.launch', 'foo.interface', [Client("android", {}, {})]),
00107 AppDefinition('foo', 'Foo', 'Is Foo', 'android', 'bar.launch', 'foo.interface', [Client("android", {}, {})]),
00108 AppDefinition('foo', 'Foo', 'Is Foo', 'android', 'foo.launch', 'bar.interface', [Client("android", {}, {})]),
00109 AppDefinition('foo', 'Foo', 'Is Foo', 'android', 'foo.launch', 'foo.interface', [Client("ios", {}, {})]),
00110 ]
00111 for nad in noteq:
00112 self.assertNotEquals(ad1, nad)
00113
00114 def test_find_resource(self):
00115 from app_manager.app import find_resource
00116 path = roslib.packages.get_pkg_dir(PKG)
00117 test_dir = os.path.join(path, 'test')
00118
00119 e = os.path.join(test_dir, 'empty.interface')
00120 self.assertEquals(e, find_resource('%s/empty.interface'%(PKG)))
00121
00122 e = os.path.join(test_dir, 'applist1', 'apps1.installed')
00123 self.assertEquals(e, find_resource('%s/apps1.installed'%(PKG)))
00124
00125 try:
00126 find_resource('empty.interface')
00127 self.fail("should have thrown ValueError: no package name")
00128 except ValueError:
00129 pass
00130 try:
00131 find_resource('app_manager')
00132 self.fail("should have thrown ValueError: no resource name")
00133 except ValueError:
00134 pass
00135
00136 def test_load_AppDefinition_by_name(self):
00137 rl_dir = roslib.packages.get_pkg_dir('roslaunch')
00138 from app_manager import NotFoundException, InternalAppException
00139 from app_manager.app import load_AppDefinition_by_name, Interface
00140 try:
00141 load_AppDefinition_by_name(None)
00142 self.fail("should fail")
00143 except ValueError: pass
00144 try:
00145 load_AppDefinition_by_name("fake_pkg/appA")
00146 self.fail("should fail")
00147 except NotFoundException: pass
00148
00149 ad = load_AppDefinition_by_name('app_manager/appA')
00150 self.assertEquals("app_manager/appA", ad.name)
00151 self.assertEquals("Android Joystick", ad.display_name)
00152 self.assertEquals("Control the TurtleBot with an Android device", ad.description)
00153 self.assertEquals("turtlebot", ad.platform)
00154 self.assertEquals(os.path.join(rl_dir, 'example-min.launch'), ad.launch)
00155 self.assert_(isinstance(ad.interface, Interface))
00156 self.assertEquals({}, ad.interface.subscribed_topics)
00157 self.assertEquals({}, ad.interface.published_topics)
00158 self.assertEquals([], ad.clients)
00159
00160
00161 import errno
00162 def fake_load_enoent(*args):
00163 raise IOError(errno.ENOENT, "fnf")
00164 def fake_load_gen(*args):
00165 raise IOError()
00166 import app_manager.app
00167 load_actual = app_manager.app.load_AppDefinition_from_file
00168 try:
00169 app_manager.app.load_AppDefinition_from_file = fake_load_enoent
00170 try:
00171 load_AppDefinition_by_name('app_manager/appA')
00172 self.fail("should have raised")
00173 except NotFoundException: pass
00174
00175 app_manager.app.load_AppDefinition_from_file = fake_load_gen
00176 try:
00177 load_AppDefinition_by_name('app_manager/appA')
00178 self.fail("should have raised")
00179 except InternalAppException: pass
00180 finally:
00181 app_manager.app.load_AppDefinition_from_file = load_actual
00182
00183 def test_load_AppDefinition_from_file(self):
00184 rl_dir = roslib.packages.get_pkg_dir('roslaunch')
00185 path = roslib.packages.get_pkg_dir(PKG)
00186 test_dir = os.path.join(path, 'test')
00187
00188 from app_manager.app import load_AppDefinition_from_file, Interface
00189 ad = load_AppDefinition_from_file(os.path.join(test_dir, 'appA.app'), 'foo/AppA')
00190 self.assertEquals("foo/AppA", ad.name)
00191 self.assertEquals("Android Joystick", ad.display_name)
00192 self.assertEquals("Control the TurtleBot with an Android device", ad.description)
00193 self.assertEquals("turtlebot", ad.platform)
00194 self.assertEquals(os.path.join(rl_dir, 'example-min.launch'), ad.launch)
00195 self.assert_(isinstance(ad.interface, Interface))
00196 self.assertEquals({}, ad.interface.subscribed_topics)
00197 self.assertEquals({}, ad.interface.published_topics)
00198 self.assertEquals([], ad.clients)
00199
00200
00201 def test_load_Interface_from_file(self):
00202 from app_manager.app import load_Interface_from_file
00203 path = roslib.packages.get_pkg_dir(PKG)
00204 test_dir = os.path.join(path, 'test')
00205
00206 empty = load_Interface_from_file(os.path.join(test_dir, 'empty.interface'))
00207 self.assertEquals({}, empty.subscribed_topics)
00208 self.assertEquals({}, empty.published_topics)
00209
00210 test1 = load_Interface_from_file(os.path.join(test_dir, 'test1.interface'))
00211 self.assertEquals({'/camera/rgb/image_color/compressed': 'sensor_msgs/CompressedImage'}, test1.published_topics)
00212 self.assertEquals({'/turtlebot_node/cmd_vel': 'geometry_msgs/Twist'}, test1.subscribed_topics)
00213
00214
00215 if __name__ == '__main__':
00216 rosunit.unitrun(PKG, 'test_app', AppTest, coverage_packages=['app_manager.app'])
00217