michael@0: #!/usr/bin/env python michael@0: # -*- coding: utf-8 -*- michael@0: michael@0: # This Source Code Form is subject to the terms of the Mozilla Public michael@0: # License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: # You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: michael@0: import mozdevice michael@0: import mozlog michael@0: import unittest michael@0: from sut import MockAgent michael@0: michael@0: class CopyTreeTest(unittest.TestCase): michael@0: def test_copyFile(self): michael@0: commands = [('dd if=/mnt/sdcard/tests/test.txt of=/mnt/sdcard/tests/test2.txt', ''), michael@0: ('isdir /mnt/sdcard/tests', 'TRUE'), michael@0: ('cd /mnt/sdcard/tests', ''), michael@0: ('ls', 'test.txt\ntest2.txt')] michael@0: michael@0: m = MockAgent(self, commands=commands) michael@0: d = mozdevice.DroidSUT("127.0.0.1", port=m.port, logLevel=mozlog.DEBUG) michael@0: michael@0: self.assertEqual(None, d.copyTree('/mnt/sdcard/tests/test.txt', michael@0: '/mnt/sdcard/tests/test2.txt')) michael@0: expected = (commands[3][1].strip()).split('\n') michael@0: self.assertEqual(expected, d.listFiles('/mnt/sdcard/tests')) michael@0: michael@0: def test_copyDir(self): michael@0: commands = [('dd if=/mnt/sdcard/tests/foo of=/mnt/sdcard/tests/bar', ''), michael@0: ('isdir /mnt/sdcard/tests', 'TRUE'), michael@0: ('cd /mnt/sdcard/tests', ''), michael@0: ('ls', 'foo\nbar')] michael@0: michael@0: m = MockAgent(self, commands=commands) michael@0: d = mozdevice.DroidSUT("127.0.0.1", port=m.port, michael@0: logLevel=mozlog.DEBUG) michael@0: michael@0: self.assertEqual(None, d.copyTree('/mnt/sdcard/tests/foo', michael@0: '/mnt/sdcard/tests/bar')) michael@0: expected = (commands[3][1].strip()).split('\n') michael@0: self.assertEqual(expected, d.listFiles('/mnt/sdcard/tests')) michael@0: michael@0: def test_copyNonEmptyDir(self): michael@0: commands = [('isdir /mnt/sdcard/tests/foo/bar', 'TRUE'), michael@0: ('dd if=/mnt/sdcard/tests/foo of=/mnt/sdcard/tests/foo2', ''), michael@0: ('isdir /mnt/sdcard/tests', 'TRUE'), michael@0: ('cd /mnt/sdcard/tests', ''), michael@0: ('ls', 'foo\nfoo2'), michael@0: ('isdir /mnt/sdcard/tests/foo2', 'TRUE'), michael@0: ('cd /mnt/sdcard/tests/foo2', ''), michael@0: ('ls', 'bar')] michael@0: michael@0: m = MockAgent(self, commands=commands) michael@0: d = mozdevice.DroidSUT("127.0.0.1", port=m.port, michael@0: logLevel=mozlog.DEBUG) michael@0: michael@0: self.assertTrue(d.dirExists('/mnt/sdcard/tests/foo/bar')) michael@0: self.assertEqual(None, d.copyTree('/mnt/sdcard/tests/foo', michael@0: '/mnt/sdcard/tests/foo2')) michael@0: expected = (commands[4][1].strip()).split('\n') michael@0: self.assertEqual(expected, d.listFiles('/mnt/sdcard/tests')) michael@0: self.assertTrue(d.fileExists('/mnt/sdcard/tests/foo2/bar')) michael@0: michael@0: if __name__ == "__main__": michael@0: unittest.main()