1 # Unix SMB/CIFS implementation.
2 # Copyright (C) Andrew Bartlett <abartlet@samba.org> 2016
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 """Tests for string and unicode handling in PIDL generated bindings
21 from samba
.dcerpc
import drsblobs
23 from samba
.ndr
import ndr_unpack
, ndr_pack
28 class TestException(Exception):
32 class StringTests(samba
.tests
.TestCase
):
36 talloc
.enable_null_tracking()
37 self
.startup_blocks
= talloc
.total_blocks()
42 if talloc
.total_blocks() != self
.startup_blocks
:
44 self
.fail("it appears we are leaking memory")
46 def test_string_from_python(self
):
47 info
= drsblobs
.repsFromTo2OtherInfo()
48 info
.dns_name1
= "hello.example.com"
49 info
.dns_name2
= "goodbye.example.com"
51 self
.assertIsNotNone(info
)
52 self
.assertEqual(info
.dns_name1
, "hello.example.com")
53 self
.assertEqual(info
.dns_name2
, "goodbye.example.com")
56 info
.dns_name2
= "goodbye.example.com"
58 self
.assertEqual(info
.dns_name1
, "")
59 self
.assertEqual(info
.dns_name2
, "goodbye.example.com")
63 self
.assertEqual(info
.dns_name1
, "")
64 self
.assertIsNone(info
.dns_name2
)
66 def test_string_with_exception(self
):
68 self
.test_string_from_python()
73 def test_string_from_python_function(self
):
75 info
= drsblobs
.repsFromTo2OtherInfo()
76 info
.dns_name1
= "1.example.com"
77 info
.dns_name2
= "2.example.com"
82 self
.assertIsNotNone(info
)
83 self
.assertEqual(info
.dns_name1
, "1.example.com")
84 self
.assertEqual(info
.dns_name2
, "2.example.com")
86 def test_string_modify_in_place(self
):
87 info
= drsblobs
.repsFromTo2OtherInfo()
88 info
.dns_name1
= "1.example.com"
89 info
.dns_name2
= "%s.example.com"
91 self
.assertIsNotNone(info
)
92 self
.assertEqual(info
.dns_name1
, "1.example.com")
93 self
.assertEqual(info
.dns_name2
, "%s.example.com")
94 info
.dns_name1
+= ".co.nz"
96 self
.assertEqual(info
.dns_name1
, "1.example.com.co.nz")
97 self
.assertEqual(info
.dns_name2
, "2.example.com")
100 def test_string_delete(self
):
102 info
= drsblobs
.repsFromTo2OtherInfo()
103 info
.dns_name1
= "1.example.com"
104 info
.dns_name2
= "2.example.com"
105 info
.dns_name1
= None
108 except AttributeError:
111 self
.assertIsNotNone(info
)
112 self
.assertIsNone(info
.dns_name1
)
113 self
.assertIsNotNone(info
.dns_name2
)
116 class StringTestsWithoutLeakCheck(samba
.tests
.TestCase
):
117 """We know that the ndr unpacking test leaves stuff in the
118 autofree_context, and we don't want to worry about that. So for
119 this test we don't make memory leak assertions."""
121 def test_string_from_ndr(self
):
122 info
= drsblobs
.repsFromTo2OtherInfo()
123 info
.dns_name1
= "1.example.com"
124 info
.dns_name2
= "2.example.com"
125 packed
= ndr_pack(info
)
128 info_unpacked
= ndr_unpack(drsblobs
.repsFromTo2OtherInfo
, packed
)
130 self
.assertIsNotNone(info_unpacked
)
131 self
.assertEqual(info_unpacked
.dns_name1
, "1.example.com")
132 self
.assertEqual(info_unpacked
.dns_name2
, "2.example.com")