michael@0: from sut import MockAgent michael@0: import mozdevice michael@0: import mozlog michael@0: import unittest michael@0: import hashlib michael@0: import tempfile michael@0: import os michael@0: michael@0: class PullTest(unittest.TestCase): michael@0: michael@0: def test_pull_success(self): michael@0: for count in [ 1, 4, 1024, 2048 ]: michael@0: cheeseburgers = "" michael@0: for i in range(count): michael@0: cheeseburgers += "cheeseburgers" michael@0: michael@0: # pull file is kind of gross, make sure we can still execute commands after it's done michael@0: remoteName = "/mnt/sdcard/cheeseburgers" michael@0: a = MockAgent(self, commands = [("pull %s" % remoteName, michael@0: "%s,%s\n%s" % (remoteName, michael@0: len(cheeseburgers), michael@0: cheeseburgers)), michael@0: ("isdir /mnt/sdcard", "TRUE")]) michael@0: michael@0: d = mozdevice.DroidSUT("127.0.0.1", port=a.port, michael@0: logLevel=mozlog.DEBUG) michael@0: pulledData = d.pullFile("/mnt/sdcard/cheeseburgers") michael@0: self.assertEqual(pulledData, cheeseburgers) michael@0: d.dirExists('/mnt/sdcard') michael@0: michael@0: def test_pull_failure(self): michael@0: michael@0: # this test simulates only receiving a few bytes of what we expect michael@0: # to be larger file michael@0: remoteName = "/mnt/sdcard/cheeseburgers" michael@0: a = MockAgent(self, commands = [("pull %s" % remoteName, michael@0: "%s,15\n%s" % (remoteName, michael@0: "cheeseburgh"))]) michael@0: d = mozdevice.DroidSUT("127.0.0.1", port=a.port, michael@0: logLevel=mozlog.DEBUG) michael@0: exceptionThrown = False michael@0: try: michael@0: d.pullFile("/mnt/sdcard/cheeseburgers") michael@0: except mozdevice.DMError: michael@0: exceptionThrown = True michael@0: self.assertTrue(exceptionThrown) michael@0: michael@0: if __name__ == '__main__': michael@0: unittest.main() michael@0: michael@0: