60 lines
2.2 KiB
Python
Executable file
60 lines
2.2 KiB
Python
Executable file
#!/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
|
|
|
|
|
|
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
|
|
self.assertTrue(func('/dev/ram0').devnum == (1, 0))
|
|
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).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"))
|
|
self.assertFalse(func("ram0", "ram1"))
|
|
self.assertFalse(func_raw(self.blockdevice)(None))
|
|
self.assertRaises(CBInternalError, func_raw(self.blockdevice), "")
|
|
|