michael@0: from sut import MockAgent michael@0: import mozdevice michael@0: import mozlog michael@0: import unittest michael@0: michael@0: class BasicTest(unittest.TestCase): michael@0: michael@0: def test_init(self): michael@0: """Tests DeviceManager initialization.""" michael@0: a = MockAgent(self) michael@0: michael@0: d = mozdevice.DroidSUT("127.0.0.1", port=a.port, logLevel=mozlog.DEBUG) michael@0: # all testing done in device's constructor michael@0: a.wait() michael@0: michael@0: def test_init_err(self): michael@0: """Tests error handling during initialization.""" michael@0: cmds = [("testroot", "/mnt/sdcard"), michael@0: ("isdir /mnt/sdcard/tests", "/mnt/sdcard/tests: No such file or directory\n"), michael@0: ("isdir /mnt/sdcard/tests", "/mnt/sdcard/tests: No such file or directory\n"), michael@0: ("mkdr /mnt/sdcard/tests", "/mnt/sdcard/tests successfully created"), michael@0: ("ver", "SUTAgentAndroid Version 1.14")] michael@0: a = MockAgent(self, start_commands = cmds) michael@0: dm = mozdevice.DroidSUT("127.0.0.1", port=a.port, logLevel=mozlog.DEBUG) michael@0: a.wait() michael@0: michael@0: def test_timeout_normal(self): michael@0: """Tests DeviceManager timeout, normal case.""" michael@0: a = MockAgent(self, commands = [("isdir /mnt/sdcard/tests", "TRUE"), michael@0: ("cd /mnt/sdcard/tests", ""), michael@0: ("ls", "test.txt"), michael@0: ("rm /mnt/sdcard/tests/test.txt", michael@0: "Removed the file")]) michael@0: d = mozdevice.DroidSUT("127.0.0.1", port=a.port, logLevel=mozlog.DEBUG) michael@0: ret = d.removeFile('/mnt/sdcard/tests/test.txt') michael@0: self.assertEqual(ret, None) # if we didn't throw an exception, we're ok michael@0: a.wait() michael@0: michael@0: def test_timeout_timeout(self): michael@0: """Tests DeviceManager timeout, timeout case.""" michael@0: a = MockAgent(self, commands = [("isdir /mnt/sdcard/tests", "TRUE"), michael@0: ("cd /mnt/sdcard/tests", ""), michael@0: ("ls", "test.txt"), michael@0: ("rm /mnt/sdcard/tests/test.txt", 0)]) michael@0: d = mozdevice.DroidSUT("127.0.0.1", port=a.port, logLevel=mozlog.DEBUG) michael@0: d.default_timeout = 1 michael@0: exceptionThrown = False michael@0: try: michael@0: d.removeFile('/mnt/sdcard/tests/test.txt') michael@0: except mozdevice.DMError: michael@0: exceptionThrown = True michael@0: self.assertEqual(exceptionThrown, True) michael@0: a.should_stop = True michael@0: a.wait() michael@0: michael@0: def test_shell(self): michael@0: """Tests shell command""" michael@0: for cmd in [ ("exec foobar", False), ("execsu foobar", True) ]: michael@0: for retcode in [ 1, 2 ]: michael@0: a = MockAgent(self, commands=[(cmd[0], michael@0: "\nreturn code [%s]" % retcode)]) michael@0: d = mozdevice.DroidSUT("127.0.0.1", port=a.port) michael@0: exceptionThrown = False michael@0: try: michael@0: d.shellCheckOutput(["foobar"], root=cmd[1]) michael@0: except mozdevice.DMError: michael@0: exceptionThrown = True michael@0: expectedException = (retcode != 0) michael@0: self.assertEqual(exceptionThrown, expectedException) michael@0: michael@0: a.wait() michael@0: michael@0: if __name__ == '__main__': michael@0: unittest.main()