summaryrefslogtreecommitdiff
path: root/python/samba/tests/lsa_string.py
blob: 130f8807a21825db56d1b4724d9449f704f21d2f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# Tests for lsa.String helpers in source4/librpc/ndr/py_lsa.c
#
# Copyright (C) Catalyst IT Ltd. 2017
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

from samba.tests import TestCase
from samba.dcerpc import lsa
from samba.ndr import ndr_pack, ndr_unpack
"""
Tests for the C helper functions in source4/librpc/ndr/py_lsa.c
for samba.dcerpc.lsa.String
"""

class LsaStringTests(TestCase):

    def test_default_constructor(self):
        s = lsa.String()
        self.assertEqual(None, s.string)
        self.assertEqual(0, s.size)
        self.assertEqual(0, s.length)

    def test_string_constructor(self):
        CONTENT = "The content string"
        s = lsa.String(CONTENT)
        self.assertEqual(CONTENT, s.string)

        # These should be zero, are set by ndr_pack and ndr_unpack
        self.assertEqual(0, s.size)
        self.assertEqual(0, s.length)

    def test_string_constructor(self):
        CONTENT = "The content string"
        s = lsa.String(CONTENT)
        self.assertEqual(CONTENT, s.string)

        # These should be zero
        self.assertEqual(0, s.size)
        self.assertEqual(0, s.length)

        packed = ndr_pack(s)
        unpacked = ndr_unpack(lsa.String, packed)

        # Original object should be unchanged
        self.assertEqual(0, s.size)
        self.assertEqual(0, s.length)

        # But they should be correct in the unpacked object
        self.assertEqual(36, unpacked.size)
        self.assertEqual(36, unpacked.length)

    def test_repr(self):
        # test an empty string
        self.assertEqual("lsaString(None)", repr(lsa.String()))
        # and one with contents
        self.assertEqual("lsaString('Hello world')",
                         repr(lsa.String("Hello world")))

    def test_to_string(self):
        # test an empty string
        self.assertEqual("", str(lsa.String()))
        # and one with contents
        self.assertEqual("Hello world",
                         str(lsa.String("Hello world")))