summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
authorMartin Pool <mbp@samba.org>2002-10-21 11:44:26 +0000
committerMartin Pool <mbp@samba.org>2002-10-21 11:44:26 +0000
commit23e608435895a39a4da52c3f649b130140f09662 (patch)
tree1bb3b9756d35310cd9a221111fb6d9bd912270c7 /source3
parentd70d4ef34b21d86ede25f00ed1b9726c9e9444be (diff)
downloadsamba-23e608435895a39a4da52c3f649b130140f09662.tar.gz
samba-23e608435895a39a4da52c3f649b130140f09662.tar.bz2
samba-23e608435895a39a4da52c3f649b130140f09662.zip
Test both new samba.tdbpack and oldtdbutil pack/unpack routines.
This makes the test suite fail because at the moment they are in fact not behaving the same way. (This used to be commit 44dd7746ede7f7f9efcf7dabcd351b1d800e535c)
Diffstat (limited to 'source3')
-rwxr-xr-xsource3/python/examples/tdbpack/test_tdbpack.py66
1 files changed, 37 insertions, 29 deletions
diff --git a/source3/python/examples/tdbpack/test_tdbpack.py b/source3/python/examples/tdbpack/test_tdbpack.py
index 36fed881e3..659dc0efed 100755
--- a/source3/python/examples/tdbpack/test_tdbpack.py
+++ b/source3/python/examples/tdbpack/test_tdbpack.py
@@ -17,13 +17,12 @@ string, with one character per field."""
__author__ = 'Martin Pool <mbp@sourcefrog.net>'
import unittest
-# import tdbutil
+import oldtdbutil
import samba.tdbpack
-packer = samba.tdbpack.pack
-unpacker = samba.tdbpack.unpack
-
-
+both_unpackers = (samba.tdbpack.unpack, oldtdbutil.unpack)
+both_packers = (samba.tdbpack.pack, oldtdbutil.pack)
+
class PackTests(unittest.TestCase):
symm_cases = [('B', ['hello' * 51], '\xff\0\0\0' + 'hello' * 51),
('w', [42], '\x2a\0'),
@@ -78,11 +77,13 @@ class PackTests(unittest.TestCase):
def test_symmetric(self):
"""Cookbook of symmetric pack/unpack tests
"""
- for format, values, expected in self.symm_cases:
- self.assertEquals(packer(format, values), expected)
- out, rest = unpacker(format, expected)
- self.assertEquals(rest, '')
- self.assertEquals(list(values), list(out))
+ for packer in both_packers:
+ for unpacker in both_unpackers:
+ for format, values, expected in self.symm_cases:
+ self.assertEquals(packer(format, values), expected)
+ out, rest = unpacker(format, expected)
+ self.assertEquals(rest, '')
+ self.assertEquals(list(values), list(out))
def test_pack(self):
@@ -100,25 +101,30 @@ class PackTests(unittest.TestCase):
# as if you called list()
]
- for format, values, expected in cases:
- self.assertEquals(packer(format, values), expected)
+ for packer in both_packers:
+ for format, values, expected in cases:
+ self.assertEquals(packer(format, values), expected)
def test_unpack_extra(self):
# Test leftover data
- for format, values, packed in self.symm_cases:
- out, rest = unpacker(format, packed + 'hello sailor!')
- self.assertEquals(rest, 'hello sailor!')
- self.assertEquals(list(values), list(out))
+ for unpacker in both_unpackers:
+ for format, values, packed in self.symm_cases:
+ out, rest = unpacker(format, packed + 'hello sailor!')
+ self.assertEquals(rest, 'hello sailor!')
+ self.assertEquals(list(values), list(out))
def test_unpack(self):
"""Cookbook of tricky unpack tests"""
cases = [
+ # Apparently I couldn't think of any tests that weren't
+ # symmetric :-/
]
- for format, values, expected in cases:
- out, rest = unpacker(format, expected)
- self.assertEquals(rest, '')
- self.assertEquals(list(values), list(out))
+ for unpacker in both_unpackers:
+ for format, values, expected in cases:
+ out, rest = unpacker(format, expected)
+ self.assertEquals(rest, '')
+ self.assertEquals(list(values), list(out))
def test_pack_failures(self):
@@ -141,7 +147,7 @@ class PackTests(unittest.TestCase):
('f', [2], TypeError),
('P', [None], TypeError),
('P', (), IndexError),
- ('f', [packer], TypeError),
+ ('f', [hex], TypeError),
('fw', ['hello'], IndexError),
('f', [u'hello'], TypeError),
('B', [2], TypeError),
@@ -153,10 +159,11 @@ class PackTests(unittest.TestCase):
('fQ', ['2'], IndexError),
(2, [2], TypeError),
({}, {}, TypeError)]
- for format, values, throwable_class in cases:
- def do_pack():
- packer(format, values)
- self.assertRaises(throwable_class, do_pack)
+ for packer in both_packers:
+ for format, values, throwable_class in cases:
+ def do_pack():
+ packer(format, values)
+ self.assertRaises(throwable_class, do_pack)
def test_unpack_failures(self):
@@ -182,10 +189,11 @@ class PackTests(unittest.TestCase):
('B', 'foobar', IndexError),
('BB', '\x01\0\0\0a\x01', IndexError),
]
-
- for format, values, throwable_class in cases:
- def do_unpack():
- unpacker(format, values)
+
+ for unpacker in both_unpackers:
+ for format, values, throwable_class in cases:
+ def do_unpack():
+ unpacker(format, values)
self.assertRaises(throwable_class, do_unpack)