summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorSybren A. St?vel <sybren@stuvel.eu>2011-07-30 21:39:10 +0200
committerSybren A. St?vel <sybren@stuvel.eu>2011-07-30 21:39:10 +0200
commit76e1aa7ec0e054b8eb58a769babaf3de4451d500 (patch)
treee03f57347dcabed0717e61f4d0e705af54a3fb7e /tests
parent439994e62dd9450c71d1173a34cfc0550a771133 (diff)
downloadrsa-76e1aa7ec0e054b8eb58a769babaf3de4451d500.tar.gz
Added start of blocks module (varint impl)
Diffstat (limited to 'tests')
-rw-r--r--tests/test_blocks.py58
1 files changed, 58 insertions, 0 deletions
diff --git a/tests/test_blocks.py b/tests/test_blocks.py
new file mode 100644
index 0000000..be7b640
--- /dev/null
+++ b/tests/test_blocks.py
@@ -0,0 +1,58 @@
+'''Tests block operations.'''
+
+from StringIO import StringIO
+import unittest
+
+from rsa import blocks
+
+class VarintTest(unittest.TestCase):
+
+ def test_read_varint(self):
+
+ encoded = '\xac\x02crummy'
+ infile = StringIO(encoded)
+
+ (decoded, read) = blocks.read_varint(infile)
+
+ # Test the returned values
+ self.assertEqual(300, decoded)
+ self.assertEqual(2, read)
+
+ # The rest of the file should be untouched
+ self.assertEqual('crummy', infile.read())
+
+ def test_read_zero(self):
+
+ encoded = '\x00crummy'
+ infile = StringIO(encoded)
+
+ (decoded, read) = blocks.read_varint(infile)
+
+ # Test the returned values
+ self.assertEqual(0, decoded)
+ self.assertEqual(1, read)
+
+ # The rest of the file should be untouched
+ self.assertEqual('crummy', infile.read())
+
+ def test_write_varint(self):
+
+ expected = '\xac\x02'
+ outfile = StringIO()
+
+ written = blocks.write_varint(outfile, 300)
+
+ # Test the returned values
+ self.assertEqual(expected, outfile.getvalue())
+ self.assertEqual(2, written)
+
+
+ def test_write_zero(self):
+
+ outfile = StringIO()
+ written = blocks.write_varint(outfile, 0)
+
+ # Test the returned values
+ self.assertEqual('\x00', outfile.getvalue())
+ self.assertEqual(1, written)
+