def testSetStorage(self):
     '''
     .. todo:: should this be in storage tests? (TBD)
     '''
     uut = MtpObject(self.default_data, self.get_default_info())
     storage = self.get_default_storage()
     uut.set_storage(storage)
     self.assertEqual(uut.storage, storage)
Exemple #2
0
 def testSetStorage(self):
     '''
     .. todo:: should this be in storage tests? (TBD)
     '''
     uut = MtpObject(self.default_data, self.get_default_info())
     storage = self.get_default_storage()
     uut.set_storage(storage)
     self.assertEqual(uut.storage, storage)
 def testAddObjectSetsStorageInChild(self):
     parent = MtpObject(self.default_data, self.get_default_info())
     uut = MtpObject(self.default_data, self.get_default_info())
     storage = self.get_default_storage()
     parent.set_storage(storage)
     parent.add_object(uut)
     self.assertEqual(uut.storage, storage)
     self.assertEqual(parent.storage, storage)
 def testGetObjectSelfWithChilds(self):
     others = [
         MtpObject(self.default_data, self.get_default_info()),
         MtpObject(self.default_data, self.get_default_info()),
         MtpObject(self.default_data, self.get_default_info())
     ]
     uut = MtpObject(self.default_data, self.get_default_info())
     for obj in others:
         uut.add_object(obj)
     obj = uut.get_object(uut.get_uid())
     self.assertEqual(uut, obj)
 def testSetStorageIsRecursive(self):
     '''
     .. todo:: should this be in storage tests? (TBD)
     '''
     parent = MtpObject(self.default_data, self.get_default_info())
     storage = self.get_default_storage()
     uut = MtpObject(self.default_data, self.get_default_info())
     parent.add_object(uut)
     parent.set_storage(storage)
     self.assertEqual(uut.storage, storage)
     self.assertEqual(parent.storage, storage)
 def testGetObjectChildren(self):
     others = [
         MtpObject(self.default_data, self.get_default_info()),
         MtpObject(self.default_data, self.get_default_info()),
         MtpObject(self.default_data, self.get_default_info())
     ]
     uut = MtpObject(self.default_data, self.get_default_info())
     for obj in others:
         uut.add_object(obj)
     obj = uut.get_object(others[0].get_uid())
     self.assertEqual(obj, others[0])
 def testGetObjectMultipleLevels(self):
     others = [
         MtpObject(self.default_data, self.get_default_info()),
         MtpObject(self.default_data, self.get_default_info()),
         MtpObject(self.default_data, self.get_default_info())
     ]
     uut = MtpObject(self.default_data, self.get_default_info())
     cur = uut
     for obj in others:
         cur.add_object(obj)
         cur = obj
     obj = uut.get_object(others[-1].get_uid())
     self.assertEqual(obj, others[-1])
 def testGetObjectsWithMultipleChildes(self):
     others = [
         MtpObject(self.default_data, self.get_default_info()),
         MtpObject(self.default_data, self.get_default_info()),
         MtpObject(self.default_data, self.get_default_info())
     ]
     uut = MtpObject(self.default_data, self.get_default_info())
     for obj in others:
         uut.add_object(obj)
     objs = uut.get_objects()
     self.assertEqual(len(objs), len(set(objs)))
     self.assertEqual(len(objs), len(others))
     self.assertEqual(set(objs), set(others))
Exemple #9
0
 def testGetObjectSelfWithChilds(self):
     others = [
         MtpObject(self.default_data, self.get_default_info()),
         MtpObject(self.default_data, self.get_default_info()),
         MtpObject(self.default_data, self.get_default_info())
     ]
     uut = MtpObject(self.default_data, self.get_default_info())
     for obj in others:
         uut.add_object(obj)
     obj = uut.get_object(uut.get_uid())
     self.assertEqual(uut, obj)
 def testGetObjectsMultipleLevels(self):
     others = [
         MtpObject(self.default_data, self.get_default_info()),
         MtpObject(self.default_data, self.get_default_info()),
         MtpObject(self.default_data, self.get_default_info())
     ]
     uut = MtpObject(self.default_data, self.get_default_info())
     cur = uut
     for obj in others:
         cur.add_object(obj)
         cur = obj
     objs = uut.get_objects()
     self.assertEqual(len(objs), len(set(objs)))
     self.assertEqual(len(objs), len(others))
     self.assertEqual(set(objs), set(others))
Exemple #11
0
 def setUp(self):
     super(MtpDeviceTests, self).setUp()
     self.object = MtpObject.from_fs_recursive('.')
     self.storage_info = MtpStorageInfo(
         st_type=0,
         fs_type=0,
         access=0,
         max_cap=150000,
         free_bytes=0,
         free_objs=0,
         desc='MyStorage',
         vol_id='Python MTP Device Stack',
     )
     self.storage = MtpStorage(self.storage_info)
     self.storage.add_object(self.object)
     self.dev_info = MtpDeviceInfo(
         std_version=0x0102,
         mtp_vendor_ext_id=0x03040506,
         mtp_version=0x0708,
         mtp_extensions='Some Extension',
         functional_mode=0x0000,
         capture_formats=[],
         playback_formats=[],
         manufacturer='BinyaminSharet',
         model='Role',
         device_version='1.2.3',
         serial_number='0123456789abcdef',
     )
     self.dev = MtpDevice(self.dev_info)
     self.dev.add_storage(self.storage)
     self.tid = 1
Exemple #12
0
 def setUp(self):
     super(MtpApiTest, self).setUp()
     self.object = MtpObject.from_fs_recursive('.')
     self.storage_info = MtpStorageInfo(
         st_type=0,
         fs_type=0,
         access=0,
         max_cap=150000,
         free_bytes=0,
         free_objs=0,
         desc='MyStorage',
         vol_id='Python MTP Device Stack',
     )
     self.storage = MtpStorage(self.storage_info)
     self.storage.add_object(self.object)
     self.dev_info = MtpDeviceInfo(
         std_version=0x0102,
         mtp_vendor_ext_id=0x03040506,
         mtp_version=0x0708,
         mtp_extensions='Some Extension',
         functional_mode=0x0000,
         capture_formats=[],
         playback_formats=[],
         manufacturer='BinyaminSharet',
         model='Role',
         device_version='1.2.3',
         serial_number='0123456789abcdef',
     )
     properties = [
         MtpDeviceProperty(MtpDevicePropertyCode.BatteryLevel, 0, UInt8(50), UInt8(0))
     ]
     self.dev = MtpDevice(self.dev_info, properties)
     self.dev.add_storage(self.storage)
     self.api = MtpApi(self.dev)
Exemple #13
0
 def testGetObjectChildren(self):
     others = [
         MtpObject(self.default_data, self.get_default_info()),
         MtpObject(self.default_data, self.get_default_info()),
         MtpObject(self.default_data, self.get_default_info())
     ]
     uut = MtpObject(self.default_data, self.get_default_info())
     for obj in others:
         uut.add_object(obj)
     obj = uut.get_object(others[0].get_uid())
     self.assertEqual(obj, others[0])
Exemple #14
0
 def testAddObjectSetsStorageInChild(self):
     parent = MtpObject(self.default_data, self.get_default_info())
     uut = MtpObject(self.default_data, self.get_default_info())
     storage = self.get_default_storage()
     parent.set_storage(storage)
     parent.add_object(uut)
     self.assertEqual(uut.storage, storage)
     self.assertEqual(parent.storage, storage)
Exemple #15
0
 def testGetObjectsWithMultipleChildes(self):
     others = [
         MtpObject(self.default_data, self.get_default_info()),
         MtpObject(self.default_data, self.get_default_info()),
         MtpObject(self.default_data, self.get_default_info())
     ]
     uut = MtpObject(self.default_data, self.get_default_info())
     for obj in others:
         uut.add_object(obj)
     objs = uut.get_objects()
     self.assertEqual(len(objs), len(set(objs)))
     self.assertEqual(len(objs), len(others))
     self.assertEqual(set(objs), set(others))
Exemple #16
0
 def testSetStorageIsRecursive(self):
     '''
     .. todo:: should this be in storage tests? (TBD)
     '''
     parent = MtpObject(self.default_data, self.get_default_info())
     storage = self.get_default_storage()
     uut = MtpObject(self.default_data, self.get_default_info())
     parent.add_object(uut)
     parent.set_storage(storage)
     self.assertEqual(uut.storage, storage)
     self.assertEqual(parent.storage, storage)
Exemple #17
0
 def testGetObjectMultipleLevels(self):
     others = [
         MtpObject(self.default_data, self.get_default_info()),
         MtpObject(self.default_data, self.get_default_info()),
         MtpObject(self.default_data, self.get_default_info())
     ]
     uut = MtpObject(self.default_data, self.get_default_info())
     cur = uut
     for obj in others:
         cur.add_object(obj)
         cur = obj
     obj = uut.get_object(others[-1].get_uid())
     self.assertEqual(obj, others[-1])
Exemple #18
0
 def testGetObjectsMultipleLevels(self):
     others = [
         MtpObject(self.default_data, self.get_default_info()),
         MtpObject(self.default_data, self.get_default_info()),
         MtpObject(self.default_data, self.get_default_info())
     ]
     uut = MtpObject(self.default_data, self.get_default_info())
     cur = uut
     for obj in others:
         cur.add_object(obj)
         cur = obj
     objs = uut.get_objects()
     self.assertEqual(len(objs), len(set(objs)))
     self.assertEqual(len(objs), len(others))
     self.assertEqual(set(objs), set(others))
Exemple #19
0
 def testFormatMatchsNone(self):
     uut = MtpObject(self.default_data, self.get_default_info())
     self.assertTrue(uut.format_matches(None))
 def testGetObjectDoesntExist(self):
     uut = MtpObject(self.default_data, self.get_default_info())
     obj = uut.get_object(uut.get_uid() + 1)
     self.assertIsNone(obj)
 def testGetInfoReturnsPackedInfo(self):
     info = self.get_default_info()
     uut = MtpObject(self.default_data, info)
     self.assertEqual(uut.get_info(), info.pack())
Exemple #22
0
 def testGetObjectsEmpty(self):
     uut = MtpObject(self.default_data, self.get_default_info())
     self.assertEqual(uut.get_objects(), [])
Exemple #23
0
 def testObjectInfo(self):
     info = self.get_default_info()
     uut = MtpObject(self.default_data, info)
     self.assertEqual(uut.info, info)
Exemple #24
0
 def testGetPropertyExceptionIfNotExist(self):
     uut = MtpObject(self.default_data, self.get_default_info())
     with self.assertRaises(MtpProtocolException) as cm:
         uut.get_property(MtpObjectPropertyCode.StorageID - 1)
     self.assertEqual(cm.exception.response,
                      ResponseCodes.OBJECT_PROP_NOT_SUPPORTED)
Exemple #25
0
 def testGetObjectDoesntExist(self):
     uut = MtpObject(self.default_data, self.get_default_info())
     obj = uut.get_object(uut.get_uid() + 1)
     self.assertIsNone(obj)
 def testFormatMatchsWildcard(self):
     uut = MtpObject(self.default_data, self.get_default_info())
     self.assertTrue(uut.format_matches(0xffffffff))
 def testGetPropertyDefaults(self):
     uut = MtpObject(self.default_data, self.get_default_info())
     prop = uut.get_property(MtpObjectPropertyCode.ObjectFormat)
     self.assertIsNotNone(prop)
     self.assertEqual(prop.value.value, self.default_format)
Exemple #28
0
    def __init__(self, app, phy):
        if not mtpdeviceloaded:
            raise Exception('You cannot use USBMtp until you install pymtpdevice')
        # TODO: un-hardcode string index (last arg before 'verbose')
        super(USBMtpInterface, self).__init__(
            app=app,
            phy=phy,
            interface_number=0,
            interface_alternate=0,
            interface_class=USBClass.VendorSpecific,
            interface_subclass=0xff,
            interface_protocol=0,
            interface_string_index=0,
            endpoints=[
                USBEndpoint(
                    app=app,
                    phy=phy,
                    number=1,
                    direction=USBEndpoint.direction_out,
                    transfer_type=USBEndpoint.transfer_type_bulk,
                    sync_type=USBEndpoint.sync_type_none,
                    usage_type=USBEndpoint.usage_type_data,
                    max_packet_size=64,
                    interval=0,
                    handler=self.handle_ep1_data_available
                ),
                USBEndpoint(
                    app=app,
                    phy=phy,
                    number=2,
                    direction=USBEndpoint.direction_in,
                    transfer_type=USBEndpoint.transfer_type_bulk,
                    sync_type=USBEndpoint.sync_type_none,
                    usage_type=USBEndpoint.usage_type_data,
                    max_packet_size=64,
                    interval=0,
                    handler=None
                ),
                USBEndpoint(
                    app=app,
                    phy=phy,
                    number=3,
                    direction=USBEndpoint.direction_in,
                    transfer_type=USBEndpoint.transfer_type_interrupt,
                    sync_type=USBEndpoint.sync_type_none,
                    usage_type=USBEndpoint.usage_type_data,
                    max_packet_size=64,
                    interval=32,
                    handler=None
                ),
            ],
        )
        self.object = MtpObject.from_fs_recursive('mtp_fs')
        # self.object = MtpObject.from_fs_recursive('mtp_fs/eits.mp3')
        self.storage_info = MtpStorageInfo(
            st_type=1,
            fs_type=2,
            access=0,
            max_cap=150000,
            free_bytes=0,
            free_objs=0,
            desc='MyStorage',
            vol_id='Python MTP Device Stack',
        )
        self.storage = MtpStorage(self.storage_info)
        self.storage.add_object(self.object)
        self.dev_info = MtpDeviceInfo(
            std_version=0x0064,
            mtp_vendor_ext_id=0x00000006,
            mtp_version=0x0064,
            mtp_extensions='microsoft.com: 1.0;',
            functional_mode=0x0000,
            capture_formats=[],
            playback_formats=[],
            manufacturer='BinyaminSharet',
            model='Role',
            device_version='1.2',
            serial_number='3031323334353637',
        )
        properties = [
            MtpDeviceProperty(MtpDevicePropertyCode.MTP_DeviceFriendlyName, 0, MStr('UmapMtpDevice'), MStr('')),
            MtpDeviceProperty(MtpDevicePropertyCode.BatteryLevel, 0, UInt8(100), UInt8(0))
        ]
        self.dev = MtpDevice(self.dev_info, properties, self.logger)
        self.dev.add_storage(self.storage)
        self.dev.set_fuzzer(app.fuzzer)
        self.api = MtpApi(self.dev)

        # OS String descriptor
        # self.add_string_with_id(50, 'MTP'.encode('utf-16') + b'\x00\x00')
        self.add_string_with_id(0xee, 'MSFT100'.encode('utf-16') + b'\x00\x00')
 def testGetPropertyExceptionIfNotExist(self):
     uut = MtpObject(self.default_data, self.get_default_info())
     with self.assertRaises(MtpProtocolException) as cm:
         uut.get_property(MtpObjectPropertyCode.StorageID - 1)
     self.assertEqual(cm.exception.response, ResponseCodes.OBJECT_PROP_NOT_SUPPORTED)
Exemple #30
0
 def testFormatMatchsWildcard(self):
     uut = MtpObject(self.default_data, self.get_default_info())
     self.assertTrue(uut.format_matches(0xffffffff))
Exemple #31
0
 def testGetPropertyDefaults(self):
     uut = MtpObject(self.default_data, self.get_default_info())
     prop = uut.get_property(MtpObjectPropertyCode.ObjectFormat)
     self.assertIsNotNone(prop)
     self.assertEqual(prop.value.value, self.default_format)
 def testFormatMatchsNone(self):
     uut = MtpObject(self.default_data, self.get_default_info())
     self.assertTrue(uut.format_matches(None))
Exemple #33
0
 def testObjectData(self):
     uut = MtpObject(self.default_data, self.get_default_info())
     self.assertEqual(uut.data, self.default_data)
Exemple #34
0
 def testAddObjectSetsParent(self):
     parent = MtpObject(self.default_data, self.get_default_info())
     uut = MtpObject(self.default_data, self.get_default_info())
     parent.add_object(uut)
     self.assertEqual(uut.parent, parent)
Exemple #35
0
 def testGetInfoReturnsPackedInfo(self):
     info = self.get_default_info()
     uut = MtpObject(self.default_data, info)
     self.assertEqual(uut.get_info(), info.pack())
 def testAddObjectSetsParent(self):
     parent = MtpObject(self.default_data, self.get_default_info())
     uut = MtpObject(self.default_data, self.get_default_info())
     parent.add_object(uut)
     self.assertEqual(uut.parent, parent)
Exemple #37
0
    def __init__(self, app, phy):
        if not mtpdeviceloaded:
            raise Exception('You cannot use USBMtp until you install pymtpdevice')
        # TODO: un-hardcode string index (last arg before 'verbose')
        super(USBMtpInterface, self).__init__(
            app=app,
            phy=phy,
            interface_number=0,
            interface_alternate=0,
            interface_class=USBClass.VendorSpecific,
            interface_subclass=0xff,
            interface_protocol=0,
            interface_string_index=0,
            endpoints=[
                USBEndpoint(
                    app=app,
                    phy=phy,
                    number=1,
                    direction=USBEndpoint.direction_out,
                    transfer_type=USBEndpoint.transfer_type_bulk,
                    sync_type=USBEndpoint.sync_type_none,
                    usage_type=USBEndpoint.usage_type_data,
                    max_packet_size=64,
                    interval=0,
                    handler=self.handle_ep1_data_available
                ),
                USBEndpoint(
                    app=app,
                    phy=phy,
                    number=2,
                    direction=USBEndpoint.direction_in,
                    transfer_type=USBEndpoint.transfer_type_bulk,
                    sync_type=USBEndpoint.sync_type_none,
                    usage_type=USBEndpoint.usage_type_data,
                    max_packet_size=64,
                    interval=0,
                    handler=None
                ),
                USBEndpoint(
                    app=app,
                    phy=phy,
                    number=3,
                    direction=USBEndpoint.direction_in,
                    transfer_type=USBEndpoint.transfer_type_interrupt,
                    sync_type=USBEndpoint.sync_type_none,
                    usage_type=USBEndpoint.usage_type_data,
                    max_packet_size=64,
                    interval=32,
                    handler=None
                ),
            ],
        )
        self.object = MtpObject.from_fs_recursive('mtp_fs')
        # self.object = MtpObject.from_fs_recursive('mtp_fs/eits.mp3')
        self.storage_info = MtpStorageInfo(
            st_type=1,
            fs_type=2,
            access=0,
            max_cap=150000,
            free_bytes=0,
            free_objs=0,
            desc='MyStorage',
            vol_id='Python MTP Device Stack',
        )
        self.storage = MtpStorage(self.storage_info)
        self.storage.add_object(self.object)
        self.dev_info = MtpDeviceInfo(
            std_version=0x0064,
            mtp_vendor_ext_id=0x00000006,
            mtp_version=0x0064,
            mtp_extensions='microsoft.com: 1.0;',
            functional_mode=0x0000,
            capture_formats=[],
            playback_formats=[],
            manufacturer='UMAP2',
            model='Role',
            device_version='1.2',
            serial_number='3031323334353637',
        )
        properties = [
            MtpDeviceProperty(MtpDevicePropertyCode.MTP_DeviceFriendlyName, 0, MStr('UmapMtpDevice'), MStr('')),
            MtpDeviceProperty(MtpDevicePropertyCode.BatteryLevel, 0, UInt8(100), UInt8(0))
        ]
        self.dev = MtpDevice(self.dev_info, properties, self.logger)
        self.dev.add_storage(self.storage)
        self.dev.set_fuzzer(app.fuzzer)
        self.api = MtpApi(self.dev)

        # OS String descriptor
        # self.add_string_with_id(50, 'MTP'.encode('utf-16') + b'\x00\x00')
        self.add_string_with_id(0xee, 'MSFT100'.encode('utf-16') + b'\x00\x00')
 def testGetObjectsEmpty(self):
     uut = MtpObject(self.default_data, self.get_default_info())
     self.assertEqual(uut.get_objects(), [])
Exemple #39
0
 def testGetObjectSelfAlone(self):
     uut = MtpObject(self.default_data, self.get_default_info())
     obj = uut.get_object(uut.get_uid())
     self.assertEqual(uut, obj)
 def testGetObjectSelfAlone(self):
     uut = MtpObject(self.default_data, self.get_default_info())
     obj = uut.get_object(uut.get_uid())
     self.assertEqual(uut, obj)