You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

82 lines
3.3 KiB

#!/usr/bin/env python
#
# Copyright 2006 sense.lab e.V.
#
# This file is part of the CryptoBox.
#
# The CryptoBox is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# The CryptoBox is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with the CryptoBox; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
"""Unittests for cryptobox.core.tools
"""
__revision__ = "$Id$"
import cryptobox.core.blockdevice as blockdevice
from cryptobox.tests.base import CommonTestClass
from cryptobox.core.exceptions import CBInternalError
import os
# different commonly available block devices - used for testing major/minor
COMMON_DEV_INFOS = [
('/sys/block/hda/hda1', '/dev/hda1', '/dev/hda', (3,1)),
('/sys/block/sda/sda1', '/dev/sda1', '/dev/sda', (8,1)),
('/sys/block/ubda/ubda', '/dev/ubda1', '/dev/ubda', (98,1)),
('/sys/block/ubdb/ubdb1', '/dev/ubdb1', '/dev/ubdb', (98,17)),
]
class CoreBlockDevice(CommonTestClass):
"""All unittests for cryptoboxtools
"""
def test_find_major_minor_of_device(self):
"""check the find_major_minor_of_device function
"""
func = blockdevice.get_blockdevice
# check if any of the common block devices is available
blockdevice_found = False
for sys_dir, dev_node, parent, major_minor in COMMON_DEV_INFOS:
if os.path.isdir(sys_dir):
self.assertTrue(func(dev_node).devnum == major_minor)
blockdevice_found = True
# we assume, that we found at least one blockdevice
self.assertTrue(blockdevice_found)
self.assertTrue(func("/dev/nothere") is None)
def test_is_part_of_blockdevice(self):
"""check the is_part_of_blockdevice function
"""
get_device = lambda devname: blockdevice.get_blockdevice(devname)
func = lambda parent, child: get_device(parent) and get_device(parent).is_parent_of(get_device(child))
func_raw = lambda parent: get_device(parent).is_parent_of
self.assertTrue(func(self.blockdevice, self.device))
self.assertFalse(func(self.blockdevice, self.blockdevice))
self.assertFalse(func(self.device, self.blockdevice))
self.assertFalse(func(self.device, self.device))
self.assertFalse(func(self.blockdevice, "/dev/hde1"))
# check if any of the common block devices is available
blockdevice_found = False
for sys_dir, dev_node, parent, major_minor in COMMON_DEV_INFOS:
if os.path.isdir(sys_dir):
self.assertFalse(func(dev_node, parent))
self.assertTrue(func(parent, dev_node))
blockdevice_found = True
self.assertFalse(func("ram0", "ram1"))
self.assertFalse(func_raw(self.blockdevice)(None))
self.assertRaises(CBInternalError, func_raw(self.blockdevice), "")