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,12 +17,11 @@ 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),
|
||||
@ -78,6 +77,8 @@ class PackTests(unittest.TestCase):
|
||||
def test_symmetric(self):
|
||||
"""Cookbook of symmetric pack/unpack tests
|
||||
"""
|
||||
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)
|
||||
@ -100,11 +101,13 @@ class PackTests(unittest.TestCase):
|
||||
# as if you called list()
|
||||
]
|
||||
|
||||
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 unpacker in both_unpackers:
|
||||
for format, values, packed in self.symm_cases:
|
||||
out, rest = unpacker(format, packed + 'hello sailor!')
|
||||
self.assertEquals(rest, 'hello sailor!')
|
||||
@ -114,7 +117,10 @@ class PackTests(unittest.TestCase):
|
||||
def test_unpack(self):
|
||||
"""Cookbook of tricky unpack tests"""
|
||||
cases = [
|
||||
# Apparently I couldn't think of any tests that weren't
|
||||
# symmetric :-/
|
||||
]
|
||||
for unpacker in both_unpackers:
|
||||
for format, values, expected in cases:
|
||||
out, rest = unpacker(format, expected)
|
||||
self.assertEquals(rest, '')
|
||||
@ -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,6 +159,7 @@ class PackTests(unittest.TestCase):
|
||||
('fQ', ['2'], IndexError),
|
||||
(2, [2], TypeError),
|
||||
({}, {}, TypeError)]
|
||||
for packer in both_packers:
|
||||
for format, values, throwable_class in cases:
|
||||
def do_pack():
|
||||
packer(format, values)
|
||||
@ -183,6 +190,7 @@ class PackTests(unittest.TestCase):
|
||||
('BB', '\x01\0\0\0a\x01', IndexError),
|
||||
]
|
||||
|
||||
for unpacker in both_unpackers:
|
||||
for format, values, throwable_class in cases:
|
||||
def do_unpack():
|
||||
unpacker(format, values)
|
||||
|
Reference in New Issue
Block a user