| 1 | #! /usr/bin/env python2.2
|
|---|
| 2 |
|
|---|
| 3 | __doc__ = """test case for samba.tdbpack functions
|
|---|
| 4 |
|
|---|
| 5 | tdbpack provides a means of pickling values into binary formats
|
|---|
| 6 | compatible with that used by the samba tdbpack()/tdbunpack()
|
|---|
| 7 | functions.
|
|---|
| 8 |
|
|---|
| 9 | Numbers are always stored in little-endian format; strings are stored
|
|---|
| 10 | in either DOS or Unix codepage as appropriate.
|
|---|
| 11 |
|
|---|
| 12 | The format for any particular element is encoded as a short ASCII
|
|---|
| 13 | string, with one character per field."""
|
|---|
| 14 |
|
|---|
| 15 | # Copyright (C) 2002 Hewlett-Packard.
|
|---|
| 16 |
|
|---|
| 17 | __author__ = 'Martin Pool <[email protected]>'
|
|---|
| 18 |
|
|---|
| 19 | import unittest
|
|---|
| 20 | import oldtdbutil
|
|---|
| 21 | import samba.tdbpack
|
|---|
| 22 |
|
|---|
| 23 | both_unpackers = (samba.tdbpack.unpack, oldtdbutil.unpack)
|
|---|
| 24 | both_packers = (samba.tdbpack.pack, oldtdbutil.pack)
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 | # # ('B', [10, 'hello'], '\x0a\0\0\0hello'),
|
|---|
| 29 | # ('BB', [11, 'hello\0world', 3, 'now'],
|
|---|
| 30 | # '\x0b\0\0\0hello\0world\x03\0\0\0now'),
|
|---|
| 31 | # ('pd', [1, 10], '\x01\0\0\0\x0a\0\0\0'),
|
|---|
| 32 | # ('BBB', [5, 'hello', 0, '', 5, 'world'],
|
|---|
| 33 | # '\x05\0\0\0hello\0\0\0\0\x05\0\0\0world'),
|
|---|
| 34 |
|
|---|
| 35 | # strings are sequences in Python, there's no getting away
|
|---|
| 36 | # from it
|
|---|
| 37 | # ('ffff', 'evil', 'e\0v\0i\0l\0'),
|
|---|
| 38 | # ('BBBB', 'evil',
|
|---|
| 39 | # '\x01\0\0\0e'
|
|---|
| 40 | # '\x01\0\0\0v'
|
|---|
| 41 | # '\x01\0\0\0i'
|
|---|
| 42 | # '\x01\0\0\0l'),
|
|---|
| 43 |
|
|---|
| 44 | # ('', [], ''),
|
|---|
| 45 |
|
|---|
| 46 | # # exercise some long strings
|
|---|
| 47 | # ('PP', ['hello' * 255, 'world' * 255],
|
|---|
| 48 | # 'hello' * 255 + '\0' + 'world' * 255 + '\0'),
|
|---|
| 49 | # ('PP', ['hello' * 40000, 'world' * 50000],
|
|---|
| 50 | # 'hello' * 40000 + '\0' + 'world' * 50000 + '\0'),
|
|---|
| 51 | # ('B', [(5*51), 'hello' * 51], '\xff\0\0\0' + 'hello' * 51),
|
|---|
| 52 | # ('BB', [(5 * 40000), 'hello' * 40000,
|
|---|
| 53 | # (5 * 50000), 'world' * 50000],
|
|---|
| 54 | # '\x40\x0d\x03\0' + 'hello' * 40000 + '\x90\xd0\x03\x00' + 'world' * 50000),
|
|---|
| 55 |
|
|---|
| 56 |
|
|---|
| 57 | class PackTests(unittest.TestCase):
|
|---|
| 58 | symm_cases = [
|
|---|
| 59 | ('w', [42], '\x2a\0'),
|
|---|
| 60 | ('www', [42, 2, 69], '\x2a\0\x02\0\x45\0'),
|
|---|
| 61 | ('wd', [42, 256], '\x2a\0\0\x01\0\0'),
|
|---|
| 62 | ('w', [0], '\0\0'),
|
|---|
|
|---|