diff options
author | Ng Pheng Siong <ngps@netmemetic.com> | 2000-11-08 14:41:57 +0000 |
---|---|---|
committer | Ng Pheng Siong <ngps@netmemetic.com> | 2000-11-08 14:41:57 +0000 |
commit | ab8947a41d54265e844e320df79a1ecc6095ac16 (patch) | |
tree | 8f526385f9403c5f8c400438620bcdcd6f97e80d /tests/test_bio_membuf.py | |
parent | 97c706ae70e56750852fe6e083c16b2c6f579912 (diff) | |
download | m2crypto-ab8947a41d54265e844e320df79a1ecc6095ac16.tar.gz |
Initial revision
git-svn-id: http://svn.osafoundation.org/m2crypto/trunk@77 2715db39-9adf-0310-9c64-84f055769b4b
Diffstat (limited to 'tests/test_bio_membuf.py')
-rw-r--r-- | tests/test_bio_membuf.py | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/tests/test_bio_membuf.py b/tests/test_bio_membuf.py new file mode 100644 index 0000000..9ae5fe7 --- /dev/null +++ b/tests/test_bio_membuf.py @@ -0,0 +1,66 @@ +#!/usr/bin/env python2.0 + +"""Unit tests for M2Crypto.BIO.MemoryBuffer. + +Copyright (c) 2000 Ng Pheng Siong. All rights reserved.""" + +RCS_id='$Id: test_bio_membuf.py,v 1.1 2000/11/08 14:41:57 ngps Exp $' + +import unittest +import M2Crypto +from M2Crypto.BIO import MemoryBuffer + +class MemoryBufferTestCase(unittest.TestCase): + + def setUp(self): + self.data = 'abcdef' * 64 + + def tearDown(self): + pass + + def check_init_empty(self): + mb = MemoryBuffer() + assert len(mb) == 0 + out = mb.read() + assert out is None + + def check_init_something(self): + mb = MemoryBuffer(self.data) + assert len(mb) == len(self.data) + out = mb.read() + assert out == self.data + + def check_read_less_than(self): + chunk = len(self.data) - 7 + mb = MemoryBuffer(self.data) + out = mb.read(chunk) + assert out == self.data[:chunk] and len(mb) == (len(self.data) - chunk) + + def check_read_more_than(self): + chunk = len(self.data) + 8 + mb = MemoryBuffer(self.data) + out = mb.read(chunk) + assert out == self.data and len(mb) == 0 + + def check_write_close(self): + mb = MemoryBuffer(self.data) + assert mb.writeable() + mb.write_close() + assert mb.readable() + self.assertRaises(IOError, mb.write, self.data) + assert not mb.writeable() + + def check_closed(self): + mb = MemoryBuffer(self.data) + mb.close() + self.assertRaises(IOError, mb.write, self.data) + assert not mb.readable() and not mb.writeable() + + +def suite(): + return unittest.makeSuite(MemoryBufferTestCase, 'check_') + + +if __name__ == '__main__': + unittest.TextTestRunner().run(suite()) + |