cryptonas/src/cryptobox/tests/test.cryptoboxtools.py
2006-11-30 14:50:28 +00:00

77 lines
2.5 KiB
Python
Executable file

#!/usr/bin/env python2.4
#
# 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
#
import unittest
import cryptobox.core.tools as cbxTools
import os
## use /dev/ubd? if possible - otherwise /dev/hd?
## so it will be possible to use these tests inside of an uml
for d in ["ubdb", "ubda", "udbc", "ubdd", "hdb", "hda", "hdc", "hdd"]:
if os.path.exists("/dev/%s1" % d):
device = d
break
else:
device = "hda"
class CryptoBoxToolsTests(unittest.TestCase):
def testGetAbsoluteDeviceName(self):
func = cbxTools.getAbsoluteDeviceName
self.assertTrue(func(device) == "/dev/%s" % device)
self.assertTrue(func("loop0") == "/dev/loop0")
self.assertTrue(func(os.path.devnull) == os.path.devnull)
def testFindMajorMinorOfDevice(self):
func = cbxTools.findMajorMinorOfDevice
self.assertTrue(func(os.path.devnull) == (1,3))
self.assertTrue(func("/dev/nothere") is None)
def testFindMajorMinorDeviceName(self):
func = cbxTools.findMajorMinorDeviceName
dir = os.path.join(os.path.sep, "dev")
self.assertTrue(os.path.devnull in func(dir,1,3))
self.assertFalse(os.path.devnull in func(dir,2,3))
self.assertFalse(None in func(dir,17,23))
def testIsPartOfBlockDevice(self):
func = cbxTools.isPartOfBlockDevice
self.assertTrue(func("/dev/%s" % device, "/dev/%s1" % device))
self.assertFalse(func("/dev/%s" % device, "/dev/%s" % device))
self.assertFalse(func("/dev/%s1" % device, "/dev/%s" % device))
self.assertFalse(func("/dev/%s1" % device, "/dev/%s1" % device))
self.assertFalse(func("/dev/%s" % device, "/dev/hde1"))
self.assertFalse(func(None, "/dev/%s1" % device))
self.assertFalse(func("/dev/%s" % device, None))
self.assertFalse(func(None, ""))
self.assertFalse(func("loop0", "loop1"))
if __name__ == "__main__":
unittest.main()