blob: 9ebb78eb7c251cf1835799dc61ebd0f03e626734 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
#!/usr/bin/env python
"""Unit tests for M2Crypto.BIO.MemoryBuffer.
Copyright (c) 2000 Ng Pheng Siong. All rights reserved."""
RCS_id='$Id$'
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 mb.readable() and not mb.writeable()
def suite():
return unittest.makeSuite(MemoryBufferTestCase, 'check_')
if __name__ == '__main__':
unittest.TextTestRunner().run(suite())
|