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
23 Tests for the C helper functions in source4/librpc/ndr/py_lsa.c
24 for samba.dcerpc.lsa.String
28 class LsaStringTests(TestCase):
30 def test_default_constructor(self):
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, are set by ndr_pack and ndr_unpack
42 self.assertEqual(0, s.size)
43 self.assertEqual(0, s.length)
45 def test_string_constructor(self):
46 CONTENT = "The content string"
47 s = lsa.String(CONTENT)
48 self.assertEqual(CONTENT, s.string)
50 # These should be zero
51 self.assertEqual(0, s.size)
52 self.assertEqual(0, s.length)
55 unpacked = ndr_unpack(lsa.String, packed)
57 # Original object should be unchanged
58 self.assertEqual(0, s.size)
59 self.assertEqual(0, s.length)
61 # But they should be correct in the unpacked object
62 self.assertEqual(36, unpacked.size)
63 self.assertEqual(36, unpacked.length)
66 # test an empty string
67 self.assertEqual("lsaString(None)", repr(lsa.String()))
68 # and one with contents
69 self.assertEqual("lsaString('Hello world')",
70 repr(lsa.String("Hello world")))
72 def test_to_string(self):
73 # test an empty string
74 self.assertEqual("", str(lsa.String()))
75 # and one with contents
76 self.assertEqual("Hello world",
77 str(lsa.String("Hello world")))