source: branches/samba-3.0/source/python/examples/tdbpack/test_tdbpack.py@ 169

Last change on this file since 169 was 1, checked in by Paul Smedley, 19 years ago

Initial code import

File size: 10.1 KB
Line 
1#! /usr/bin/env python2.2
2
3__doc__ = """test case for samba.tdbpack functions
4
5tdbpack provides a means of pickling values into binary formats
6compatible with that used by the samba tdbpack()/tdbunpack()
7functions.
8
9Numbers are always stored in little-endian format; strings are stored
10in either DOS or Unix codepage as appropriate.
11
12The format for any particular element is encoded as a short ASCII
13string, with one character per field."""
14
15# Copyright (C) 2002 Hewlett-Packard.
16
17__author__ = 'Martin Pool <[email protected]>'
18
19import unittest
20import oldtdbutil
21import samba.tdbpack
22
23both_unpackers = (samba.tdbpack.unpack, oldtdbutil.unpack)
24both_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
57class 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'),