test_posix.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. # -*- coding: utf-8 -*-
  2. #
  3. # SelfTest/Util/test_posix.py: Self-test for the OSRNG.posix.new() function
  4. #
  5. # Written in 2008 by Dwayne C. Litzenberger <dlitz@dlitz.net>
  6. #
  7. # ===================================================================
  8. # The contents of this file are dedicated to the public domain. To
  9. # the extent that dedication to the public domain is not available,
  10. # everyone is granted a worldwide, perpetual, royalty-free,
  11. # non-exclusive license to exercise all rights associated with the
  12. # contents of this file for any purpose whatsoever.
  13. # No rights are reserved.
  14. #
  15. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  16. # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  17. # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  18. # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  19. # BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  20. # ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  21. # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  22. # SOFTWARE.
  23. # ===================================================================
  24. """Self-test suite for Crypto.Random.OSRNG.posix"""
  25. __revision__ = "$Id$"
  26. import unittest
  27. class SimpleTest(unittest.TestCase):
  28. def runTest(self):
  29. """Crypto.Random.OSRNG.posix.new()"""
  30. # Import the OSRNG.nt module and try to use it
  31. import Crypto.Random.OSRNG.posix
  32. randobj = Crypto.Random.OSRNG.posix.new()
  33. x = randobj.read(16)
  34. y = randobj.read(16)
  35. self.assertNotEqual(x, y)
  36. def get_tests(config={}):
  37. return [SimpleTest()]
  38. if __name__ == '__main__':
  39. suite = lambda: unittest.TestSuite(get_tests())
  40. unittest.main(defaultTest='suite')
  41. # vim:set ts=4 sw=4 sts=4 expandtab: