mirror of
https://github.com/samba-team/samba.git
synced 2025-08-02 00:22:11 +03:00
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 commit is contained in:
@ -17,13 +17,12 @@ string, with one character per field."""
|
|||||||
__author__ = 'Martin Pool <mbp@sourcefrog.net>'
|
__author__ = 'Martin Pool <mbp@sourcefrog.net>'
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
# import tdbutil
|
import oldtdbutil
|
||||||
import samba.tdbpack
|
import samba.tdbpack
|
||||||
|
|
||||||
packer = samba.tdbpack.pack
|
both_unpackers = (samba.tdbpack.unpack, oldtdbutil.unpack)
|
||||||
unpacker = samba.tdbpack.unpack
|
both_packers = (samba.tdbpack.pack, oldtdbutil.pack)
|
||||||
|
|
||||||
|
|
||||||
class PackTests(unittest.TestCase):
|
class PackTests(unittest.TestCase):
|
||||||
symm_cases = [('B', ['hello' * 51], '\xff\0\0\0' + 'hello' * 51),
|
symm_cases = [('B', ['hello' * 51], '\xff\0\0\0' + 'hello' * 51),
|
||||||
('w', [42], '\x2a\0'),
|
('w', [42], '\x2a\0'),
|
||||||
@ -78,11 +77,13 @@ class PackTests(unittest.TestCase):
|
|||||||
def test_symmetric(self):
|
def test_symmetric(self):
|
||||||
"""Cookbook of symmetric pack/unpack tests
|
"""Cookbook of symmetric pack/unpack tests
|
||||||
"""
|
"""
|
||||||
for format, values, expected in self.symm_cases:
|
for packer in both_packers:
|
||||||
self.assertEquals(packer(format, values), expected)
|
for unpacker in both_unpackers:
|
||||||
out, rest = unpacker(format, expected)
|
for format, values, expected in self.symm_cases:
|
||||||
self.assertEquals(rest, '')
|
self.assertEquals(packer(format, values), expected)
|
||||||
self.assertEquals(list(values), list(out))
|
out, rest = unpacker(format, expected)
|
||||||
|
self.assertEquals(rest, '')
|
||||||
|
self.assertEquals(list(values), list(out))
|
||||||
|
|
||||||
|
|
||||||
def test_pack(self):
|
def test_pack(self):
|
||||||
@ -100,25 +101,30 @@ class PackTests(unittest.TestCase):
|
|||||||
# as if you called list()
|
# as if you called list()
|
||||||
]
|
]
|
||||||
|
|
||||||
for format, values, expected in cases:
|
for packer in both_packers:
|
||||||
self.assertEquals(packer(format, values), expected)
|
for format, values, expected in cases:
|
||||||
|
self.assertEquals(packer(format, values), expected)
|
||||||
|
|
||||||
def test_unpack_extra(self):
|
def test_unpack_extra(self):
|
||||||
# Test leftover data
|
# Test leftover data
|
||||||
for format, values, packed in self.symm_cases:
|
for unpacker in both_unpackers:
|
||||||
out, rest = unpacker(format, packed + 'hello sailor!')
|
for format, values, packed in self.symm_cases:
|
||||||
self.assertEquals(rest, 'hello sailor!')
|
out, rest = unpacker(format, packed + 'hello sailor!')
|
||||||
self.assertEquals(list(values), list(out))
|
self.assertEquals(rest, 'hello sailor!')
|
||||||
|
self.assertEquals(list(values), list(out))
|
||||||
|
|
||||||
|
|
||||||
def test_unpack(self):
|
def test_unpack(self):
|
||||||
"""Cookbook of tricky unpack tests"""
|
"""Cookbook of tricky unpack tests"""
|
||||||
cases = [
|
cases = [
|
||||||
|
# Apparently I couldn't think of any tests that weren't
|
||||||
|
# symmetric :-/
|
||||||
]
|
]
|
||||||
for format, values, expected in cases:
|
for unpacker in both_unpackers:
|
||||||
out, rest = unpacker(format, expected)
|
for format, values, expected in cases:
|
||||||
self.assertEquals(rest, '')
|
out, rest = unpacker(format, expected)
|
||||||
self.assertEquals(list(values), list(out))
|
self.assertEquals(rest, '')
|
||||||
|
self.assertEquals(list(values), list(out))
|
||||||
|
|
||||||
|
|
||||||
def test_pack_failures(self):
|
def test_pack_failures(self):
|
||||||
@ -141,7 +147,7 @@ class PackTests(unittest.TestCase):
|
|||||||
('f', [2], TypeError),
|
('f', [2], TypeError),
|
||||||
('P', [None], TypeError),
|
('P', [None], TypeError),
|
||||||
('P', (), IndexError),
|
('P', (), IndexError),
|
||||||
('f', [packer], TypeError),
|
('f', [hex], TypeError),
|
||||||
('fw', ['hello'], IndexError),
|
('fw', ['hello'], IndexError),
|
||||||
('f', [u'hello'], TypeError),
|
('f', [u'hello'], TypeError),
|
||||||
('B', [2], TypeError),
|
('B', [2], TypeError),
|
||||||
@ -153,10 +159,11 @@ class PackTests(unittest.TestCase):
|
|||||||
('fQ', ['2'], IndexError),
|
('fQ', ['2'], IndexError),
|
||||||
(2, [2], TypeError),
|
(2, [2], TypeError),
|
||||||
({}, {}, TypeError)]
|
({}, {}, TypeError)]
|
||||||
for format, values, throwable_class in cases:
|
for packer in both_packers:
|
||||||
def do_pack():
|
for format, values, throwable_class in cases:
|
||||||
packer(format, values)
|
def do_pack():
|
||||||
self.assertRaises(throwable_class, do_pack)
|
packer(format, values)
|
||||||
|
self.assertRaises(throwable_class, do_pack)
|
||||||
|
|
||||||
|
|
||||||
def test_unpack_failures(self):
|
def test_unpack_failures(self):
|
||||||
@ -182,10 +189,11 @@ class PackTests(unittest.TestCase):
|
|||||||
('B', 'foobar', IndexError),
|
('B', 'foobar', IndexError),
|
||||||
('BB', '\x01\0\0\0a\x01', IndexError),
|
('BB', '\x01\0\0\0a\x01', IndexError),
|
||||||
]
|
]
|
||||||
|
|
||||||
for format, values, throwable_class in cases:
|
for unpacker in both_unpackers:
|
||||||
def do_unpack():
|
for format, values, throwable_class in cases:
|
||||||
unpacker(format, values)
|
def do_unpack():
|
||||||
|
unpacker(format, values)
|
||||||
self.assertRaises(throwable_class, do_unpack)
|
self.assertRaises(throwable_class, do_unpack)
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user