smbd: improve reinit_after_fork error handling
[Samba.git] / python / samba / tests / lsa_string.py
blobbcc76b5b0baf9569ed86f2213750f15f69fc585c
1 # Tests for lsa.String helpers in source4/librpc/ndr/py_lsa.c
3 # Copyright (C) Catalyst IT Ltd. 2017
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 from samba.tests import TestCase
20 from samba.dcerpc import lsa
21 from samba.ndr import ndr_pack, ndr_unpack
22 """
23 Tests for the C helper functions in source4/librpc/ndr/py_lsa.c
24 for samba.dcerpc.lsa.String
25 """
28 class LsaStringTests(TestCase):
30 def test_default_constructor(self):
31 s = lsa.String()
32 self.assertEqual(None, s.string)
33 self.assertEqual(0, s.size)
34 self.assertEqual(0, s.length)
36 def test_string_constructor(self):
37 CONTENT = "The content string"
38 s = lsa.String(CONTENT)
39 self.assertEqual(CONTENT, s.string)
41 # These should be zero
42 self.assertEqual(0, s.size)
43 self.assertEqual(0, s.length)
45 packed = ndr_pack(s)
46 unpacked = ndr_unpack(lsa.String, packed)
48 # Original object should be unchanged
49 self.assertEqual(0, s.size)
50 self.assertEqual(0, s.length)
52 # But they should be correct in the unpacked object
53 self.assertEqual(36, unpacked.size)
54 self.assertEqual(36, unpacked.length)
56 def test_repr(self):
57 # test an empty string
58 self.assertEqual("lsaString(None)", repr(lsa.String()))
59 # and one with contents
60 self.assertEqual("lsaString('Hello world')",
61 repr(lsa.String("Hello world")))
63 def test_to_string(self):
64 # test an empty string
65 self.assertEqual("", str(lsa.String()))
66 # and one with contents
67 self.assertEqual("Hello world",
68 str(lsa.String("Hello world")))