1 # Unix SMB/CIFS implementation.
2 # Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007
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 the _glue Python bindings."""
20 from samba
import _glue
21 from samba
import param
25 class GlueTests(samba
.tests
.TestCase
):
27 def test_generate_random_str(self
):
28 string
= _glue
.generate_random_str(10)
29 self
.assertEqual(type(string
), str)
30 self
.assertEqual(len(string
), 10)
32 def test_generate_random_password(self
):
33 password
= _glue
.generate_random_password(5, 10)
34 self
.assertEqual(type(password
), str)
35 self
.assertTrue(5 <= len(password
) <= 10)
37 def test_unix2nttime(self
):
38 self
.assertEqual(_glue
.unix2nttime(1), 116444736010000000)
40 def test_nttime2unix(self
):
41 self
.assertEqual(_glue
.nttime2unix(116444736010000000), 1)
43 def test_float2nttime(self
):
44 self
.assertEqual(_glue
.float2nttime(1.0), 116444736010000000)
45 self
.assertEqual(_glue
.float2nttime(1611058908.0), 132555325080000000)
46 # NTTIME has a resolution of 100ns
47 self
.assertEqual(_glue
.float2nttime(1611058908.1234567), 132555325081234567)
48 self
.assertEqual(_glue
.float2nttime(1611058908.123456789), 132555325081234567)
50 def test_nttime2float(self
):
51 self
.assertEqual(_glue
.nttime2float(1), -11644473600.0)
52 self
.assertEqual(_glue
.nttime2float(0x7fffffffffffffff), 910692730085.4775)
53 self
.assertEqual(_glue
.nttime2float(0x8000000000000000), 910692730085.4775)
54 self
.assertEqual(_glue
.nttime2float(0xf000000000000000), 910692730085.4775)
55 self
.assertEqual(_glue
.nttime2float(116444736010000000), 1.0)
56 self
.assertEqual(_glue
.nttime2float(132555325080000000), 1611058908.0)
57 self
.assertEqual(_glue
.nttime2float(132555325081234567), 1611058908.1234567)
58 # NTTIME_OMIT (0) and NTTIME_FREEZE (UINT64_MAX) map to SAMBA_UTIME_OMIT (1)
59 self
.assertEqual(_glue
.nttime2float(0), 1.0)
60 self
.assertEqual(_glue
.nttime2float(0xffffffffffffffff), 1.0)
62 def test_nttime2string(self
):
63 string
= _glue
.nttime2string(116444736010000000)
64 self
.assertEqual(type(string
), str)
65 self
.assertIn('1970', string
)
67 def test_debug_level(self
):
68 prev_level
= _glue
.get_debug_level()
70 self
.assertIsNone(_glue
.set_debug_level(0))
71 self
.assertEqual(_glue
.get_debug_level(), 0)
72 self
.assertIsNone(_glue
.set_debug_level(5))
73 self
.assertEqual(_glue
.get_debug_level(), 5)
75 _glue
.set_debug_level(prev_level
)
77 def test_interface_ips(self
):
79 ips
= _glue
.interface_ips(lp
)
80 self
.assertEqual(type(ips
), list)
82 def test_strcasecmp(self
):
83 self
.assertEqual(_glue
.strcasecmp_m('aA', 'Aa'), 0)
84 self
.assertNotEqual(_glue
.strcasecmp_m('ab', 'Aa'), 0)
86 def test_strstr_m(self
):
87 string
= 'testing_string_num__one'
88 self
.assertEqual(_glue
.strstr_m(string
, '_'), '_string_num__one')
89 self
.assertEqual(_glue
.strstr_m(string
, '__'), '__one')
90 self
.assertEqual(_glue
.strstr_m(string
, 'ring'), 'ring_num__one')